I ran into a problem where my mocha tests were not finishing after running with chai-http. Mocha just hangs after the tests and eventually runs into a timeout (at least on my CI).
Asked
Active
Viewed 6,324 times
1 Answers
41
Turns out, Mocha (4.0) changed their behavior regarding the termination of the tests. The best workaround I have found is to add the --exit
flag to the npm script to revert to pre-4.0 behaviour.
...
"scripts": {
"start": "node server.js",
"test": "mocha --exit"
},
...

El Mac
- 3,256
- 7
- 38
- 58
-
1This is just hiding the real error under the carpet. The reason for the hanging is a mishandled asynchronous call. Unfortunately mocha or chai don't really explicitly tell where the issue is, beyond which test file it is in - you'll need to turn off all tests in that file and turn them back on one by one to find where the freeze happens. – Juha Untinen Jun 01 '18 at 09:55
-
@JuhaUntinen According to the issue [response](https://github.com/chaijs/chai-http/issues/178#issuecomment-336602457) on GitHub, the default was to force mocha to exit **after** the tests finished. This means the real error is not happening in the real productive code, but probably it's happening in the task runner. I can't change that behavior currently. – El Mac Jun 01 '18 at 12:44