Skip to content

Commit d795c0a

Browse files
MoLowdanielleadams
authored andcommitted
test_runner: dont split lines on test:stdout
PR-URL: #48057 Backport-PR-URL: #48684 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 04eb1f8 commit d795c0a

4 files changed

Lines changed: 18 additions & 23 deletions

File tree

‎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+
returndata.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: 11 additions & 5 deletions
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+
constlines=RegExpPrototypeSymbolSplit(kLineBreakRegExp,data.message);
51+
for(leti=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-
constlines=StringPrototypeSplit(value,kLineBreakRegExp);
133+
constlines=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
constframes=[];
225231

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

‎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,
@@ -74,7 +72,6 @@ const {
7472
constkFilterArgs=['--test','--experimental-test-coverage','--watch'];
7573
constkFilterArgValues=['--test-reporter','--test-reporter-destination'];
7674
constkDiagnosticsFilterArgs=['tests','suites','pass','fail','cancelled','skipped','todo','duration_ms'];
77-
constkSplitLine=hardenRegExp(/\r?\n/);
7875

7976
constkCanceledTests=newSafeSet()
8077
.add(kCancelledByParent).add(kAborted).add(kTestTimeoutFailure);
@@ -300,15 +297,11 @@ class FileTest extends Test {
300297
}
301298

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

314307
while(bufferHead?.length>=kSerializedSizeHeader){
@@ -385,7 +378,7 @@ function runTestFile(path, root, inspectPort, filesWatcher, testNamePatterns) {
385378
subtest.addToReport({
386379
__proto__: null,
387380
type: 'test:stderr',
388-
data: {__proto__: null,file: path,message: line},
381+
data: {__proto__: null,file: path,message: line+'\n'},
389382
});
390383
});
391384

‎test/fixtures/test-runner/output/arbitrary-output-colored.snapshot‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{ foo: [32m'bar'[39m }
2-
32
[33m1[39m
4-
53
[32m✔ passing test [90m(*ms)[39m[39m
64
[34mℹ tests 1[39m
75
[34mℹ suites 0[39m
@@ -13,9 +11,7 @@
1311
[34mℹ duration_ms *[39m
1412
TAP version 13
1513
# { foo: [32m'bar'[39m }
16-
#
1714
# [33m1[39m
18-
#
1915
# Subtest: passing test
2016
ok 1 - passing test
2117
---

0 commit comments

Comments
 (0)