karma-mocha hangs when there's a exception in afterEach hook #4250
Labels
area: integrations
related to working with 3rd party software (e.g., babel, typescript)
type: bug
a defect, confirmed by a maintainer
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
If an exception/assert error occurs in a hook, karma-mocha stops immediately due to an unhandled exception.
Steps to Reproduce
Example repo: https://github.com/mclin/karma-mocha-bug
Create a test that throws in afterEach:
test.test.js
Run this test in with karma and karma-mocha
karma.conf.js
Run it with karma start and see the tests stall and the browser times out.
Expected behavior:
Test should complete the tests with an error
Mocha 7.0.1
Actual behavior: [What actually happens]
It hangs and the browser disconnects.
Mocha 7.1.1
Reproduces how often: 100%
Versions
mocha 7.1.1
karma-mocha 2.0.0
karma 5.0.2
MacOS 10.14.6
Chrome 81.0.4044.113
Additional Information
This issue was introduced in mocha 7.1.0 here:
a995e33
Unhandled exception occurs here
karma-mocha is passing a hook object as the param with a 'test end' event.
https://github.com/karma-runner/karma-mocha/blob/master/src/adapter.js#L132
The hook doesn't have a
retriedTest
method, so it throws "Uncaught TypeError: test.retriedTest is not a function"Either karma-mocha shouldn't be passing a hook into "test end" or there needs to be a duck/type check for calling
retriedTest()
The text was updated successfully, but these errors were encountered: