@@ -14,11 +14,15 @@ function isPreBreak(output) {
14
14
}
15
15
16
16
function startCLI ( args , flags = [ ] , spawnOpts = { } ) {
17
+ let stderrOutput = '' ;
17
18
const child =
18
19
spawn ( process . execPath , [ ...flags , 'inspect' , ...args ] , spawnOpts ) ;
19
20
20
21
const outputBuffer = [ ] ;
21
22
function bufferOutput ( chunk ) {
23
+ if ( this === child . stderr ) {
24
+ stderrOutput += chunk ;
25
+ }
22
26
outputBuffer . push ( chunk ) ;
23
27
}
24
28
@@ -32,7 +36,7 @@ function startCLI(args, flags = [], spawnOpts = {}) {
32
36
child . stderr . on ( 'data' , bufferOutput ) ;
33
37
34
38
if ( process . env . VERBOSE === '1' ) {
35
- child . stdout . pipe ( process . stderr ) ;
39
+ child . stdout . pipe ( process . stdout ) ;
36
40
child . stderr . pipe ( process . stderr ) ;
37
41
}
38
42
@@ -59,10 +63,20 @@ function startCLI(args, flags = [], spawnOpts = {}) {
59
63
}
60
64
}
61
65
62
- function onChildExit ( ) {
66
+ function onChildClose ( code , signal ) {
63
67
tearDown ( ) ;
64
- reject ( new Error (
65
- `Child quit while waiting for ${ pattern } ; found: ${ this . output } ` ) ) ;
68
+ let message = 'Child exited' ;
69
+ if ( code ) {
70
+ message += `, code ${ code } ` ;
71
+ }
72
+ if ( signal ) {
73
+ message += `, signal ${ signal } ` ;
74
+ }
75
+ message += ` while waiting for ${ pattern } ; found: ${ this . output } ` ;
76
+ if ( stderrOutput ) {
77
+ message += `\n STDERR: ${ stderrOutput } ` ;
78
+ }
79
+ reject ( new Error ( message ) ) ;
66
80
}
67
81
68
82
const timer = setTimeout ( ( ) => {
@@ -76,10 +90,10 @@ function startCLI(args, flags = [], spawnOpts = {}) {
76
90
function tearDown ( ) {
77
91
clearTimeout ( timer ) ;
78
92
child . stdout . removeListener ( 'data' , checkOutput ) ;
79
- child . removeListener ( 'exit ' , onChildExit ) ;
93
+ child . removeListener ( 'close ' , onChildClose ) ;
80
94
}
81
95
82
- child . on ( 'exit ' , onChildExit ) ;
96
+ child . on ( 'close ' , onChildClose ) ;
83
97
child . stdout . on ( 'data' , checkOutput ) ;
84
98
checkOutput ( ) ;
85
99
} ) ;
@@ -156,7 +170,7 @@ function startCLI(args, flags = [], spawnOpts = {}) {
156
170
quit ( ) {
157
171
return new Promise ( ( resolve ) => {
158
172
child . stdin . end ( ) ;
159
- child . on ( 'exit ' , resolve ) ;
173
+ child . on ( 'close ' , resolve ) ;
160
174
} ) ;
161
175
} ,
162
176
} ;
0 commit comments