Skip to content

Commit 38fb2c1

Browse files
pulkit-30danielleadams
authored andcommitted
test: fix invalid output TAP if there newline in test name
PR-URL: #45742 Fixes: #45396 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent a58bf14 commit 38fb2c1

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/internal/test_runner/tap_stream.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ class TapStream extends Readable {
131131

132132
// In certain places, # and \ need to be escaped as \# and \\.
133133
function tapEscape(input) {
134-
return StringPrototypeReplaceAll(
135-
StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'
136-
);
134+
let result = StringPrototypeReplaceAll(input, '\\', '\\\\');
135+
result = StringPrototypeReplaceAll(result, '#', '\\#');
136+
result = StringPrototypeReplaceAll(result, '\b', '\\b');
137+
result = StringPrototypeReplaceAll(result, '\f', '\\f');
138+
result = StringPrototypeReplaceAll(result, '\t', '\\t');
139+
result = StringPrototypeReplaceAll(result, '\n', '\\n');
140+
result = StringPrototypeReplaceAll(result, '\r', '\\r');
141+
result = StringPrototypeReplaceAll(result, '\v', '\\v');
142+
return result;
137143
}
138144

139145
function jsToYaml(indent, name, value) {

test/message/test_runner_output.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ test('test with a name and options provided', { skip: true });
213213
test({ skip: true }, function functionAndOptions() {});
214214

215215
// A test whose description needs to be escaped.
216-
test('escaped description \\ # \\#\\');
216+
test('escaped description \\ # \\#\\ \n \t \f \v \b \r');
217217

218218
// A test whose skip message needs to be escaped.
219219
test('escaped skip message', { skip: '#skip' });

test/message/test_runner_output.out

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ not ok 13 - async assertion fail
127127
failureType: 'testCodeFailure'
128128
error: |-
129129
Expected values to be strictly equal:
130-
130+
131131
true !== false
132-
132+
133133
code: 'ERR_ASSERTION'
134134
expected: false
135135
actual: true
@@ -353,8 +353,8 @@ ok 36 - functionAndOptions # SKIP
353353
---
354354
duration_ms: *
355355
...
356-
# Subtest: escaped description \\ \# \\\#\\
357-
ok 37 - escaped description \\ \# \\\#\\
356+
# Subtest: escaped description \\ \# \\\#\\ \n \t \f \v \b \r
357+
ok 37 - escaped description \\ \# \\\#\\ \n \t \f \v \b \r
358358
---
359359
duration_ms: *
360360
...

0 commit comments

Comments
 (0)