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

Commit523d936

Browse files
committed
load subtasks on startup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parenta690ce0 commit523d936

File tree

12 files changed

+66
-20
lines changed

12 files changed

+66
-20
lines changed

‎src/actions/utils/loadWatchers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ const loadWatchers = (watchers: string[]) => {
3838
constnow=+newDate()
3939
if(!lastFire||lastFire-now>1000){
4040
vscode.commands.executeCommand(COMMANDS.RUN_TEST,{
41-
onSuccess:()=>{
42-
// cleanup watcher on success
43-
disposeWatcher(watcher)
41+
callbacks:{
42+
onSuccess:()=>{
43+
// cleanup watcher on success
44+
disposeWatcher(watcher)
45+
},
4446
},
4547
})
4648
}

‎src/channel/index.ts

Lines changed: 2 additions & 2 deletions
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)
309+
vscode.commands.executeCommand(COMMANDS.RUN_TEST,{subtasks:true})
310310
return
311311
case'EDITOR_SYNC_PROGRESS':
312312
// update progress when a level is deemed complete in the client
@@ -317,7 +317,7 @@ class Channel implements Channel {
317317
awaitshowOutput(channel)
318318
return
319319
case'EDITOR_RUN_TEST':
320-
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
320+
vscode.commands.executeCommand(COMMANDS.RUN_TEST,action?.payload)
321321
return
322322
default:
323323
logger(`No match for action type:${actionType}`)

‎src/editor/commands.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,27 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
8181
// send test run message back to client
8282
webview.send({type:'TEST_RUNNING',payload:{ position}})
8383
},
84+
onLoadSubtasks:({ summary})=>{
85+
webview.send({type:'LOAD_TEST_SUBTASKS',payload:{ summary}})
86+
},
8487
})
8588
},
8689
[COMMANDS.SET_CURRENT_POSITION]:(position:T.Position)=>{
8790
// set from last setup stepAction
8891
currentPosition=position
8992
},
90-
[COMMANDS.RUN_TEST]:(callback?:{onSuccess:()=>void})=>{
93+
[COMMANDS.RUN_TEST]:({
94+
subtasks,
95+
callbacks,
96+
}:{subtasks?:boolean;callbacks?:{onSuccess:()=>void}}={})=>{
9197
logger('run test current',currentPosition)
9298
// use stepId from client, or last set stepId
9399
// const position: T.Position = {
94100
// ...current,
95101
// stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
96102
// }
97103
logger('currentPosition',currentPosition)
98-
testRunner({position:currentPosition,onSuccess:callback?.onSuccess})
104+
testRunner({position:currentPosition,onSuccess:callbacks?.onSuccess, subtasks})
99105
},
100106
}
101107
}

‎src/services/testRunner/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ interface Callbacks {
1313
onFail(position:T.Position,failSummary:T.TestFail):void
1414
onRun(position:T.Position):void
1515
onError(position:T.Position):void
16+
onLoadSubtasks({ summary}:{summary:{[testName:string]:boolean}}):void
1617
}
1718

1819
constfailChannelName='CodeRoad (Tests)'
1920
constlogChannelName='CodeRoad (Logs)'
2021

2122
interfaceTestRunnerParams{
2223
position:T.Position
24+
subtasks?:boolean
2325
onSuccess?:()=>void
2426
}
2527

2628
constcreateTestRunner=(data:TT.Tutorial,callbacks:Callbacks)=>{
2729
consttestRunnerConfig=data.config.testRunner
2830
consttestRunnerFilterArg=testRunnerConfig.args?.filter
29-
returnasync({ position, onSuccess}:TestRunnerParams):Promise<void>=>{
31+
returnasync({ position, onSuccess, subtasks}:TestRunnerParams):Promise<void>=>{
3032
conststartTime=throttle()
3133
// throttle time early
3234
if(!startTime){
@@ -36,7 +38,9 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks) => {
3638
logger('------------------- RUN TEST -------------------')
3739

3840
// flag as running
39-
callbacks.onRun(position)
41+
if(!subtasks){
42+
callbacks.onRun(position)
43+
}
4044

4145
letresult:{stdout:string|undefined;stderr:string|undefined}
4246
try{
@@ -79,6 +83,12 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks) => {
7983

8084
consttap:ParserOutput=parser(stdout||'')
8185

86+
if(subtasks){
87+
callbacks.onLoadSubtasks({summary:tap.summary})
88+
// exit early
89+
return
90+
}
91+
8292
addOutput({channel:logChannelName,text:tap.logs.join('\n'),show:false})
8393

8494
if(stderr){
@@ -105,7 +115,9 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks) => {
105115
// PASS
106116
if(tap.ok){
107117
clearOutput(failChannelName)
118+
108119
callbacks.onSuccess(position)
120+
109121
if(onSuccess){
110122
onSuccess()
111123
}

‎typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface Environment {
3939
}
4040

4141
exportinterfaceTestStatus{
42-
type:'success'|'warning'|'error'|'loading'
42+
type:'success'|'warning'|'error'|'loading'|'hidden'
4343
title:string
4444
content?:string
4545
summary?:{[testName:string]:boolean}

‎typings/tutorial.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type Step = {
2727
content:string
2828
setup:StepActions
2929
solution:Maybe<StepActions>
30+
subtasks?:{[testName:string]:boolean}
3031
}
3132

3233
/** A tutorial for use in VSCode CodeRoad */

‎web-app/src/components/Message/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Message as AlifdMessage } from '@alifd/next'
22
import*asReactfrom'react'
33

44
interfaceProps{
5-
type?:'success'|'warning'|'error'|'notice'|'help'|'loading'
5+
type?:'success'|'warning'|'error'|'notice'|'help'|'loading'|'hidden'
66
shape?:'inline'|'addon'|'toast'
77
size?:'medium'|'large'
88
title:string
@@ -16,6 +16,9 @@ interface Props {
1616

1717
constMessage=(props:Props)=>{
1818
const[visible,setVisible]=React.useState(true)
19+
if(props.type==='hidden'){
20+
returnnull
21+
}
1922
functiononClose(){
2023
if(props.onClose){
2124
props.onClose()

‎web-app/src/components/ProcessMessages/TestMessage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const durations = {
88
warning:20000,
99
error:4500,
1010
loading:300000,
11+
hidden:0,
1112
}
1213

1314
constuseTimeout=({ duration, key}:{duration:number;key:string})=>{

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,12 @@ const Level = ({
158158
returnnull
159159
}
160160
letsubtasks=null
161-
if(step.setup.subtasks){
162-
if(testStatus?.summary){
163-
subtasks=Object.keys(testStatus.summary).map((testName:string)=>({
164-
name:testName,
165-
//@ts-ignore typescript is wrong here
166-
pass:testStatus.summary[testName],
167-
}))
168-
}
161+
if(step.setup.subtasks&&testStatus?.summary){
162+
subtasks=Object.keys(testStatus.summary).map((testName:string)=>({
163+
name:testName,
164+
//@ts-ignore typescript is wrong here
165+
pass:testStatus.summary[testName],
166+
}))
169167
}
170168
return(
171169
<Step
@@ -184,7 +182,7 @@ const Level = ({
184182

185183
<divref={pageBottomRef}/>
186184

187-
{(testStatus||processes.length>0)&&(
185+
{((testStatus&&testStatus.type!=='hidden')||processes.length>0)&&(
188186
<divcss={styles.processes}>
189187
<ProcessMessagesprocesses={processes}testStatus={testStatus}onOpenLogs={onOpenLogs}/>
190188
</div>

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ export default (editorSend: any) => ({
5656
actions:step.setup,
5757
},
5858
})
59+
60+
if(step.setup.subtasks){
61+
// load subtask data by running tests and parsing result
62+
editorSend({
63+
type:'EDITOR_RUN_TEST',
64+
payload:{
65+
position:context.position,
66+
subtasks:true,
67+
},
68+
})
69+
}
5970
}
6071
},
6172
editorLoadSolution(context:T.MachineContext):void{

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ const testActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
2929
testClear:assign({
3030
testStatus:null,
3131
}),
32+
//@ts-ignore
33+
testSubtasks:assign({
34+
testStatus:(context,event)=>({
35+
type:'hidden',
36+
title:'',
37+
content:'',
38+
summary:event.payload.summary,
39+
}),
40+
}),
3241
}
3342

3443
exportdefaulttestActions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export const createMachine = (options: any) => {
170170
Normal:{
171171
id:'tutorial-level',
172172
on:{
173+
LOAD_TEST_SUBTASKS:{
174+
actions:['testSubtasks'],
175+
},
173176
TEST_RUNNING:'TestRunning',
174177
STEP_SOLUTION_LOAD:{
175178
actions:['editorLoadSolution'],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp