Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test-runner-inspect #44620

Merged
merged 2 commits into from Sep 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 12 additions & 28 deletions lib/internal/test_runner/runner.js
Expand Up @@ -4,21 +4,18 @@ 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');
const readline = require('readline/promises');
MoLow marked this conversation as resolved.
Show resolved Hide resolved
const console = require('internal/console/global');
const {
codes: {
Expand Down Expand Up @@ -114,28 +111,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 +126,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 = readline.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