afterEach hooks run outer suite first, unlike Jest
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react-native, typescript
Research direction
Start with collectInheritedHooks in packages/runtime/src/runner/hooks.ts, then read the existing tests for beforeEach and afterEach hook order. Reproduce the reported order with nested suites and verify the hooks run innermost first for afterEach while beforeEach keeps its current order. Done when the test confirms the reported behavior is fixed.
Written by the indexing model from the issue text.
Description
Describe the bug
collectInheritedHooks in packages/runtime/src/runner/hooks.ts collects hooks from the root suite down and runs them in that order for both beforeEach and afterEach.
Jest and Vitest run afterEach the other way round, innermost suite first. So an afterEach in setupFilesAfterEnv runs before a test file’s own afterEach. Anything that checks cleanup at the top level then sees resources the test hasn’t closed yet. Reversing the list for afterEach fixes it.
We have a library that runs in both Node.JS and React Native through different native bindings and we reuse the same test suite between them.
System Info
System:
OS: macOS 15.6
CPU: (14) arm64 Apple M4 Pro
Memory: 141.98 MB / 48.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 24.16.0
path: /Users/user/.nvm/versions/node/v24.16.0/bin/node
Yarn:
version: 1.22.22
path: /Users/user/.nvm/versions/node/v24.16.0/bin/yarn
npm:
version: 11.13.0
path: /Users/user/.nvm/versions/node/v24.16.0/bin/npm
Watchman:
version: 2025.10.20.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 25.2
- iOS 26.2
- macOS 26.2
- tvOS 26.2
- visionOS 26.2
- watchOS 26.2
Android SDK:
API Levels:
- "34"
- "35"
- "36"
- "37"
Build Tools:
- 34.0.0
- 35.0.0
- 36.0.0
- 36.1.0
- 37.0.0
System Images:
- android-24 | Google APIs ARM 64 v8a
- android-29 | Google APIs ARM 64 v8a
- android-35 | ARM 64 v8a
- android-35 | Google APIs ARM 64 v8a
- android-36.1 | Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2025.1 AI-251.27812.49.2514.14217341
Xcode:
version: 26.2/17C52
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.17
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 20.2.0
wanted: latest
react:
installed: 19.3.0
wanted: 19.3.0
react-native:
installed: 0.88.0
wanted: 0.88.0
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: true
newArchEnabled: true
React Native Harness Version
1.6.0
Reproduction
Steps to reproduce
npm installnpx expo run:ios --no-bundlerto build and install the app. If you don't have an iPhone 17 Pro simulator on iOS 26.2, change the simulator inrn-harness.config.mjsfirst.npm run test:ios
The second test in afterEach.harness.ts fails:
● inner › afterEach hooks of the first test ran inner first
expected 'outer afterEach > inner afterEach' to be 'inner afterEach > outer afterEach'
The outer suite's afterEach runs before the inner suite's. Jest and Vitest run afterEach hooks from the innermost suite outwards. It happens on every platform: the order comes from collectInheritedHooks in packages/runtime/src/runner/hooks.ts, which returns the hooks root first for afterEach as well as beforeEach. Reversing the list for afterEach makes the test pass.
- Dominant language
- TypeScript
- Stars
- 335
- Forks
- 23
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 53
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from callstackincubator/react-native-harness
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
callstackincubator/react-native-harness#128 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
callstackincubator/react-native-harness#277 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
callstackincubator/react-native-harness#273 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 15/100
callstackincubator/react-native-harness#247 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Ship prebuilt iOS XCTest agent artifacts and re-sign them locally instead of building per deviceOpenenhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
callstackincubator/react-native-harness#208 ·
Maintainers usually reply within 1 day
All issues in callstackincubator/react-native-harness
Similar issues
-
Plugin: sheet music can't be scrolled by hand before playbackPossibly taken @snakajima claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
receptron/jinglescript#51 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 9 days
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openclaw/openclaw#186424 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
chore(worker): five module header comments describe the code from before later issues changed itOpenarea:dev U2-later
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bentleypark/aiwatch#1824 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Pal-AI-Lab/Coopanion#469 ·
Maintainers usually reply within 1 day