镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Async errors are blocked until test run is finished #51714

Description

@forgotPassword

Version

v21.6.1

Platform

Windows

Subsystem

No response

What steps will reproduce the bug?

var test = require('node:test');

setTimeout(function(){
    console.log(xxxxxxxxxx); // uncaughtException 
}, 100)

test('bug', function(t, done){
    setTimeout(function(){
        done();
    }, 10000);
});

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

Activity

  1. marco-ippolito commented on Feb 10, 2024

    @marco-ippolito
    Member

    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 ignored

  2. forgotPassword commented on Feb 10, 2024

    @forgotPassword
    Author

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

  3. added
    test_runnerIssues and PRs related to the test runner subsystem.
    on Feb 11, 2024
  4. MoLow commented on Feb 11, 2024

    @MoLow
    Member

    this seems to be expected. tests run in a queue, and all unexpected warnings and errors are reported after the queue is drained.

  5. koshic commented on Feb 11, 2024

    @koshic

    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.

  6. MoLow commented on Feb 11, 2024

    @MoLow
    Member

    I guess we can add a stack trace to this warning, are you interested in sending a PR?

  7. koshic commented on Feb 11, 2024

    @koshic

    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.

  8. forgotPassword commented on Feb 12, 2024

    @forgotPassword
    Author

    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?

  9. github-actions commented on May 23, 2026

    @github-actions
    Contributor

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

  10. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on May 23, 2026
  11. github-actions commented on Jun 22, 2026

    @github-actions
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.test_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions