-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: better error handing for test hook #52401
test_runner: better error handing for test hook #52401
Conversation
Review requested:
|
be37e0d
to
0e35b75
Compare
@@ -514,13 +514,13 @@ Error [ERR_TEST_FAILURE]: test could not be started because its parent finished | |||
} | |||
</failure> | |||
</testcase> | |||
<!-- Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. --> | |||
<!-- Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. --> | |||
<!-- Warning: Test "unhandled rejection - passes but warns" at test/fixtures/test-runner/output/output.js:72:1 generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. --> |
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.
Probably should also have the replaceTestLocationLine
transformer?
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 am ok with these being a number. it shouldn't change much
@@ -297,13 +297,13 @@ | |||
invalid subtest fail (*ms) | |||
'test could not be started because its parent finished' | |||
|
|||
Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | |||
Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | |||
Warning: Test "unhandled rejection - passes but warns" at test/fixtures/test-runner/output/output.js:72:1 generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. |
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.
same
@@ -297,13 +297,13 @@ | |||
invalid subtest fail (*ms) | |||
'test could not be started because its parent finished' | |||
|
|||
Warning: Test "unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | |||
Warning: Test "async unhandled rejection - passes but warns" generated asynchronous activity after the test ended. This activity created the error "Error: rejected from async unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. | |||
Warning: Test "unhandled rejection - passes but warns" at test/fixtures/test-runner/output/output.js:72:1 generated asynchronous activity after the test ended. This activity created the error "Error: rejected from unhandled rejection fail" and would have caused the test to fail, but instead triggered an unhandledRejection event. |
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.
same
@@ -10,7 +10,7 @@ const { spawnSync } = require('child_process'); | |||
fixtures.path('test-runner', 'extraneous_set_immediate_async.mjs'), | |||
]); | |||
const stdout = child.stdout.toString(); | |||
assert.match(stdout, /^# Warning: Test "extraneous async activity test" generated asynchronous activity after the test ended/m); | |||
assert.match(stdout, /^# Warning: Test "extraneous async activity test" at .+extraneous_set_immediate_async\.mjs:3:1 generated asynchronous activity after the test ended/m); |
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.
assert.match(stdout, /^# Warning: Test "extraneous async activity test" at .+extraneous_set_immediate_async\.mjs:3:1 generated asynchronous activity after the test ended/m); | |
assert.match(stdout, /^# Warning: Test "extraneous async activity test" at .+extraneous_set_immediate_async\.mjs:\d+:\d+ generated asynchronous activity after the test ended/m); |
(same for rest of the file)
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 am ok with this being a number. it shouldn't change much
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.
We can leave col/row number here, because fixtures are won't change too much, it's good to keep it here
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.
Nice improvement
msg = `Warning: Test "${test.name}" generated asynchronous ` + | ||
const name = test instanceof TestHook ? `Test Hook "${test.hookType}"` : `Test "${test.name}"`; | ||
const relPath = relative(process.cwd(), test.loc.file); | ||
msg = `Warning: ${name} at ${relPath}:${test.loc.line}:${test.loc.column} generated asynchronous ` + | ||
'activity after the test ended. This activity created the error ' + | ||
`"${err}" and would have caused the test to fail, but instead ` + | ||
`triggered an ${eventName} event.`; |
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.
There is another warning on line 70 that we should change to an error. We should also remove the part that says "after the test ended" since we have seen that it can happen before a test even starts.
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.
We should also remove the part that says "after the test ended" since we have seen that it can happen before a test even starts.
I will keep this comment because it seems out of the context of this PR. And perhaps we can open another PR and add such test case
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.
LGTM. Thanks, I think this is a nice change.
@himself65 CI seems to have failures related to the snapshots |
How to fix it? |
see https://ci.nodejs.org/job/node-test-binary-windows-js-suites/27045/RUN_SUBSET=1,nodes=win11-COMPILED_BY-vs2022/console for example:
|
Once you fix the transfrormers @MoLow mentioned, run the following command to update the snapshots: Lines 690 to 694 in 5b33f9d
|
working on this now |
074683d
to
16f2eef
Compare
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
16f2eef
to
ebaa222
Compare
Commit Queue failed- Loading data for nodejs/node/pull/52401 ✔ Done loading data for nodejs/node/pull/52401 ----------------------------------- PR info ------------------------------------ Title test_runner: better error handing for test hook (#52401) Author Alex Yang (@himself65) Branch himself65:himself65/20240407/better-error-handler -> nodejs:main Labels needs-ci, test_runner Commits 1 - test_runner: better error handing for test hook Committers 1 - Alex Yang PR-URL: https://github.com/nodejs/node/pull/52401 Fixes: https://github.com/nodejs/node/issues/52399 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/52401 Fixes: https://github.com/nodejs/node/issues/52399 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig -------------------------------------------------------------------------------- ⚠ Commits were pushed since the last approving review: ⚠ - test_runner: better error handing for test hook ℹ This PR was created on Sun, 07 Apr 2024 07:56:26 GMT ✔ Approvals: 4 ✔ - Moshe Atlow (@MoLow) (TSC): https://github.com/nodejs/node/pull/52401#pullrequestreview-1990080998 ✔ - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/52401#pullrequestreview-1990786703 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/52401#pullrequestreview-1990921524 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/52401#pullrequestreview-1991730905 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2024-04-15T07:42:58Z: https://ci.nodejs.org/job/node-test-pull-request/58391/ - Querying data for job/node-test-pull-request/58391/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/8687402947 |
Landed in f098b7a |
Fixes: #52399