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,7 +22,7 @@ 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 )
@@ -31,41 +31,36 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
3131 try {
3232 result = await node . exec ( config . command )
3333 } catch ( err ) {
34- result = err
34+ result = { stdout : err . stdout , stderr : err . stack }
3535 }
3636 const { stdout, stderr } = result
3737
38- // simple way to throttle requests
39- if ( ! stdout ) {
40- return
41- }
42-
38+ const tap = parser ( stdout || '' )
4339 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
40+ // failures also trigger stderr
41+ if ( stdout && stdout . length && ! tap . ok ) {
42+ const message = tap . message ? tap . message : ''
43+ callbacks . onFail ( payload , message )
44+ return
45+ } else {
46+ callbacks . onError ( payload )
47+ // open terminal with error string
48+ const channel = getOutputChannel ( outputChannelName )
49+ channel . show ( false )
50+ channel . appendLine ( stderr )
51+ return
52+ }
5153 }
5254
53- // pass or fail?
54- const tap = parser ( stdout )
55+ // success!
5556 if ( tap . ok ) {
5657 callbacks . onSuccess ( payload )
5758 if ( onSuccess ) {
5859 onSuccess ( )
5960 }
6061 } 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 )
62+ // should never get here
63+ callbacks . onError ( payload )
6964 }
7065 }
7166}
0 commit comments