Skip to content
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(jest-circus): reverse order of afterEach, afterAll hooks #12861

Closed

Conversation

justjake
Copy link

Summary

fixes #12678

Currently, jest-circus runs afterAll and afterEach hooks in declaration order. However, both the docs and jasmine2 show afterAll and afterEach hooks running in reverse declaration order. This makes intuitive sense when using beforeEach to set up resources, and afterEach to dispose of resources:

let resource1: Resource
let resource2: Resource
beforeEach(() => { resource1 = new BaseResource() })
afterEach(() => { resource1.dispose() })

beforeEach(() => { resource2 = new ResourceConsumer(resource1) })
afterEach(() => { resource2.dispose() }) // May use resource1 after resource1 is disposed

This PR reverses the order of afterAll and afterEach hooks before they are executed.

Test plan

I added a snapshot test to jest-circus that emits output in the order shown in the documentation: https://jestjs.io/docs/setup-teardown#scoping

@justjake justjake changed the title jest-circus: reverse order of afterEach, afterAll hooks fix(jest-circus): reverse order of afterEach, afterAll hooks May 19, 2022
@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 17, 2022
@satanTime
Copy link

Up

@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 15, 2022
@github-actions
Copy link

This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this Dec 15, 2022
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: jest-circus doesn't respect beforeAll / beforeEach / afterEach / afterAll order
3 participants