Skip to content

Commit

Permalink
test: fix test-runner-inspect
Browse files Browse the repository at this point in the history
PR-URL: nodejs#44620
Backport-PR-URL: nodejs#44873
Fixes: nodejs#44600
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
MoLow committed Oct 3, 2022
1 parent d02572c commit d351059
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ const {
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
ArrayPrototypePop,
ArrayPrototypePush,
ArrayPrototypeSlice,
ArrayPrototypeSort,
ObjectAssign,
PromisePrototypeThen,
RegExpPrototypeSymbolSplit,
SafePromiseAll,
SafeSet,
StringPrototypeEndsWith,
} = primordials;

const { Buffer } = require('buffer');
const { spawn } = require('child_process');
const { readdirSync, statSync } = require('fs');
// TODO(aduh95): switch to internal/readline/interface when backporting to Node.js 16.x is no longer a concern.
const { createInterface } = require('readline');
const console = require('internal/console/global');
const {
codes: {
Expand Down Expand Up @@ -114,28 +112,6 @@ function getRunArgs({ path, inspectPort }) {
return argv;
}

function makeStderrCallback(callback) {
if (!isUsingInspector()) {
return callback;
}
let buffer = Buffer.alloc(0);
return (data) => {
callback(data);
const newData = Buffer.concat([buffer, data]);
const str = newData.toString('utf8');
let lines = str;
if (StringPrototypeEndsWith(lines, '\n')) {
buffer = Buffer.alloc(0);
} else {
lines = RegExpPrototypeSymbolSplit(/\r?\n/, str);
buffer = Buffer.from(ArrayPrototypePop(lines), 'utf8');
lines = ArrayPrototypeJoin(lines, '\n');
}
if (isInspectorMessage(lines)) {
process.stderr.write(lines);
}
};
}

function runTestFile(path, root, inspectPort) {
const subtest = root.createSubtest(Test, path, async (t) => {
Expand All @@ -151,9 +127,18 @@ function runTestFile(path, root, inspectPort) {
err = error;
});

child.stderr.on('data', makeStderrCallback((data) => {
child.stderr.on('data', (data) => {
stderr += data;
}));
});

if (isUsingInspector()) {
const rl = createInterface({ input: child.stderr });
rl.on('line', (line) => {
if (isInspectorMessage(line)) {
process.stderr.write(line + '\n');
}
});
}

const { 0: { 0: code, 1: signal }, 1: stdout } = await SafePromiseAll([
once(child, 'exit', { signal: t.signal }),
Expand Down

0 comments on commit d351059

Please sign in to comment.