summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPulkit Gupta <pulkit30.bsr@gmail.com>2022-12-12 01:32:37 +0530
committerDanielle Adams <adamzdanielle@gmail.com>2023-01-04 20:31:55 -0500
commitb76f1aef12ad93a5eed6497f2da8ee1af67d682d (patch)
tree0218e66dddc779f50dd8584f2752084d43ac52b1
parent7a12f4815fcaa92bbec5552b7c0bcce229fbac32 (diff)
downloadnode-new-b76f1aef12ad93a5eed6497f2da8ee1af67d682d.tar.gz
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>
-rw-r--r--lib/internal/test_runner/tap_stream.js12
-rw-r--r--test/message/test_runner_output.js2
-rw-r--r--test/message/test_runner_output.out8
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js
index 3abd7ed556..a5834ee46f 100644
--- a/lib/internal/test_runner/tap_stream.js
+++ b/lib/internal/test_runner/tap_stream.js
@@ -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) {
diff --git a/test/message/test_runner_output.js b/test/message/test_runner_output.js
index 2a71cd3e16..47087303a7 100644
--- a/test/message/test_runner_output.js
+++ b/test/message/test_runner_output.js
@@ -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' });
diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out
index 96d977b21c..14479c773b 100644
--- a/test/message/test_runner_output.out
+++ b/test/message/test_runner_output.out
@@ -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: *
...