Commit d1b33dad authored by Robert Knight's avatar Robert Knight

Ensure that the test run fails if an uncaught exception occurs

Due to an issue with the interaction between mocha and karma-mocha [1],
uncaught exceptions or promise rejections that occur in between tests
can cause the test run to stop immediately yet incorrectly report that
all tests executed succesfully and hence CI runs / Jenkins builds
incorrectly report their status.

This commit works around the issue until the problem is resolved in
mocha / karma-mocha by adding an `afterEach` hook which will re-throw
any uncaught exceptions and ensure that mocha notices them and reports
the failure correctly to Karma.

[1] See comments on https://github.com/hypothesis/client/issues/2249
parent d92c7ba9
......@@ -23,3 +23,21 @@ registerIcons({
...sidebarIcons,
...annotatorIcons,
});
// Ensure that uncaught exceptions between tests result in the tests failing.
// This works around an issue with mocha / karma-mocha, see
// https://github.com/hypothesis/client/issues/2249.
let pendingError = null;
window.addEventListener('error', event => {
pendingError = event.error;
});
window.addEventListener('unhandledrejection', event => {
pendingError = event.reason;
});
afterEach(() => {
if (pendingError) {
console.error('An uncaught exception was thrown between tests');
throw pendingError;
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment