-
-
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
Fix hook pattern of 'this.skip()' in beforeEach hooks #3741
Conversation
Curious on your thoughts -- outside scope of this PR. Think there's any value to adding a |
Yes, I was thinking about extending |
862d296
to
e285f52
Compare
e285f52
to
91f3056
Compare
@boneskull please tell me wether it makes sense to continue with this PR. Thanks. |
@juergba I think what you're proposing sounds good. |
I've been ignoring this because of the "WIP" in the title. If it's ready to review, please let me know. |
Patch release is risky. IMO it certainly is a bug fix, but there have been very few (one?) opened issue about this topic. Either users don't use Anyway there are more hook pattern fixes to come, for Please review, it works, but I need to be confirmed with one or two doubts. |
I think this needs to be semver-major then |
91f3056
to
7243531
Compare
I'm thoroughly reviewing this one. It's taking me a bit due to having stepped away from the code for a while, and because our vars / function names are not very friendly (in runner.js, at least). |
FWIW, this is a major issue for us. We are trying to find a solution, but other than forking mocha and fixing the bug, we're not sure what to do. We have beforeEach functions which acquire resources, and we have afterEach(done) functions which release them. The tests are predicated on the assumption that if a beforeEach runs, and there is an afterEach, then it will be run, whether the test passes, fails or is skipped. End of story. If the afterEach is not run because a test is skipped via this.skip(), then the resources will not be cleaned up, and tests will eventually cascade fail. I know this is not what this exact PR is about, but you were wondering why you haven't had any other issues reported. Most likely because there is a very good issue, which documents the exact issue, and has a number of PRs in progress. Its only when you dig into the PR that you find some debate about when or if to actually release the fix. Yes, this will possibly be a "breaking fix", and yes, you may want to update the major semver. your call :) But please fix! Thankyou 👍 |
7243531
to
f23a057
Compare
f23a057
to
92babcf
Compare
@mrstux It would be awesome if you could do some test runs with this branch. @boneskull @craigtaub @outsideris |
92babcf
to
fd350d6
Compare
@HarshaNalluru I would highly appreciate some feedback on this PR. Could you do some test runs with this branch? |
This .skip() behaviour seems to be more appropriate. |
@HarshaNalluru thank you! 👍 |
fd350d6
to
1566a9a
Compare
1566a9a
to
dc9bf3b
Compare
Description
#3745 is required for this PR.
The current hook pattern is incorrect. Skipping a test within a
beforeEach
hook executes all innerbeforeEach
hooks, but skipsafterEach
hooks completely.Some of the
afterEach
hooks should run to ensure a correct cleanup. This same pattern has already been implemented with failing hooks and also while using the--bail
option.The correct hook pattern should be:
beforeEach
runs for each test individually and determines at runtime wether to skip or not.(The failing hook pattern is different: the first hook failure skips all linked tests.)
this.skip()
aborts hook execution, subsequent innerbeforeEach
should be skipped ("B").beforeEach
=> skip correspondingafterEach
hooks as well ("Y").afterEach
hooks of the same/higher suite level than the skipping one should run ("Z").Description of the Change
We abort
hookDown()
at skippingsuite
level in order to skip subsequent innerbeforeEach
hooks. The same skippingsuite
level is used as entry point forhookUp()
to skip corresponding innerafterEach
hooks.Applicable issues
closes #2546
closes #2623 PR
#3740 partially