@@ -37,6 +37,14 @@ const MB = KB * KB;
37
37
cat . stdout . _handle . readStart = common . mustNotCall ( ) ;
38
38
grep . stdout . _handle . readStart = common . mustNotCall ( ) ;
39
39
40
+ // Keep an array of error codes and assert on them during process exit. This
41
+ // is because stdio can still be open when a child process exits, and we don't
42
+ // want to lose information about what caused the error.
43
+ const errors = [ ] ;
44
+ process . on ( 'exit' , ( ) => {
45
+ assert . deepStrictEqual ( errors , [ ] ) ;
46
+ } ) ;
47
+
40
48
[ cat , grep , wc ] . forEach ( ( child , index ) => {
41
49
const errorHandler = ( thing , type ) => {
42
50
// Don't want to assert here, as we might miss error code info.
@@ -46,7 +54,9 @@ const MB = KB * KB;
46
54
child . stderr . on ( 'data' , ( d ) => { errorHandler ( d , 'data' ) ; } ) ;
47
55
child . on ( 'error' , ( err ) => { errorHandler ( err , 'error' ) ; } ) ;
48
56
child . on ( 'exit' , common . mustCall ( ( code ) => {
49
- assert . strictEqual ( code , 0 , `child ${ index } exited with code ${ code } ` ) ;
57
+ if ( code !== 0 ) {
58
+ errors . push ( `child ${ index } exited with code ${ code } ` ) ;
59
+ }
50
60
} ) ) ;
51
61
} ) ;
52
62
0 commit comments