Closed serge1peshcoff closed 7 years ago
Crap, that was totally my fault.
In case anyone stumbles upon the same error, here is the code that caused the crashing (to be more precise, exiting) and how to fix it:
process.on('uncaughtException', (err) => {
log.error(err);
// If something goes wrong, the process will exit.
// In testing environment, on some exception Mocha
// would just exit without printing anything. So I added
// this checking to fix it.
if (process.env.NODE_ENV !== 'test') {
process.exit(1);
}
});
That line of code made Mocha just stop the process, not finishing the test and the report.
yeah Mocha is not great software. I believe it uses a global handler like this and assigns errors to test cases in the global scope. I recommend moving to AVA or something else.
Hey ! I have exactly similar issue, but I didn't understand where should I put the piece of code. Could you help me ?
@WoodySlum my issue was that I was using custom process.on('uncaughtException')
and process.exit()
was run inside it, so the Mocha would exit silently instead of writing a report. So I've wrapped the exit
call inside a if
statement that checks if the process.env
is not test
I am using Mocha to write tests and Istanbul to count code coverage. And I am using this script to run Mocha with Istanbul to count code coverage and to post it to Github:
istanbul cover ./node_modules/mocha/bin/_mocha --report lcov -- -R spec --timeout 10000 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
The thing is, if I run my tests without Istanbul, with
mocha --timeout 10000
, everything works fine, but if I run this command above, it crashes sometimes. I tried running this command 5 times and it crashed in 3 cases (when I was runningmocha
, everything worked every time I ran it).Here is my
npm-debug.log
which was created after the crash:How can I fix this?