@@ -20,14 +20,13 @@ const logChannelName = 'CodeRoad (Logs)'
2020
2121interface TestRunnerParams {
2222 position : T . Position
23- filter ?: string
2423 onSuccess ?: ( ) => void
2524}
2625
27- const createTestRunner = ( config : TT . TestRunnerConfig , callbacks : Callbacks ) => {
28- const testRunnerFilterArg = config . args ?. filter
29- return async ( { position , filter : testFilter , onSuccess } : TestRunnerParams ) : Promise < void > => {
30- logger ( 'createTestRunner' , position )
26+ const createTestRunner = ( data : TT . Tutorial , callbacks : Callbacks ) => {
27+ const testRunnerConfig = data . config . testRunner
28+ const testRunnerFilterArg = testRunnerConfig . args ?. filter
29+ return async ( { position, onSuccess } : TestRunnerParams ) : Promise < void > => {
3130 const startTime = throttle ( )
3231 // throttle time early
3332 if ( ! startTime ) {
@@ -41,17 +40,29 @@ const createTestRunner = (config: TT.TestRunnerConfig, callbacks: Callbacks) =>
4140
4241 let result : { stdout : string | undefined ; stderr : string | undefined }
4342 try {
44- let command = config . args ? `${ config . command } ${ config ?. args . tap } ` : config . command // TODO: enforce TAP
43+ let command = testRunnerConfig . args
44+ ? `${ testRunnerConfig . command } ${ testRunnerConfig ?. args . tap } `
45+ : testRunnerConfig . command // TODO: enforce TAP
4546
4647 // filter tests if requested
4748 if ( testRunnerFilterArg ) {
49+ // get tutorial step from position
50+ // check the step actions for specific command
51+ // NOTE: cannot just pass in step actions as the test can be called by:
52+ // - onEditorSave, onWatcher, onSolution, onRunTest, onSubTask
53+ const levels = data . levels
54+ const level = levels . find ( ( l ) => l . id === position . levelId )
55+ const step = level ?. steps . find ( ( s ) => s . id === position . stepId )
56+ const testFilter = step ?. setup ?. filter
4857 if ( testFilter ) {
49- command += ` ${ testRunnerFilterArg } ${ testFilter } `
58+ // append filter commands
59+ command = [ command , testRunnerFilterArg , testFilter ] . join ( ' ' )
5060 } else {
5161 throw new Error ( 'Test Runner filter not configured' )
5262 }
5363 }
54- result = await exec ( { command, dir : config . directory || config . path } ) // TODO: remove config.path later
64+ logger ( 'COMMAND' , command )
65+ result = await exec ( { command, dir : testRunnerConfig . directory || testRunnerConfig . path } ) // TODO: remove config.path later
5566 } catch ( err ) {
5667 result = { stdout : err . stdout , stderr : err . stack }
5768 }
0 commit comments