Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/internal/test_runner/tap_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same change on the following lines. Other than that, I think this looks good.

Suggested change
result = StringPrototypeReplaceAll(result,'\b', '\\b');
result = StringPrototypeReplaceAll(result, '\b', '\\b');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, didn't notice that 😞
fixed 🚀

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) {
Expand Down
2 changes: 1 addition & 1 deletion test/message/test_runner_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
8 changes: 4 additions & 4 deletions test/message/test_runner_output.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: *
...
Expand Down