I'm talking about behaviour that can be switched off with --no-exit option.
Having this as default looks dangerous, as it may hide serious issues in tests (any orphaned async flow is just silenced, leaving no clue to developer)
e.g. on my side I had a promise with crashing test not returned properly. Still test process as handled by mocha was exiting smiling with a success. It took me a while to figure out why it happens.
@medikoo did you try having a call to done() in the test and increase the timeout?
@michaelBenin no, it was a setup issue, it was orphaned async flow not provided to mocha as documented.
So describe block ended with no test being run, while there were scheduled ones and what's worse, the scheduled ones were failing.
But fact that API was misused should be irrelevant, what's relevant is that background async tasks (which in the end would crash) where just aborted cause of forced process exit. Especially test suites should not do this.
In my tests I have a teardown util which is the last test to be run. Would something like this benefit you?
@michaelBenin this issue is about silencing eventual errors in configuration which in normal cricumstances will explicitly crash (and that way become apparent).
Otherwise once spotted, those errors are easy to fix, there's no problem with that.
See also #1855 for a potential caveat about eventually timing out so this doesn't lead to just sitting waiting on anything that keeps the process open forever.
so this doesn't lead to just sitting waiting on anything that keeps the process open forever.
In my opinion tests always should come up with proper cleanup. If effect of a test is that process is kept forever then it is a clear issue with a test or a functionality that's being tested. I believe it's quite important that such issues are exposed to the developer
If we want to get this in V4, it should be a simple matter of switching the default for the parameter... right?
Hi, we're looking to update to mocha 4 and think this is a great change.
However, is there a way to tell when mocha intends to exit / all tests are done? We have some setup-code that spawns a server that is used across multiple test suites (so before(), after() don't work for that). Thanks!
@maximilianschmitt I would suggest opening a server in a separate process
Global ("root-level") before and after, i.e. the ones outside any describe, should run at the very beginning and very end of Mocha's test run.
Thanks @ScottFreeCode , that should do it! :)
Most helpful comment
In my opinion tests always should come up with proper cleanup. If effect of a test is that process is kept forever then it is a clear issue with a test or a functionality that's being tested. I believe it's quite important that such issues are exposed to the developer