Skip to content

Commit

Permalink
test_runner: dont split lines on test:stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed May 23, 2023
1 parent 92a938b commit fbb24cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/reporter/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SpecReporter extends Transform {
break;
case 'test:stderr':
case 'test:stdout':
return `${data.message}\n`;
return data.message;
case 'test:diagnostic':
return `${colors[type]}${this.#indent(data.nesting)}${symbols[type]}${data.message}${white}\n`;
case 'test:coverage':
Expand Down
10 changes: 8 additions & 2 deletions lib/internal/test_runner/reporter/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ async function * tapReporter(source) {
yield `${indent(data.nesting)}# Subtest: ${tapEscape(data.name)}\n`;
break;
case 'test:stderr':
case 'test:stdout':
case 'test:diagnostic':
case 'test:stdout': {
const lines = StringPrototypeSplit(data.message, kLineBreakRegExp);
for (let i = 0; i < lines.length; i++) {
if (lines[i].length === 0) continue;
yield `${indent(data.nesting)}# ${tapEscape(lines[i])}${i < lines.length - 1 ? '\n' : ''}`;
}
break;
} case 'test:diagnostic':
yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`;
break;
case 'test:coverage':
Expand Down
19 changes: 6 additions & 13 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ const {
ArrayPrototypeSlice,
ArrayPrototypeSome,
ArrayPrototypeSort,
hardenRegExp,
ObjectAssign,
PromisePrototypeThen,
SafePromiseAll,
SafePromiseAllReturnVoid,
SafePromiseAllSettledReturnVoid,
PromiseResolve,
RegExpPrototypeSymbolSplit,
SafeMap,
SafeSet,
StringPrototypeIndexOf,
Expand Down Expand Up @@ -75,7 +73,6 @@ const {
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
const kSplitLine = hardenRegExp(/\r?\n/);

const kCanceledTests = new SafeSet()
.add(kCancelledByParent).add(kAborted).add(kTestTimeoutFailure);
Expand Down Expand Up @@ -280,15 +277,11 @@ class FileTest extends Test {
}

if (TypedArrayPrototypeGetLength(nonSerialized) > 0) {
const messages = RegExpPrototypeSymbolSplit(kSplitLine, nonSerialized.toString('utf-8'));
for (let i = 0; i < messages.length; i++) {
const message = messages[i];
this.addToReport({
__proto__: null,
type: 'test:stdout',
data: { __proto__: null, file: this.name, message },
});
}
this.addToReport({
__proto__: null,
type: 'test:stdout',
data: { __proto__: null, file: this.name, message: nonSerialized.toString('utf-8') },
});
}

while (bufferHead?.length >= kSerializedSizeHeader) {
Expand Down Expand Up @@ -362,7 +355,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
subtest.addToReport({
__proto__: null,
type: 'test:stderr',
data: { __proto__: null, file: path, message: line },
data: { __proto__: null, file: path, message: line + '\n' },
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/test-runner/output/arbitrary-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const { Buffer } = require('buffer');

for await (const chunk of reported) {
process.stdout.write(chunk);
process.stdout.write(Buffer.concat([Buffer.from("arbitrary - pre"), chunk]));
process.stdout.write(Buffer.from("arbitrary - mid"));
process.stdout.write(Buffer.concat([chunk, Buffer.from("arbitrary - post")]));
process.stdout.write(Buffer.concat([Buffer.from("arbitrary - pre\n"), chunk]));
process.stdout.write(Buffer.from("arbitrary - mid\n"));
process.stdout.write(Buffer.concat([chunk, Buffer.from("arbitrary - post\n")]));
}
})();

0 comments on commit fbb24cf

Please sign in to comment.