1+ import * as T from 'typings'
12import * as TT from 'typings/tutorial'
23import * as vscode from 'vscode'
3- import createTestRunner , { Payload } from '../services/testRunner'
4+ import createTestRunner from '../services/testRunner'
45import { setupActions } from '../actions/setupActions'
56import createWebView from '../webview'
7+ import logger from '../services/logger'
68
79export const COMMANDS = {
810 START : 'coderoad.start' ,
911 OPEN_WEBVIEW : 'coderoad.open_webview' ,
1012 CONFIG_TEST_RUNNER : 'coderoad.config_test_runner' ,
1113 RUN_TEST : 'coderoad.run_test' ,
12- SET_CURRENT_STEP : 'coderoad.set_current_step ' ,
14+ SET_CURRENT_POSITION : 'coderoad.set_current_position ' ,
1315}
1416
1517interface CreateCommandProps {
@@ -20,7 +22,7 @@ interface CreateCommandProps {
2022export const createCommands = ( { extensionPath, workspaceState } : CreateCommandProps ) => {
2123 // React panel webview
2224 let webview : any
23- let currentStepId : string | null = ''
25+ let currentPosition : T . Position
2426 let testRunner : any
2527
2628 return {
@@ -55,32 +57,38 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
5557 await setupActions ( { actions : config . actions , send : webview . send , path : config . path } )
5658 }
5759 testRunner = createTestRunner ( config , {
58- onSuccess : ( payload : Payload ) => {
60+ onSuccess : ( position : T . Position ) => {
61+ logger ( 'test pass position' , position )
5962 // send test pass message back to client
60- webview . send ( { type : 'TEST_PASS' , payload } )
63+ webview . send ( { type : 'TEST_PASS' , payload : { position } } )
6164 } ,
62- onFail : ( payload : Payload , message : string ) => {
65+ onFail : ( position : T . Position , message : string ) => {
6366 // send test fail message back to client with failure message
64- webview . send ( { type : 'TEST_FAIL' , payload : { ... payload , message } } )
67+ webview . send ( { type : 'TEST_FAIL' , payload : { position , message } } )
6568 } ,
66- onError : ( payload : Payload ) => {
67- // send test error message back to client
68- webview . send ( { type : 'TEST_ERROR' , payload } )
69+ onError : ( position : T . Position ) => {
70+ // TODO: send test error message back to client
71+ const message = 'Error with test runner'
72+ webview . send ( { type : 'TEST_ERROR' , payload : { position, message } } )
6973 } ,
70- onRun : ( payload : Payload ) => {
74+ onRun : ( position : T . Position ) => {
7175 // send test run message back to client
72- webview . send ( { type : 'TEST_RUNNING' , payload } )
76+ webview . send ( { type : 'TEST_RUNNING' , payload : { position } } )
7377 } ,
7478 } )
7579 } ,
76- [ COMMANDS . SET_CURRENT_STEP ] : ( { stepId } : Payload ) => {
80+ [ COMMANDS . SET_CURRENT_POSITION ] : ( position : T . Position ) => {
7781 // set from last setup stepAction
78- currentStepId = stepId
82+ currentPosition = position
7983 } ,
80- [ COMMANDS . RUN_TEST ] : ( current : Payload | undefined , onSuccess : ( ) => void ) => {
84+ [ COMMANDS . RUN_TEST ] : ( callback ?: { onSuccess : ( ) => void } ) => {
85+ logger ( 'run test current' , currentPosition )
8186 // use stepId from client, or last set stepId
82- const payload : Payload = { stepId : current && current . stepId ?. length ? current . stepId : currentStepId }
83- testRunner ( payload , onSuccess )
87+ // const position: T.Position = {
88+ // ...current,
89+ // stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
90+ // }
91+ testRunner ( currentPosition , callback ?. onSuccess )
8492 } ,
8593 }
8694}
0 commit comments