-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thrown error in afterEach as a root hook plugin is ignored in watchmode #4347
Comments
This might be the same root problem as #4344. |
One more related issue: console logs are ignored in root hook plugins in watchmode. |
that sounds like a bug |
Hit this issue myself recently. I did a little digging & issue seems to be caused by the cloning the suite on L40. Lines 38 to 66 in 02bdb6b
It looks like Lines 117 to 127 in 7d3151d
I did a quick local patch to add these & watch worked as expected with root hooks. |
## Rationale Tests with root level hooks are ignored when running in watch mode. This occurs on initial & subsequent runs. ## Changes - extended `suite.clone` to clone hooks This change was necessary to ensure that when a suite is cloned during the setup phase for watch that hooks are available on the newly cloned suite. Note the use of `suite.clone` appears to be only used in to `lib/cli/run-watch`. I did consider making the cloning of hooks optional but opted not to as this `suite.clone` is internal `mocha` & not publicly referenced in the API documentation. Tests for `suite.clone` have been amended to reflect the above change. - Extended integration tests for watch to take into consideration hooks ## Refs - mochajs/issues/4347
## Rationale Tests with root level hooks are ignored when running in watch mode. This occurs on initial & subsequent runs. ## Changes - extended `suite.clone` to clone hooks This change was necessary to ensure that when a suite is cloned during the setup phase for watch that hooks are available on the newly cloned suite. Note the use of `suite.clone` appears to be only used in `lib/cli/run-watch`. I did consider making the cloning of hooks optional but opted not to as `suite.clone` is internal to `mocha` & not publicly referenced in the API documentation. Tests for `suite.clone` have been amended to reflect the above change. - Extended integration tests for watch to take into consideration hooks ## Refs - mochajs/issues/4347
FYI I've submitted a PR to address. #4382 |
## Rationale Tests with root level hooks are ignored when running in watch mode. This occurs on initial & subsequent runs. ## Changes - extended `suite.clone` to clone hooks This change was necessary to ensure that when a suite is cloned during the setup phase for watch that hooks are available on the newly cloned suite. Note the use of `suite.clone` appears to be only used in `lib/cli/run-watch`. I did consider making the cloning of hooks optional but opted not to as `suite.clone` is internal to `mocha` & not publicly referenced in the API documentation. Tests for `suite.clone` have been amended to reflect the above change. - Extended integration tests for watch to take into consideration hooks ## Refs - mochajs/issues/4347
## Rationale Tests with root level hooks are ignored when running in watch mode. This occurs on initial & subsequent runs. ## Changes - updated `lib/cli/run-watch` to re-initialise rootHooks As we have swapped out the root suite it is necessary to re-initialize root level hooks again. - Extended integration tests for watch to take into consideration hooks ## Refs - mochajs/issues/4347
## Rationale Tests with root level hooks are ignored when running in watch mode. This occurs on initial & subsequent runs. ## Changes - updated `lib/cli/run-watch` to re-initialise rootHooks As we have swapped out the root suite it is necessary to re-initialize root level hooks again. - Extended integration tests for watch to take into consideration hooks ## Refs - /issues/4347
Prerequisites
faq
label[ ] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.Not syntax related[ ] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itselfNot related to code under testnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Steps to Reproduce
Full repro: https://github.com/eps1lon/repro-mocha-root-hook-throw
mocha test.js
fails as expectedmocha test.js --watch
passes unexpectedlyExpected behavior:
afterEach as a root hook behave the same as "local" hooks with regard to thrown errors.
Actual behavior:
Thrown error is ignored in afterEach in watchmode
Reproduces how often:
All the time
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 8.0.1mocha --version
does not work because I didn't install it globallynode --version
: 12.16.2fish, version 2.7.1
Additional Information
N/A
The text was updated successfully, but these errors were encountered: