1+ import * as G from 'typings/graphql'
12import * as vscode from 'vscode'
23import ReactWebView from './ReactWebView'
3- import runTest from '../actions/runTest '
4+ import createTestRunner , { Payload } from '../services/testRunner '
45
56const COMMANDS = {
67 START : 'coderoad.start' ,
78 OPEN_WEBVIEW : 'coderoad.open_webview' ,
9+ CONFIG_TEST_RUNNER : 'coderoad.config_test_runner' ,
810 RUN_TEST : 'coderoad.run_test' ,
911 SET_CURRENT_STEP : 'coderoad.set_current_step' ,
1012}
@@ -19,6 +21,7 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
1921 // React panel webview
2022 let webview : any
2123 let currentStepId = ''
24+ let testRunner : any
2225
2326 return {
2427 // initialize
@@ -49,37 +52,38 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
4952 // setup 1x1 horizontal layout
5053 webview . createOrShow ( )
5154 } ,
52- [ COMMANDS . SET_CURRENT_STEP ] : ( { stepId} : { stepId : string } ) => {
53- // NOTE: as async, may sometimes be inaccurate
54- // set from last setup stepAction
55- currentStepId = stepId
56- } ,
57- [ COMMANDS . RUN_TEST ] : ( current : { stepId : string } | undefined , onSuccess : ( ) => void ) => {
58- console . log ( '-------- command.run_test ------ ' )
59- // use stepId from client, or last set stepId
60- const payload = { stepId : current ? current . stepId : currentStepId }
61- runTest ( {
62- onSuccess : ( ) => {
55+ [ COMMANDS . CONFIG_TEST_RUNNER ] : ( config : G . TutorialTestRunner ) => {
56+ testRunner = createTestRunner ( config , {
57+ onSuccess : ( payload : Payload ) => {
6358 // send test pass message back to client
64- webview . send ( { type : 'TEST_PASS' , payload} )
65- onSuccess ( )
6659 vscode . window . showInformationMessage ( 'PASS' )
60+ webview . send ( { type : 'TEST_PASS' , payload} )
6761 } ,
68- onFail : ( ) => {
62+ onFail : ( payload : Payload ) => {
6963 // send test fail message back to client
70- webview . send ( { type : 'TEST_FAIL' , payload} )
7164 vscode . window . showWarningMessage ( 'FAIL' )
65+ webview . send ( { type : 'TEST_FAIL' , payload} )
7266 } ,
73- onError : ( ) => {
74- console . log ( 'COMMAND TEST_ERROR' )
67+ onError : ( payload : Payload ) => {
7568 // send test error message back to client
7669 webview . send ( { type : 'TEST_ERROR' , payload} )
7770 } ,
78- onRun : ( ) => {
71+ onRun : ( payload : Payload ) => {
7972 // send test run message back to client
8073 webview . send ( { type : 'TEST_RUNNING' , payload} )
8174 }
8275 } )
8376 } ,
77+ [ COMMANDS . SET_CURRENT_STEP ] : ( { stepId} : Payload ) => {
78+ // NOTE: as async, may sometimes be inaccurate
79+ // set from last setup stepAction
80+ currentStepId = stepId
81+ } ,
82+ [ COMMANDS . RUN_TEST ] : ( current : Payload | undefined , onSuccess : ( ) => void ) => {
83+ console . log ( '-------- command.run_test ------ ' )
84+ // use stepId from client, or last set stepId
85+ const payload : Payload = { stepId : current ? current . stepId : currentStepId }
86+ testRunner ( payload , onSuccess )
87+ } ,
8488 }
8589}
0 commit comments