Open robertknight opened 4 years ago
As a workaround we added event handlers for uncaught exceptions/promise rejections in our test suite which saves the error and re-throws it later in a context that does get reported to Karma: https://github.com/hypothesis/client/blob/915be0b927edcb9b0215fa94f8b9e61c934c3fc9/src/sidebar/test/bootstrap.js#L29
A similar issue occurs with unhandled promise rejections which trigger an unhandledrejection
event to be dispatched to the window. Unlike uncaught exceptions it seems that Mocha doesn't currently intercept the unhandledrejection
event at all, so no fail
event is reported.
We encountered an issue in our application where Karma would sometimes start running tests and then exit part-way through but still report that all tests had been executed successfully.
Debugging the interactions between karma-mocha and mocha, it seems that what was happening is:
error
global event handler and reports afail
event to karma-mocha, followed by anend
event.test end
event. karma-mocha only reports the test status to Karma in response to thetest end
event and not thefail
event. As a result, the Karma test run finishes reporting that all tests executed successfully, despite having only run some of the testsI don't yet have a complete example project, but I was able to reproduce the problem reliably in our test suite by adding this broken test:
This was tested with karma-mocha v2.0.1 and mocha v8.1.1.
The expected behavior is that the uncaught exception is reported and the test run should fail.
I'm not sure here whether the fault is really in mocha for not generating an extra
test end
event or whether karma-mocha should anticipate receiving afail
event that is not followed by atest end
event. It would seem wise to me thatkarma-mocha
should have logic to ensure thatfail
events always get reported even if mocha doesn't generate atest end
event though.