11import node from '../../services/node'
22import { getOutputChannel } from '../../editor/outputChannel'
33import parser from './parser'
4- import { setLatestProcess , isLatestProcess } from './throttle'
4+ // import { setLatestProcess, isLatestProcess } from './throttle'
55
66export interface Payload {
77 stepId : string
@@ -22,50 +22,46 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
2222 const outputChannelName = 'TEST_OUTPUT'
2323
2424 return async ( payload : Payload , onSuccess ?: ( ) => void ) : Promise < void > => {
25- console . log ( '------------------- run test ------------------' )
25+ console . log ( '------------------- RUN TEST - ------------------' )
2626
2727 // flag as running
2828 callbacks . onRun ( payload )
2929
3030 let result : { stdout : string | undefined ; stderr : string | undefined }
3131 try {
32- result = await node . exec ( config . command )
32+ result = await node . exec ( 'npm test' )
3333 } catch ( err ) {
34- result = err
34+ console . log ( err )
35+ result = { stdout : err . stdout , stderr : err . stack }
3536 }
3637 const { stdout, stderr } = result
3738
38- // simple way to throttle requests
39- if ( ! stdout ) {
40- return
41- }
42-
39+ const tap = parser ( stdout || '' )
4340 if ( stderr ) {
44- callbacks . onError ( payload )
45-
46- // open terminal with error string
47- const channel = getOutputChannel ( outputChannelName )
48- channel . show ( false )
49- channel . appendLine ( stderr )
50- return
41+ // failures also trigger stderr
42+ if ( stdout && stdout . length && ! tap . ok ) {
43+ const message = tap . message ? tap . message : ''
44+ callbacks . onFail ( payload , message )
45+ return
46+ } else {
47+ callbacks . onError ( payload )
48+ // open terminal with error string
49+ const channel = getOutputChannel ( outputChannelName )
50+ channel . show ( false )
51+ channel . appendLine ( stderr )
52+ return
53+ }
5154 }
5255
53- // pass or fail?
54- const tap = parser ( stdout )
56+ // success!
5557 if ( tap . ok ) {
5658 callbacks . onSuccess ( payload )
5759 if ( onSuccess ) {
5860 onSuccess ( )
5961 }
6062 } else {
61- // TODO: consider logging output to channel
62- // open terminal with failed test string
63- // const channel = getOutputChannel(outputChannelName)
64- // channel.show(false)
65- // channel.appendLine(tap.message)
66-
67- const message = tap . message ? tap . message : ''
68- callbacks . onFail ( payload , message )
63+ // should never get here
64+ callbacks . onError ( payload )
6965 }
7066 }
7167}
0 commit comments