@@ -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,14 @@ interface CreateCommandProps {
1919 workspaceState : vscode . Memento
2020}
2121
22+ let sendToClient = ( action : T . Action ) : void => {
23+ /* */
24+ }
25+
26+ export const send = ( action : T . Action ) : void => {
27+ sendToClient ( action )
28+ }
29+
2230export const createCommands = ( { extensionPath, workspaceState } : CreateCommandProps ) : { [ key : string ] : any } => {
2331 // React panel webview
2432 let webview : any
@@ -30,6 +38,10 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
3038 [ COMMANDS . START ] : async ( ) => {
3139 if ( webview && webview . state . loaded ) {
3240 webview . createOrShow ( )
41+ // make send to client function exportable
42+ // as "send". This makes it easier to pass the send
43+ // function throughout the codebase
44+ sendToClient = webview . send
3345 } else {
3446 // activate machine
3547 webview = createWebView ( {
@@ -39,38 +51,31 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
3951 }
4052 } ,
4153 [ 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
54+ const setupActions = data . config . setup
55+ if ( setupActions ) {
56+ hooks . onInit ( setupActions )
5257 }
5358 testRunner = createTestRunner ( data , {
5459 onSuccess : ( position : T . Position ) => {
5560 logger ( 'test pass position' , position )
5661 // send test pass message back to client
57- webview . send ( { type : 'TEST_PASS' , payload : { position : { ...position , complete : true } } } )
62+ send ( { type : 'TEST_PASS' , payload : { position : { ...position , complete : true } } } )
5863 } ,
5964 onFail : ( position : T . Position , failSummary : T . TestFail ) : void => {
6065 // send test fail message back to client with failure message
61- webview . send ( { type : 'TEST_FAIL' , payload : { position, fail : failSummary } } )
66+ send ( { type : 'TEST_FAIL' , payload : { position, fail : failSummary } } )
6267 } ,
6368 onError : ( position : T . Position ) => {
6469 // TODO: send test error message back to client
6570 const message = 'Error with test runner'
66- webview . send ( { type : 'TEST_ERROR' , payload : { position, message } } )
71+ send ( { type : 'TEST_ERROR' , payload : { position, message } } )
6772 } ,
6873 onRun : ( position : T . Position ) => {
6974 // send test run message back to client
70- webview . send ( { type : 'TEST_RUNNING' , payload : { position } } )
75+ send ( { type : 'TEST_RUNNING' , payload : { position } } )
7176 } ,
7277 onLoadSubtasks : ( { summary } ) => {
73- webview . send ( { type : 'LOAD_SUBTASK_RESULTS' , payload : { summary } } )
78+ send ( { type : 'LOAD_SUBTASK_RESULTS' , payload : { summary } } )
7479 } ,
7580 } )
7681 } ,
@@ -85,7 +90,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
8590 testRunner ( { position : currentPosition , onSuccess : callbacks ?. onSuccess , subtasks } )
8691 } ,
8792 [ COMMANDS . ENTER ] : ( ) => {
88- webview . send ( { type : 'KEY_PRESS_ENTER' } )
93+ send ( { type : 'KEY_PRESS_ENTER' } )
8994 } ,
9095 }
9196}
0 commit comments