You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
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:
Mocha runs a test
The test starts a timer or some other async task
The test returns before the timer has expired, Mocha reports that the test passed and karma-mocha reports this back to Karma
At some point after the test has "finished", the timer expires in between tests and the timer callback triggers an uncaught exception. Mocha catches the uncaught exception via an error global event handler and reports a fail event to karma-mocha, followed by an end event.
Since this error occurs outside of a test there is no corresponding test end event. karma-mocha only reports the test status to Karma in response to the test end event and not the fail event. As a result, the Karma test run finishes reporting that all tests executed successfully, despite having only run some of the tests
I 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:
describe('TESTING',()=>{it('should blow up',()=>{setTimeout(()=>{thrownewError('Fail!');},0);// Test exits here and "passes", but triggers an error later in between tests});});
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 a fail event that is not followed by a test end event. It would seem wise to me that karma-mocha should have logic to ensure that fail events always get reported even if mocha doesn't generate a test end event though.
The text was updated successfully, but these errors were encountered:
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.
Karma-mocha has an issue[1]: when unhandled exception is thrown right
after a test ends, the mocha doesn't executu other tests, but Karma
reports success. With the fix, the exception is rethrown correctly
after all tests and Karma fails (as expected).
[1] karma-runner/karma-mocha#227
Change-Id: Iae031a01ead3a9004b0c290559f0b070c58a6919
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.The text was updated successfully, but these errors were encountered: