@@ -14,7 +14,8 @@ function buildExecRunner(failedByAssert, runOpts) {
1414 } = runOpts
1515
1616 const executeCommandAsync = ( cmd , index ) => new Promise ( ( resolve ) => {
17- let watcher = null
17+ let execProc = null
18+
1819 let additionalOpts = null
1920 let originalCmd = cmd
2021 let specificCallBack = null
@@ -23,8 +24,7 @@ function buildExecRunner(failedByAssert, runOpts) {
2324 /**
2425 * @now this variable will be used for process kill if time more than @longestProcessTime
2526 */
26- const now = + Date . now ( )
27-
27+ const startTime = + Date . now ( )
2828
2929 /**
3030 * @param {undefined|function } addSpecificOptions if function cmd will go to this function as argument
@@ -44,30 +44,49 @@ function buildExecRunner(failedByAssert, runOpts) {
4444 }
4545 }
4646
47- if ( debugProcess ) { console . log ( cmd ) }
47+ execProc = exec ( cmd , execOpts , ( error , stdout , stderr ) => {
48+ if ( debugProcess ) {
49+ console . log ( '___________________________________________________________________________' )
50+ console . log ( `command for process: ${ cmd } ` )
51+ console . log ( `stdout: ${ stdout } ` ) ;
52+ console . error ( `stderr: ${ stderr } ` ) ;
53+ console . error ( `error ${ error } ` )
54+ console . log ( '___________________________________________________________________________' )
55+ }
56+
57+ executionStack += `${ stdout } ${ stderr } `
58+ } )
4859
49- const proc = exec ( cmd , execOpts )
5060
51- const killTooLongExecution = ( proc ) => {
52- if ( now - Date . now ( ) < longestProcessTime ) {
53- proc . kill ( )
61+ const killTooLongExecution = ( procWhatShouldBekilled ) => {
62+ if ( + Date . now ( ) - startTime > longestProcessTime ) {
63+ procWhatShouldBekilled . kill ( )
5464 }
5565 }
5666
57- watcher = setInterval ( ( ) => killTooLongExecution ( proc ) , 5000 )
67+ const watcher = setInterval ( ( ) => killTooLongExecution ( execProc ) , 5000 )
5868
59- proc . on ( 'exit' , ( ) => { clearInterval ( watcher ) } )
69+ execProc . on ( 'exit' , ( ) => {
70+ if ( debugProcess ) {
71+ console . log ( 'EXIT PROCESS' )
72+ }
73+ } )
6074
61- proc . stdout . on ( 'data' , ( data ) => {
62- executionStack += data . toString ( )
75+ execProc . on ( 'close' , ( ) => {
76+ if ( debugProcess ) {
77+ console . log ( 'CLOSE PROCESS' )
78+ }
79+ clearInterval ( watcher )
6380 } )
64- proc . stderr . on ( 'data' , ( data ) => console . log ( data . toString ( 'utf8' ) ) )
65- proc . on ( 'error' , ( e ) => { console . error ( e ) } )
6681
67- proc . on ( 'close' , async ( code ) => {
82+ execProc . on ( 'error' , ( e ) => { console . error ( e ) } )
83+
84+ execProc . on ( 'close' , async ( code ) => {
85+ // clear watcher interval
86+ clearInterval ( watcher )
87+
6888 let commandToRerun = null
6989
70- if ( debugProcess ) { console . log ( executionStack , code ) }
7190
7291 // if process code 0 - exit as a success result
7392 if ( code === 0 ) {
0 commit comments