From d1647d4bf98fe32b24a627ead9667dc651a768e9 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 10 Apr 2021 11:36:19 -0700 Subject: [PATCH] fixup! fixup! fixup! fixup! fixup! test,debugger: migrate node-inspect tests to core --- test/common/inspector-cli.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/test/common/inspector-cli.js b/test/common/inspector-cli.js index 8268f34f941b35..d45eaa958b709b 100644 --- a/test/common/inspector-cli.js +++ b/test/common/inspector-cli.js @@ -14,11 +14,15 @@ function isPreBreak(output) { } function startCLI(args, flags = [], spawnOpts = {}) { + let stderrOutput = ''; const child = spawn(process.execPath, [...flags, 'inspect', ...args], spawnOpts); const outputBuffer = []; function bufferOutput(chunk) { + if (this === child.stderr) { + stderrOutput += chunk; + } outputBuffer.push(chunk); } @@ -32,7 +36,7 @@ function startCLI(args, flags = [], spawnOpts = {}) { child.stderr.on('data', bufferOutput); if (process.env.VERBOSE === '1') { - child.stdout.pipe(process.stderr); + child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); } @@ -59,10 +63,20 @@ function startCLI(args, flags = [], spawnOpts = {}) { } } - function onChildExit() { + function onChildClose(code, signal) { tearDown(); - reject(new Error( - `Child quit while waiting for ${pattern}; found: ${this.output}`)); + let message = 'Child exited'; + if (code) { + message += `, code ${code}`; + } + if (signal) { + message += `, signal ${signal}`; + } + message += ` while waiting for ${pattern}; found: ${this.output}`; + if (stderrOutput) { + message += `\n STDERR: ${stderrOutput}`; + } + reject(new Error(message)); } const timer = setTimeout(() => { @@ -76,10 +90,10 @@ function startCLI(args, flags = [], spawnOpts = {}) { function tearDown() { clearTimeout(timer); child.stdout.removeListener('data', checkOutput); - child.removeListener('exit', onChildExit); + child.removeListener('close', onChildClose); } - child.on('exit', onChildExit); + child.on('close', onChildClose); child.stdout.on('data', checkOutput); checkOutput(); }); @@ -156,7 +170,7 @@ function startCLI(args, flags = [], spawnOpts = {}) { quit() { return new Promise((resolve) => { child.stdin.end(); - child.on('exit', resolve); + child.on('close', resolve); }); }, };