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_runner: top-level diagnostics not ommited when running with --test #46441
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
lib/internal/test_runner/runner.js
Outdated
| @@ -16,6 +16,7 @@ const { | |||
| SafeMap, | |||
| SafeSet, | |||
| StringPrototypeStartsWith, | |||
| StringPrototypeSplit, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this up a line (sorted).
lib/internal/test_runner/runner.js
Outdated
| @@ -51,6 +52,7 @@ const { | |||
|
|
|||
| const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch']; | |||
| const kFilterArgValues = ['--test-reporter', '--test-reporter-destination']; | |||
| const diagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const diagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']; | |
| const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms']; |
lib/internal/test_runner/runner.js
Outdated
| @@ -130,6 +132,10 @@ function getRunArgs({ path, inspectPort }) { | |||
|
|
|||
| class FileTest extends Test { | |||
| #buffer = []; | |||
| #checkNestedComment(node) { | |||
| const commentArgs = StringPrototypeSplit(node.comment, ' '); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can node.comment ever be a non-string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there would be any case where comment is not type string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can that be asserted here, since passing an object into StringPrototypeSplit isn't safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW StringPrototypeSplit is always "unsafe", there's no way of using it without either accepting prototype pollution or suffer very bad perf. Ideally we would not use it at all, but sometimes there is just no other way around.
In this case though, it seems it wouldn't be very difficult to use something else, since we don't even use the split values but are just counting the spaces.
const firstSpaceIndex = StringPrototypeIndexOf(comment.node, ' ');
const secondSpaceIndex = StringPrototypeIndexOf(comment.node, ' ', firstSpaceIndex);
return secondSpaceIndex === -1 && ArrayPrototypeIncludes(kDiagnosticsFilterArgs, StringPrototypeSlice(comment.node, 0, firstSpaceIndex));There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review
committing required changes
| @@ -130,6 +133,12 @@ function getRunArgs({ path, inspectPort }) { | |||
|
|
|||
| class FileTest extends Test { | |||
| #buffer = []; | |||
| #checkNestedComment({ comment }) { | |||
| const firstSpaceIndex = StringPrototypeIndexOf(comment, ' '); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about the case where node.comment does not contain any spaces.
| const firstSpaceIndex = StringPrototypeIndexOf(comment, ' '); | |
| const firstSpaceIndex = StringPrototypeIndexOf(comment, ' '); | |
| if (firstSpaceIndex === -1) return false; |
fix: #45910
Should not omit top-level diagnostics when running test with
--testflag.Changes
added a logic
#checkNestedComment()to filter top-level diagnostics only in cases they are redundant and show themtest:
output:
I am not sure about test failing
when running test without
--testflag, test output is: