From be6311b0b4bc90dfb2f32df7fbb0da54efc2c975 Mon Sep 17 00:00:00 2001 From: Shiba Rin Date: Tue, 23 May 2023 21:26:38 +0800 Subject: [PATCH] test_runner: delegate split message to reporter --- lib/internal/test_runner/reporter/tap.js | 15 +++++++++++++++ lib/internal/test_runner/runner.js | 17 +++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/internal/test_runner/reporter/tap.js b/lib/internal/test_runner/reporter/tap.js index 80289ef225788f..89f7672bb56e55 100644 --- a/lib/internal/test_runner/reporter/tap.js +++ b/lib/internal/test_runner/reporter/tap.js @@ -46,7 +46,11 @@ async function * tapReporter(source) { yield `${indent(data.nesting)}# Subtest: ${tapEscape(data.name)}\n`; break; case 'test:stderr': + yield `# ${data.message}\n`; + break; case 'test:stdout': + yield reportStdout(data.message); + break; case 'test:diagnostic': yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`; break; @@ -87,6 +91,17 @@ function reportDetails(nesting, data = kEmptyObject) { return details; } +function reportStdout(message) { + const lines = StringPrototypeSplit(message, kLineBreakRegExp); + + const formattedLines = []; + for (let i = 0; i < lines.length; i++) { + ArrayPrototypePush(formattedLines, `# ${lines[i]}`); + } + + return `${ArrayPrototypeJoin(formattedLines, '\n')}\n`; +} + const memo = new SafeMap(); function indent(nesting) { let value = memo.get(nesting); diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js index f0b6d315b7c402..5c7cdd2791f062 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, @@ -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); @@ -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) {