mocha
mocha copied to clipboard
🐛 Bug: Browser doesn't include call stack for global uncaught errors
Bug Report Checklist
- [X] I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
- [X] I have searched for related issues and issues with the
faq
label, but none matched my issue. - [X] 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.
- [X] I want to provide a PR to resolve this
Expected
When an uncaught error occurs during a test in browsers, you'd expect to see the call stack. That's useful.
Error: Oh no!
at inner (test.example.js:8:15)
Actual
Mocha's browser error handling code was written before browsers gave nice stacks (https://github.com/mochajs/mocha/commit/eb58761bb3346d2597e8365e60273417127b72c4).
Error: Error: Oh no! (http://127.0.0.1:8081/test.example.js:8)
Minimal, Reproducible Example
Using a minimal browser setup such as in https://github.com/mochajs/mocha-examples/pull/72:
it("example", (done) => {
function inner() {
throw new Error("Oh no!");
}
setTimeout(inner);
});
Versions
Mocha: 10.3.0
Additional Info
This was filed long ago in #2167, then a fix proposed in #3952. Since #2167 is quite old, re-filing to be more current.
Hey hey, thanks for noticing & working on this! We're using Mocha in Chrome DevTools and this specific feature is much needed :)
I had taken a stab to fix this in here then I realized that your PR #5107 already looks good. Are you thinking of continuing that and making it cross the finish line?
Ah that's nifty to hear you're using Mocha in the Chrome DevTools! We're just waiting for review from another maintainer on #5107. I know everyone else has been swamped lately, so unclear when we'll be able to.
#5107 is merged; we'll release a new version with the fix soon. 🚀
#5107 was released in [email protected]
. 🚀