Skip to content

Commit fbb24cf

Browse files
committed
test_runner: dont split lines on test:stdout
1 parent 92a938b commit fbb24cf

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

lib/internal/test_runner/reporter/spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class SpecReporter extends Transform {
119119
break;
120120
case 'test:stderr':
121121
case 'test:stdout':
122-
return `${data.message}\n`;
122+
return data.message;
123123
case 'test:diagnostic':
124124
return `${colors[type]}${this.#indent(data.nesting)}${symbols[type]}${data.message}${white}\n`;
125125
case 'test:coverage':

lib/internal/test_runner/reporter/tap.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ async function * tapReporter(source) {
4646
yield `${indent(data.nesting)}# Subtest: ${tapEscape(data.name)}\n`;
4747
break;
4848
case 'test:stderr':
49-
case 'test:stdout':
50-
case 'test:diagnostic':
49+
case 'test:stdout': {
50+
const lines = StringPrototypeSplit(data.message, kLineBreakRegExp);
51+
for (let i = 0; i < lines.length; i++) {
52+
if (lines[i].length === 0) continue;
53+
yield `${indent(data.nesting)}# ${tapEscape(lines[i])}${i < lines.length - 1 ? '\n' : ''}`;
54+
}
55+
break;
56+
} case 'test:diagnostic':
5157
yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`;
5258
break;
5359
case 'test:coverage':

lib/internal/test_runner/runner.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ const {
1111
ArrayPrototypeSlice,
1212
ArrayPrototypeSome,
1313
ArrayPrototypeSort,
14-
hardenRegExp,
1514
ObjectAssign,
1615
PromisePrototypeThen,
1716
SafePromiseAll,
1817
SafePromiseAllReturnVoid,
1918
SafePromiseAllSettledReturnVoid,
2019
PromiseResolve,
21-
RegExpPrototypeSymbolSplit,
2220
SafeMap,
2321
SafeSet,
2422
StringPrototypeIndexOf,
@@ -75,7 +73,6 @@ const {
7573
const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
7674
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
7775
const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
78-
const kSplitLine = hardenRegExp(/\r?\n/);
7976

8077
const kCanceledTests = new SafeSet()
8178
.add(kCancelledByParent).add(kAborted).add(kTestTimeoutFailure);
@@ -280,15 +277,11 @@ class FileTest extends Test {
280277
}
281278

282279
if (TypedArrayPrototypeGetLength(nonSerialized) > 0) {
283-
const messages = RegExpPrototypeSymbolSplit(kSplitLine, nonSerialized.toString('utf-8'));
284-
for (let i = 0; i < messages.length; i++) {
285-
const message = messages[i];
286-
this.addToReport({
287-
__proto__: null,
288-
type: 'test:stdout',
289-
data: { __proto__: null, file: this.name, message },
290-
});
291-
}
280+
this.addToReport({
281+
__proto__: null,
282+
type: 'test:stdout',
283+
data: { __proto__: null, file: this.name, message: nonSerialized.toString('utf-8') },
284+
});
292285
}
293286

294287
while (bufferHead?.length >= kSerializedSizeHeader) {
@@ -362,7 +355,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
362355
subtest.addToReport({
363356
__proto__: null,
364357
type: 'test:stderr',
365-
data: { __proto__: null, file: path, message: line },
358+
data: { __proto__: null, file: path, message: line + '\n' },
366359
});
367360
});
368361

test/fixtures/test-runner/output/arbitrary-output.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const { Buffer } = require('buffer');
1212

1313
for await (const chunk of reported) {
1414
process.stdout.write(chunk);
15-
process.stdout.write(Buffer.concat([Buffer.from("arbitrary - pre"), chunk]));
16-
process.stdout.write(Buffer.from("arbitrary - mid"));
17-
process.stdout.write(Buffer.concat([chunk, Buffer.from("arbitrary - post")]));
15+
process.stdout.write(Buffer.concat([Buffer.from("arbitrary - pre\n"), chunk]));
16+
process.stdout.write(Buffer.from("arbitrary - mid\n"));
17+
process.stdout.write(Buffer.concat([chunk, Buffer.from("arbitrary - post\n")]));
1818
}
1919
})();
2020

0 commit comments

Comments
 (0)