-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Don't call afterEach within beforeEach #46963
Conversation
Otherwise, a new afterEach handler is added for each test case and the number of handlers run grows quadratically.
Before this change, 247177 hooks were executed; after, 152329. |
Other than numbers of handlers and repeatedly adding handlers being unneeded, does this have some kind of perf impact? |
@weswigham Unclear. Handlers are slower in the module transformation branch and at least part of the problem is that they run more handlers. I'm guessing it has to do with this bug and test ordering, but I'm still investigating. I don't expect any immediate perf win in |
In the module transformation branch, there were 2,883,032 runs before and 151,826 after. Seems like a win. 😄 Edit: And test runtime in that branch dropped from ~1200s to ~795s. |
I can't recall if it was jest or mocha, but one of them actually recommends you use |
@rbuckton My guess was that it was leftover from our previous jest (?) usage. I reviewed a bunch of mocha samples and couldn't find any doing it this way and the trace of hook executions looks a lot more sensible after the change (typically, two before hooks and two after hooks for each test). |
Also note that, if the old form was correct, some of our other hooks would need updating in the other direction. |
We've never previously used jest, just mocha. |
Otherwise, a new afterEach handler is added for each test case and the number of handlers run grows quadratically.
Otherwise, a new afterEach handler is added for each test case and the number of handlers run grows quadratically (wrt the number of tests in the suite adding the handlers).