77const spawn = require ( 'child_process' ) . spawn
88const kill = require ( 'tree-kill' ) ;
99
10+ const TIMEOUT_MS = 5 * 60 * 1000 ; // 5 minutes
11+
1012const spawned_process = spawn ( 'npm' , [ 'start' , `apps.automated.${ process . argv [ 2 ] } ` ] , {
1113 stdio : [ 'inherit' , 'pipe' , 'pipe' ]
1214} )
13-
1415const { stdout, stderr} = spawned_process
1516
1617stdout . pipe ( process . stdout )
1718stderr . pipe ( process . stderr )
1819
1920let lineBuffer = [ ]
21+ let timeout_id ;
22+
23+ function exit ( code ) {
24+ kill ( spawned_process . pid )
25+ process . exit ( code )
26+ }
27+
28+ function onTimeout ( ) {
29+ console . log ( `Tests TIMEOUT (${ TIMEOUT_MS } ms)` )
30+ exit ( 1 )
31+ }
32+
33+ function healthCheck ( ) {
34+ clearTimeout ( timeout_id )
35+ timeout_id = setTimeout ( onTimeout , TIMEOUT_MS )
36+ }
2037
2138stdout . on ( 'data' , data => {
39+ healthCheck ( ) ;
2240 const line = data . toString ( ) ;
2341
2442 // start buffering lines when tests are complete
@@ -29,8 +47,6 @@ stdout.on('data', data => {
2947 if ( line . includes ( 'Tests EOF!' ) ) {
3048 let ok = lineBuffer . join ( '\n' ) . includes ( 'OK, 0 failed' )
3149 console . log ( ok ? 'Tests PASSED' : 'Tests FAILED' ) ;
32- kill ( spawned_process . pid )
33- process . exit ( ok ? 0 : 1 )
50+ exit ( ok ? 0 : 1 )
3451 }
3552} )
36-
0 commit comments