diff --git a/lib/internal/test_runner/reporter/spec.js b/lib/internal/test_runner/reporter/spec.js index 2410544d9736fe..0df89a90efa554 100644 --- a/lib/internal/test_runner/reporter/spec.js +++ b/lib/internal/test_runner/reporter/spec.js @@ -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': diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index 80289ef225788f..4aec4ba072d954 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -5,10 +5,10 @@ const { ArrayPrototypePush, ObjectEntries, RegExpPrototypeSymbolReplace, + RegExpPrototypeSymbolSplit, SafeMap, SafeSet, StringPrototypeReplaceAll, - StringPrototypeSplit, StringPrototypeRepeat, } = primordials; const { inspectWithNoCustomRetry } = require('internal/errors'); @@ -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 = RegExpPrototypeSymbolSplit(kLineBreakRegExp, data.message); + for (let i = 0; i < lines.length; i++) { + if (lines[i].length === 0) continue; + yield `# ${tapEscape(lines[i])}\n`; + } + break; + } case 'test:diagnostic': yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`; break; case 'test:coverage': @@ -124,7 +130,7 @@ function jsToYaml(indent, name, value, seen) { return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`; } - const lines = StringPrototypeSplit(value, kLineBreakRegExp); + const lines = RegExpPrototypeSymbolSplit(kLineBreakRegExp, value); if (lines.length === 1) { return `${prefix}${inspectWithNoCustomRetry(value, inspectOptions)}\n`; @@ -224,7 +230,7 @@ function jsToYaml(indent, name, value, seen) { const frames = []; ArrayPrototypeForEach( - StringPrototypeSplit(errStack, kLineBreakRegExp), + RegExpPrototypeSymbolSplit(kLineBreakRegExp, errStack), (frame) => { const processed = RegExpPrototypeSymbolReplace( kFrameStartRegExp, diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index 656d4b2c51234a..88b648d9a19cbf 100644 --- a/lib/internal/test_runner/runner.js +++ b/lib/internal/test_runner/runner.js @@ -11,14 +11,12 @@ const { ArrayPrototypeSlice, ArrayPrototypeSome, ArrayPrototypeSort, - hardenRegExp, ObjectAssign, PromisePrototypeThen, SafePromiseAll, SafePromiseAllReturnVoid, SafePromiseAllSettledReturnVoid, PromiseResolve, - RegExpPrototypeSymbolSplit, SafeMap, SafeSet, StringPrototypeIndexOf, @@ -74,7 +72,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); @@ -300,15 +297,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) { @@ -385,7 +378,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' }, }); }); diff --git a/test/fixtures/test-runner/output/arbitrary-output-colored.snapshot b/test/fixtures/test-runner/output/arbitrary-output-colored.snapshot index 87866602f04559..34b5c0479857ff 100644 --- a/test/fixtures/test-runner/output/arbitrary-output-colored.snapshot +++ b/test/fixtures/test-runner/output/arbitrary-output-colored.snapshot @@ -1,7 +1,5 @@ { foo: [32m'bar'[39m } - [33m1[39m - [32m✔ passing test [90m(*ms)[39m[39m [34mℹ tests 1[39m [34mℹ suites 0[39m @@ -13,9 +11,7 @@ [34mℹ duration_ms *[39m TAP version 13 # { foo: [32m'bar'[39m } -# # [33m1[39m -# # Subtest: passing test ok 1 - passing test ---