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_runner: top-level diagnostics not ommited when running with --test #46441

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pulkit-30
Copy link
Contributor

@pulkit-30 pulkit-30 commented Jan 31, 2023

fix: #45910

Should not omit top-level diagnostics when running test with --test flag.

Changes

added a logic #checkNestedComment() to filter top-level diagnostics only in cases they are redundant and show them
test:

test('should not omit top-level diagnostics', () => setImmediate(() => done()));

output:

TAP version 13
# Subtest: *
    # Subtest: should not omit top-level diagnostics
    ok 1 - should not omit top-level diagnostics
      ---
      duration_ms: 2.072958
      ...
    1..1
    # Warning: Test "should not omit top-level diagnostics" generated asynchronous activity after the test ended. This activity created the error "ReferenceError: done is not defined" and would have caused the test to fail, but instead triggered an uncaughtException event.
not ok 1 - *
  ---
  duration_ms: 57.882541
  failureType: 'subtestsFailed'
  exitCode: 1
  error: 'test failed'
  code: 'ERR_TEST_FAILURE'
  ...
1..1
# tests 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 59.641875

I am not sure about test failing
when running test without --test flag, test output is:

TAP version 13
# Subtest: should not omit top-level diagnostics
ok 1 - should not omit top-level diagnostics
  ---
  duration_ms: 2.544125
  ...
1..1
# Warning: Test "should not omit top-level diagnostics" generated asynchronous activity after the test ended. This activity created the error "ReferenceError: done is not defined" and would have caused the test to fail, but instead triggered an uncaughtException event.
# tests 1
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 6.197042

@nodejs-github-bot
Copy link
Contributor

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added dont-land-on-v14.x PRs that should not land on the v14.x-staging branch and should not be released in v14.x. needs-ci PRs that need a full CI run. test_runner labels Jan 31, 2023
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
test/message/test_runner_output.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
MoLow
MoLow approved these changes Jan 31, 2023
@@ -16,6 +16,7 @@ const {
SafeMap,
SafeSet,
StringPrototypeStartsWith,
StringPrototypeSplit,
Copy link
Contributor

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).

@@ -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'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const diagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
const kDiagnosticsFilterArgs = ['tests', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];

@@ -130,6 +132,10 @@ function getRunArgs({ path, inspectPort }) {

class FileTest extends Test {
#buffer = [];
#checkNestedComment(node) {
const commentArgs = StringPrototypeSplit(node.comment, ' ');
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor

@aduh95 aduh95 Jan 31, 2023

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));

Copy link
Contributor Author

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 🚀

MoLow
MoLow approved these changes Jan 31, 2023
@@ -130,6 +133,12 @@ function getRunArgs({ path, inspectPort }) {

class FileTest extends Test {
#buffer = [];
#checkNestedComment({ comment }) {
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ');
Copy link
Contributor

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.

Suggested change
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ');
const firstSpaceIndex = StringPrototypeIndexOf(comment, ' ');
if (firstSpaceIndex === -1) return false;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dont-land-on-v14.x PRs that should not land on the v14.x-staging branch and should not be released in v14.x. needs-ci PRs that need a full CI run. test_runner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test runner: top-level diagnostics are ommited when running with --test
8 participants