Skip to content

🐛 Bug: unhandledRejection in the default Runner kills process with 0 status code #5507

@alxndrsn

Description

@alxndrsn

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Tests should fail if there's an unhandled rejection with no process-level listener.

Actual

As demonstrated in #5505, a test which throws an unhandled promise rejection inside runner code will cause the mocha process to exit with status code 0.

Minimal, Reproducible Example

$ echo 'it("t", async () => { require("node:assert").deepEqual(Object.create(null), { a:1 }); });' > demo.js; npx mocha demo.js; echo $?


0

Versions

$ node --version
v22.14.0

$ npx mocha --version
11.7.4

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: in triagea maintainer should (re-)triage (review) this issuetype: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions