test: fix invalid output TAP if there newline in test name

PR-URL: https://github.com/nodejs/node/pull/45742
Fixes: https://github.com/nodejs/node/issues/45396
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Pulkit Gupta authored and Michaël Zasso committed 2022-12-13 09:42:45 +00:00
1 parent 5d7cd363ab
commit 5c4475dab9
3 files changed
+14 -8

No files matched your search

+9 -3
View File
@@ -131,9 +131,15 @@ class TapStream extends Readable {
// In certain places, # and \ need to be escaped as \# and \\.
function tapEscape(input) {
return StringPrototypeReplaceAll(
StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'
);
let result = StringPrototypeReplaceAll(input, '\\', '\\\\');
result = StringPrototypeReplaceAll(result, '#', '\\#');
result = StringPrototypeReplaceAll(result, '\b', '\\b');
result = StringPrototypeReplaceAll(result, '\f', '\\f');
result = StringPrototypeReplaceAll(result, '\t', '\\t');
result = StringPrototypeReplaceAll(result, '\n', '\\n');
result = StringPrototypeReplaceAll(result, '\r', '\\r');
result = StringPrototypeReplaceAll(result, '\v', '\\v');
return result;
}
function jsToYaml(indent, name, value) {
+1 -1
View File
@@ -213,7 +213,7 @@ test('test with a name and options provided', { skip: true });
test({ skip: true }, function functionAndOptions() {});
// A test whose description needs to be escaped.
test('escaped description \\ # \\#\\');
test('escaped description \\ # \\#\\ \n \t \f \v \b \r');
// A test whose skip message needs to be escaped.
test('escaped skip message', { skip: '#skip' });
+4 -4
View File
@@ -127,9 +127,9 @@ not ok 13 - async assertion fail
failureType: 'testCodeFailure'
error: |-
Expected values to be strictly equal:
true !== false
code: 'ERR_ASSERTION'
expected: false
actual: true
@@ -353,8 +353,8 @@ ok 36 - functionAndOptions # SKIP
---
duration_ms: *
...
# Subtest: escaped description \\ \# \\\#\\
ok 37 - escaped description \\ \# \\\#\\
# Subtest: escaped description \\ \# \\\#\\ \n \t \f \v \b \r
ok 37 - escaped description \\ \# \\\#\\ \n \t \f \v \b \r
---
duration_ms: *
...