-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors after test completion are swallowed #3226
Comments
I see other issues implying that maybe Mocha does error in these cases, but I can reproduce with the test case above 100% of the time. I tried specifying |
The ignoring code seems to be here: https://github.com/mochajs/mocha/blob/master/lib/runner.js#L729. Looks like this behavior was introduced by #1578. The intent was to ignore async failures after the test had already failed, but as an unintended(?) side-effect Mocha now also ignores errors after the test has succeeded. |
@rpaterson I think you're right that this is unintended. |
See the following mocha issue and changelog: mochajs/mocha#3226 https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#502--2018-03-05 Test should have failed in all cases, but false passing occured with older mocha versions.
A mocha defect silently ignored this for the previous package-lock mocha version (5.0.1). See the following issue and changelog: mochajs/mocha#3226 https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#502--2018-03-05 Test should have failed in all cases, but false passing occured with older mocha versions.
A mocha defect silently ignored this for the previous package-lock mocha version (5.0.1). See the following issue and changelog: mochajs/mocha#3226 https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#502--2018-03-05 Test should have failed in all cases, but false passing occured with older mocha versions.
The 5.* version is the latest one that supports node.js 4. Upgrade to latest 9.2.* version requires node.js 12.* Improve several unit tests as they started to fail because of mochajs/mocha#3226
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.Description
Sometimes tests are written incorrectly and throw errors after they're complete. This applies to all three of Mocha's test forms (sync, promise, callback). If you write this sort of code in a normal Node program then the errors usually bubble up and kill the Node event loop, an error message is printed, and the process exits with a non-zero code. However when run with Mocha these errors are completely swallowed and never appear anywhere, and the process exits with code 0.
Obviously these tests are written badly, but I would expect Mocha to at least exit with an error code if a developer makes this sort of mistake! I can see how it may be difficult or impossible for Mocha to figure out which test caused the error, but it shouldn't just swallow the error completely.
Steps to Reproduce
Expected behavior:
At minimum Mocha executable should fail with a non-zero error code and print out some sort of error message. Ideally Mocha would also be able to associate the error with the test that caused it, but I realize that may not be possible.
Actual behavior:
Tests pass, Mocha exits with code zero.
Reproduces how often: 100%
Versions
Tested with Mocha 5.0
mocha --version
andnode node_modules/.bin/mocha --version
: 5.0.0node --version
: v8.9.3The text was updated successfully, but these errors were encountered: