Skip to content

Commit 3278542

Browse files
MoLowtargos
authored andcommittedMay 30, 2023
test_runner: dont split lines on test:stdout
PR-URL: #48057 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent db62325 commit 3278542

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed
 

‎lib/internal/test_runner/reporter/spec.js

+1-1
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

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const {
55
ArrayPrototypePush,
66
ObjectEntries,
77
RegExpPrototypeSymbolReplace,
8+
RegExpPrototypeSymbolSplit,
89
SafeMap,
910
SafeSet,
1011
StringPrototypeReplaceAll,
11-
StringPrototypeSplit,
1212
StringPrototypeRepeat,
1313
} = primordials;
1414
const { inspectWithNoCustomRetry } = require('internal/errors');
@@ -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 = RegExpPrototypeSymbolSplit(kLineBreakRegExp, data.message);
51+
for (let i = 0; i < lines.length; i++) {
52+
if (lines[i].length === 0) continue;
53+
yield `# ${tapEscape(lines[i])}\n`;
54+
}
55+
break;
56+
} case 'test:diagnostic':
5157
yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`;
5258
break;
5359
case 'test:coverage':
@@ -124,7 +130,7 @@ function jsToYaml(indent, name, value, seen) {
124130
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
125131
}
126132

127-
const lines = StringPrototypeSplit(value, kLineBreakRegExp);
133+
const lines = RegExpPrototypeSymbolSplit(kLineBreakRegExp, value);
128134

129135
if (lines.length === 1) {
130136
return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`;
@@ -224,7 +230,7 @@ function jsToYaml(indent, name, value, seen) {
224230
const frames = [];
225231

226232
ArrayPrototypeForEach(
227-
StringPrototypeSplit(errStack, kLineBreakRegExp),
233+
RegExpPrototypeSymbolSplit(kLineBreakRegExp, errStack),
228234
(frame) => {
229235
const processed = RegExpPrototypeSymbolReplace(
230236
kFrameStartRegExp,

‎lib/internal/test_runner/runner.js

+6-13
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);
@@ -301,15 +298,11 @@ class FileTest extends Test {
301298
}
302299

303300
if (TypedArrayPrototypeGetLength(nonSerialized) > 0) {
304-
const messages = RegExpPrototypeSymbolSplit(kSplitLine, nonSerialized.toString('utf-8'));
305-
for (let i = 0; i < messages.length; i++) {
306-
const message = messages[i];
307-
this.addToReport({
308-
__proto__: null,
309-
type: 'test:stdout',
310-
data: { __proto__: null, file: this.name, message },
311-
});
312-
}
301+
this.addToReport({
302+
__proto__: null,
303+
type: 'test:stdout',
304+
data: { __proto__: null, file: this.name, message: nonSerialized.toString('utf-8') },
305+
});
313306
}
314307

315308
while (bufferHead?.length >= kSerializedSizeHeader) {
@@ -383,7 +376,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
383376
subtest.addToReport({
384377
__proto__: null,
385378
type: 'test:stderr',
386-
data: { __proto__: null, file: path, message: line },
379+
data: { __proto__: null, file: path, message: line + '\n' },
387380
});
388381
});
389382

0 commit comments

Comments
 (0)
Please sign in to comment.