@@ -2,9 +2,9 @@ import * as T from 'typings'
22import * as TT from 'typings/tutorial'
33import * as vscode from 'vscode'
44import createTestRunner from './services/testRunner'
5- import { onSetupActions } from './actions/onActions'
65import createWebView from './services/webview'
76import logger from './services/logger'
7+ import * as hooks from './services/hooks'
88
99export const COMMANDS = {
1010 START : 'coderoad.start' ,
@@ -19,6 +19,16 @@ interface CreateCommandProps {
1919 workspaceState : vscode . Memento
2020}
2121
22+ let sendToClient = ( action : T . Action ) : void => {
23+ // function is replaced when webclient loads
24+ }
25+
26+ // This makes it easier to pass the send
27+ // function throughout the codebase
28+ export const send = ( action : T . Action ) : void => {
29+ sendToClient ( action )
30+ }
31+
2232export const createCommands = ( { extensionPath, workspaceState } : CreateCommandProps ) : { [ key : string ] : any } => {
2333 // React panel webview
2434 let webview : any
@@ -36,41 +46,37 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
3646 extensionPath,
3747 workspaceState,
3848 } )
49+ // make send to client function exportable
50+ // as "send".
51+ sendToClient = webview . send
3952 }
4053 } ,
4154 [ COMMANDS . CONFIG_TEST_RUNNER ] : async ( data : TT . Tutorial ) => {
42- const testRunnerConfig = data . config . testRunner
43- const setup = testRunnerConfig . setup || testRunnerConfig . actions // TODO: deprecate and remove config.actions
44- if ( setup ) {
45- // setup tutorial test runner commits
46- // assumes git already exists
47- await onSetupActions ( {
48- actions : setup ,
49- send : webview . send ,
50- dir : testRunnerConfig . directory || testRunnerConfig . path ,
51- } ) // TODO: deprecate and remove config.path
55+ const setupActions = data . config . setup
56+ if ( setupActions ) {
57+ hooks . onInit ( setupActions )
5258 }
5359 testRunner = createTestRunner ( data , {
5460 onSuccess : ( position : T . Position ) => {
5561 logger ( 'test pass position' , position )
5662 // send test pass message back to client
57- webview . send ( { type : 'TEST_PASS' , payload : { position : { ...position , complete : true } } } )
63+ send ( { type : 'TEST_PASS' , payload : { position : { ...position , complete : true } } } )
5864 } ,
5965 onFail : ( position : T . Position , failSummary : T . TestFail ) : void => {
6066 // send test fail message back to client with failure message
61- webview . send ( { type : 'TEST_FAIL' , payload : { position, fail : failSummary } } )
67+ send ( { type : 'TEST_FAIL' , payload : { position, fail : failSummary } } )
6268 } ,
6369 onError : ( position : T . Position ) => {
6470 // TODO: send test error message back to client
6571 const message = 'Error with test runner'
66- webview . send ( { type : 'TEST_ERROR' , payload : { position, message } } )
72+ send ( { type : 'TEST_ERROR' , payload : { position, message } } )
6773 } ,
6874 onRun : ( position : T . Position ) => {
6975 // send test run message back to client
70- webview . send ( { type : 'TEST_RUNNING' , payload : { position } } )
76+ send ( { type : 'TEST_RUNNING' , payload : { position } } )
7177 } ,
7278 onLoadSubtasks : ( { summary } ) => {
73- webview . send ( { type : 'LOAD_SUBTASK_RESULTS' , payload : { summary } } )
79+ send ( { type : 'LOAD_SUBTASK_RESULTS' , payload : { summary } } )
7480 } ,
7581 } )
7682 } ,
@@ -85,7 +91,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
8591 testRunner ( { position : currentPosition , onSuccess : callbacks ?. onSuccess , subtasks } )
8692 } ,
8793 [ COMMANDS . ENTER ] : ( ) => {
88- webview . send ( { type : 'KEY_PRESS_ENTER' } )
94+ send ( { type : 'KEY_PRESS_ENTER' } )
8995 } ,
9096 }
9197}
0 commit comments