Skip to content

Commit c0854ac

Browse files
pulkit-30MoLow
authored andcommitted
test: fix invalid output TAP if there newline in test name
PR-URL: nodejs/node#45742 Fixes: nodejs/node#45396 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> (cherry picked from commit 22dc987fde29734c5bcbb7c33da20d184ff61627)
1 parent 71b659e commit c0854ac

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

lib/internal/test_runner/tap_stream.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/lib/internal/test_runner/tap_stream.js
1+
// https://github.com/nodejs/node/blob/22dc987fde29734c5bcbb7c33da20d184ff61627/lib/internal/test_runner/tap_stream.js
22

33
'use strict'
44

@@ -134,9 +134,15 @@ class TapStream extends Readable {
134134

135135
// In certain places, # and \ need to be escaped as \# and \\.
136136
function tapEscape (input) {
137-
return StringPrototypeReplaceAll(
138-
StringPrototypeReplaceAll(input, '\\', '\\\\'), '#', '\\#'
139-
)
137+
let result = StringPrototypeReplaceAll(input, '\\', '\\\\')
138+
result = StringPrototypeReplaceAll(result, '#', '\\#')
139+
result = StringPrototypeReplaceAll(result, '\b', '\\b')
140+
result = StringPrototypeReplaceAll(result, '\f', '\\f')
141+
result = StringPrototypeReplaceAll(result, '\t', '\\t')
142+
result = StringPrototypeReplaceAll(result, '\n', '\\n')
143+
result = StringPrototypeReplaceAll(result, '\r', '\\r')
144+
result = StringPrototypeReplaceAll(result, '\v', '\\v')
145+
return result
140146
}
141147

142148
function jsToYaml (indent, name, value) {

test/message/test_runner_output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://github.com/nodejs/node/blob/cb7e0c59df10a42cd6930ca7f99d3acee1ce7627/test/message/test_runner_output.js
1+
// https://github.com/nodejs/node/blob/22dc987fde29734c5bcbb7c33da20d184ff61627/test/message/test_runner_output.js
22
// Flags: --no-warnings
33
'use strict'
44
require('../common')
@@ -214,7 +214,7 @@ test('test with a name and options provided', { skip: true })
214214
test({ skip: true }, function functionAndOptions () {})
215215

216216
// A test whose description needs to be escaped.
217-
test('escaped description \\ # \\#\\')
217+
test('escaped description \\ # \\#\\ \n \t \f \v \b \r')
218218

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

test/message/test_runner_output.out

Lines changed: 4 additions & 4 deletions
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)