Repository navigation
Async errors are blocked until test run is finished #51714
Description
Activity
This is a weird behavior:
If you wrap the uncaught expection in a test it behaves correctly.var test = require('node:test'); test('bug', function (t, done) { setTimeout(function () { console.log(xxxxxxxxxx); // uncaughtException done(); }, 100) }); test('bug', function (t, done) { setTimeout(function () { done(); }, 10000); });
Output:
✖ failing tests: test at index.js:4:1 ✖ bug (101.890542ms) ReferenceError: xxxxxxxxxx is not defined at Timeout._onTimeout (/Users/mippolito/Documents/projects/test/index.js:6:17) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7)Thats because the uncaught exception get listened by the test runner, and it cancels all pending tests.
However if the uncaught exception is thrown outside like in your example, it is listened but ignoredIt is plausible for the exception to be outside of the test, eg you require some module/file at the beginning of the document, and then describe your tests. If the required module fails (async-ly), you won't know about it until after the test.
- addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Feb 11, 2024 this seems to be expected. tests run in a queue, and all unexpected warnings and errors are reported after the queue is drained.
Even this is expected behavior, overall output looks ambiguous:
➜ main git:(master) ✗ node 1.cjs ✔ bug (10002.205177ms) ℹ Warning: A resource generated asynchronous activity after the test ended. This activity created the error "ReferenceError: xxxxxxxxxx is not defined" which triggered an uncaughtException event, caught by the test runner. ℹ tests 1 ℹ suites 0 ℹ pass 1 ℹ fail 0 ℹ cancelled 0 ℹ skipped 0 ℹ todo 0 ℹ duration_ms 10010.956102 ➜ main git:(master) ✗ echo $? 1 ➜ main git:(master) ✗
Node said 'Warning', but exit code is 1, so it's an error in terms of execution flow. Personally for me it's hard to find the root cause without additional hints.
I guess we can add a stack trace to this warning, are you interested in sending a PR?
I guess we can add a stack trace to this warning,
Yeah, it would be nice.
are you interested in sending a PR?
Sorry, no - I can't guarantee reasonable timeline for that activity.
Not sure how a stack trace is going to help if the test never finishes because the thing you are waiting on has exploded.
The message says something about 'after the test ended', well, this happens during the test. Why not log the error immediately?
- added a commit that references this issue
on Apr 16, 2024 github-actions commented
on May 23, 2026 on May 23, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on May 23, 2026 github-actions commented
on Jun 22, 2026 on Jun 22, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Version
v21.6.1
Platform
Windows
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
I would expect uncaughtException would bubble/log immediately. In my case because of the error, the test never finished, as such nothing was logged so there was no way of knowing what is happening.
What do you see instead?
The reflection of myself in the monitor.
Additional information
No response