Skip to content

Commit d1647d4

Browse files
committed
fixup! fixup! fixup! fixup! fixup! test,debugger: migrate node-inspect tests to core
1 parent c9e09fc commit d1647d4

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

test/common/inspector-cli.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ function isPreBreak(output) {
1414
}
1515

1616
function startCLI(args, flags = [], spawnOpts = {}) {
17+
let stderrOutput = '';
1718
const child =
1819
spawn(process.execPath, [...flags, 'inspect', ...args], spawnOpts);
1920

2021
const outputBuffer = [];
2122
function bufferOutput(chunk) {
23+
if (this === child.stderr) {
24+
stderrOutput += chunk;
25+
}
2226
outputBuffer.push(chunk);
2327
}
2428

@@ -32,7 +36,7 @@ function startCLI(args, flags = [], spawnOpts = {}) {
3236
child.stderr.on('data', bufferOutput);
3337

3438
if (process.env.VERBOSE === '1') {
35-
child.stdout.pipe(process.stderr);
39+
child.stdout.pipe(process.stdout);
3640
child.stderr.pipe(process.stderr);
3741
}
3842

@@ -59,10 +63,20 @@ function startCLI(args, flags = [], spawnOpts = {}) {
5963
}
6064
}
6165

62-
function onChildExit() {
66+
function onChildClose(code, signal) {
6367
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));
6680
}
6781

6882
const timer = setTimeout(() => {
@@ -76,10 +90,10 @@ function startCLI(args, flags = [], spawnOpts = {}) {
7690
function tearDown() {
7791
clearTimeout(timer);
7892
child.stdout.removeListener('data', checkOutput);
79-
child.removeListener('exit', onChildExit);
93+
child.removeListener('close', onChildClose);
8094
}
8195

82-
child.on('exit', onChildExit);
96+
child.on('close', onChildClose);
8397
child.stdout.on('data', checkOutput);
8498
checkOutput();
8599
});
@@ -156,7 +170,7 @@ function startCLI(args, flags = [], spawnOpts = {}) {
156170
quit() {
157171
return new Promise((resolve) => {
158172
child.stdin.end();
159-
child.on('exit', resolve);
173+
child.on('close', resolve);
160174
});
161175
},
162176
};

0 commit comments

Comments
 (0)