-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
area: documentationanything involving docs or mochajs.organything involving docs or mochajs.orgstatus: accepting prsMocha can use your help with this one!Mocha can use your help with this one!
Description
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
faqlabel, 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
ESM errors thrown at top level gets silently swallowed (hidden) and does not fail the suite (as I assume is expected). Mocha ignores the error and keeps going. Makes it really annoying to debug whats wrong. Any it tests defined before the error do get "registered" normally though.
Actual
Nothing, simply ignores the error and keeps going
Minimal, Reproducible Example
given a test test/add.test.ts suite like this
import assert from 'node:assert/strict'
throw new Error()
it('should add stuff', () => {
const b = 1 + 1;
assert.equal(2, b)
})Then mocha --extension ts will simply output
(node:64751) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
0 passing (0ms)
instead of exposing the error.
Versions
Mocha 11.7.1
Node v24.3.0
Additional Info
Conversely if you change it to
import assert from 'node:assert/strict'
it('should add stuff', () => {
const b = 1 + 1;
assert.equal(2, b)
})
throw new Error()it will then output
Running main test suite...
(node:64877) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
✔ should add stuff
1 passing (1ms)
Still no mention of the error.
Metadata
Metadata
Assignees
Labels
area: documentationanything involving docs or mochajs.organything involving docs or mochajs.orgstatus: accepting prsMocha can use your help with this one!Mocha can use your help with this one!