Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3ff8f9

Browse files
committed
subtask progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent83b4899 commitd3ff8f9

File tree

9 files changed

+85
-17
lines changed

9 files changed

+85
-17
lines changed

‎src/channel/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class Channel implements Channel {
306306
awaitvscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION,action.payload.position)
307307
awaitsolutionActions({actions:action.payload.actions,send:this.send})
308308
// run test following solution to update position
309-
vscode.commands.executeCommand(COMMANDS.RUN_TEST,{subtasks:true})
309+
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
310310
return
311311
case'EDITOR_SYNC_PROGRESS':
312312
// update progress when a level is deemed complete in the client

‎src/editor/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
8282
webview.send({type:'TEST_RUNNING',payload:{ position}})
8383
},
8484
onLoadSubtasks:({ summary})=>{
85-
webview.send({type:'LOAD_TEST_SUBTASKS',payload:{ summary}})
85+
webview.send({type:'LOAD_SUBTASK_RESULTS',payload:{ summary}})
8686
},
8787
})
8888
},

‎src/services/testRunner/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial'
33
import{exec}from'../node'
44
importloggerfrom'../logger'
55
importparser,{ParserOutput}from'./parser'
6+
importparseSubtasksfrom'./subtasks'
67
import{debounce,throttle}from'./throttle'
78
importonErrorfrom'../sentry/onError'
89
import{clearOutput,addOutput}from'./output'
@@ -13,7 +14,7 @@ interface Callbacks {
1314
onFail(position:T.Position,failSummary:T.TestFail):void
1415
onRun(position:T.Position):void
1516
onError(position:T.Position):void
16-
onLoadSubtasks({ summary}:{summary:{[testName:string]:boolean}}):void
17+
onLoadSubtasks({ summary}:{summary:{[testId:number]:boolean}}):void
1718
}
1819

1920
constfailChannelName='CodeRoad (Tests)'
@@ -28,7 +29,7 @@ interface TestRunnerParams {
2829
constcreateTestRunner=(data:TT.Tutorial,callbacks:Callbacks)=>{
2930
consttestRunnerConfig=data.config.testRunner
3031
consttestRunnerFilterArg=testRunnerConfig.args?.filter
31-
returnasync({ position, onSuccess, subtasks}:TestRunnerParams):Promise<void>=>{
32+
returnasync({ position, onSuccess}:TestRunnerParams):Promise<void>=>{
3233
conststartTime=throttle()
3334
// throttle time early
3435
if(!startTime){
@@ -37,8 +38,24 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks) => {
3738

3839
logger('------------------- RUN TEST -------------------')
3940

41+
// calculate level & step from position
42+
constlevel:TT.Level|null=data.levels.find((l)=>l.id===position.levelId)||null
43+
if(!level){
44+
console.warn(`Level "${position.levelId}" not found`)
45+
return
46+
}
47+
conststep:TT.Step|null=level.steps.find((s)=>s.id===position.stepId)||null
48+
if(!step){
49+
console.warn(`Step "${position.stepId}" not found`)
50+
return
51+
}
52+
53+
console.log('STEP')
54+
console.log(JSON.stringify(step))
55+
4056
// flag as running
41-
if(!subtasks){
57+
// no need to flag subtasks as running
58+
if(!step.setup?.subtasks){
4259
callbacks.onRun(position)
4360
}
4461

@@ -81,8 +98,12 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks) => {
8198

8299
consttap:ParserOutput=parser(stdout||'')
83100

84-
if(subtasks){
85-
callbacks.onLoadSubtasks({summary:tap.summary})
101+
if(step.setup.subtasks){
102+
constsummary=parseSubtasks(tap.summary,position.stepId||'')
103+
104+
console.log('---subtask summary')
105+
console.log(summary)
106+
callbacks.onLoadSubtasks({ summary})
86107
// exit early
87108
return
88109
}

‎src/services/testRunner/parser.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,28 @@ not ok 2 test_add_one_number (tests.math_test.MathTest)
269269
})
270270
})
271271
})
272+
273+
describe('subtasks',()=>{
274+
it('should parse subtasks',()=>{
275+
constsummary={
276+
'SUBTASKS 1.1 :1 should add one number':true,
277+
'SUBTASKS 1.1 :2 should add two numbers':false,
278+
'SUBTASKS 1.1 :3 should add three numbers':false,
279+
}
280+
constsubtaskRegex=/^SUBTASKS\s(?<stepId>(\d+\.\d+))\s:(?<testId>\d+)\s/
281+
constsubtaskSummary={}
282+
Object.keys(summary).forEach((key)=>{
283+
constmatch=key.match(subtaskRegex)
284+
if(!!match){
285+
const{ stepId, testId}=match.groups||{}
286+
consttestIndex=Number(testId)-1
287+
subtaskSummary[testIndex]=summary[key]
288+
}
289+
})
290+
expect(subtaskSummary).toEqual({
291+
0:true,
292+
1:false,
293+
2:false,
294+
})
295+
})
296+
})

‎src/services/testRunner/subtasks.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
interfaceSummary{
2+
[key:string]:boolean
3+
}
4+
5+
// if a subtask matches the current stepId name
6+
// in the format "SUBTASKS 1.1 :1" where 1.1 is the stepId & :1 is the testId
7+
// values will be parsed and sent to the client
8+
constparseSubtasks=(summary:Summary,expectedStepId:string|null):Summary=>{
9+
constsubtaskRegex=/^SUBTASKS\s(?<stepId>(\d+\.\d+))\s:(?<testId>\d+)\s/
10+
constsubtaskSummary={}
11+
Object.keys(summary).forEach((key)=>{
12+
constmatch=key.match(subtaskRegex)
13+
if(!!match){
14+
const{ stepId, testId}=match.groups||{}
15+
if(stepId===expectedStepId){
16+
consttestIndex=Number(testId)-1
17+
subtaskSummary[testIndex]=summary[key]
18+
}
19+
}
20+
})
21+
returnsubtaskSummary
22+
}
23+
24+
exportdefaultparseSubtasks

‎typings/tutorial.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type Step = {
2727
content:string
2828
setup:StepActions
2929
solution:Maybe<StepActions>
30-
subtasks?:{[testName:string]:boolean}
30+
subtasks?:{[index:number]:boolean}
3131
hints?:string[]
3232
}
3333

@@ -52,7 +52,7 @@ export type StepActions = {
5252
files?:string[]
5353
watchers?:string[]
5454
filter?:string
55-
subtasks?:boolean
55+
subtasks?:string[]
5656
}
5757

5858
exportinterfaceTestRunnerArgs{

‎web-app/src/containers/Tutorial/components/Level.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,12 @@ const Level = ({
199199
returnnull
200200
}
201201
letsubtasks=null
202-
if(step?.setup?.subtasks&&testStatus?.summary){
203-
subtasks=Object.keys(testStatus.summary).map((testName:string)=>({
204-
name:testName,
205-
//@ts-ignore typescript is wrong here
206-
pass:testStatus.summary[testName],
202+
if(step?.setup?.subtasks){
203+
subtasks=step.setup.subtasks.map((subtask:string,subtaskIndex:number)=>({
204+
name:subtask,
205+
pass:!!(testStatus?.summary ?testStatus.summary[subtaskIndex] :false),
207206
}))
208207
}
209-
consthints=step.hints
210208
return(
211209
<Step
212210
key={step.id}

‎web-app/src/services/state/actions/editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default (editorSend: any) => ({
5858
})
5959

6060
if(step.setup.subtasks){
61-
// load subtaskdata by running tests and parsing result
61+
// load subtasksummary by running tests and parsing result
6262
editorSend({
6363
type:'EDITOR_RUN_TEST',
6464
payload:{

‎web-app/src/services/state/machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const createMachine = (options: any) => {
155155
Normal:{
156156
id:'tutorial-level',
157157
on:{
158-
LOAD_TEST_SUBTASKS:{
158+
LOAD_SUBTASK_RESULTS:{
159159
actions:['testSubtasks'],
160160
},
161161
TEST_RUNNING:'TestRunning',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp