fix: restore Jest support in consumer projects - #10377
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Jest resolver now maps Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The Jest resolver, package publication entry, documentation, and scroll-handler regression coverage align with the intended Jest support change. No merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…bump reanimated 4.6.0 split its shared/.native files without shipping the jest resolver that makes the split work outside its own monorepo (upstream fix pending: software-mansion/react-native-reanimated#10377). Mirror that resolver locally so Jest resolves the affected modules to their JSReanimated-safe variant, and pull the jestUtils matcher types into the tsc program the same way, since plain Node/tsc resolution never reaches the .native.d.ts that carries them. Also brings package-lock.json back in sync with package.json (npm ci was failing on this PR with "Missing: react-native-worklets@0.10.4 from lock file"), and drops two devDependencies an earlier fix attempt added that turned out not to be needed for the tests to pass.
…t of the bump The npm-minor-and-patch group bump moved react-native, react-native-worklets, and react-native-reanimated together (0.86.2/0.10.1/4.5.1 -> 0.87.1/0.12.1/ 4.6.0), and that trio broke three separate things: - reanimated 4.6.0 split its shared/.native files without shipping the jest resolver needed to use them outside its own monorepo (upstream fix pending: software-mansion/react-native-reanimated#10377) -- every jest suite failed at import time. - react-native 0.87.1 pulled in @react-native/gradle-plugin's AGP 9.2.1, which refuses to run under Gradle < 9.4.1, but expo's own bundled android template (checked directly against every published 57.0.x release) still ships a 9.3.1 wrapper -- so bumping the wrapper to satisfy AGP then hits a second, harder wall: expo-modules-autolinking pins Kotlin 2.1.20 for its own Gradle plugin, and 2.1.20 can't read the Kotlin 2.3.0 stdlib metadata Gradle 9.4.1 ships internally. No published expo-modules-autolinking release (57.0.12 is latest; 58.x is canary-only) fixes this yet. - metro moved with react-native and resolved image-size@1.2.1 again, which carries GHSA-5p2g-fcmc-qvqq / GHSA-w3rx-r6r6-pgpr, and no image-size release up to and including the latest (2.0.2) fixes either advisory. None of that is fixable from this repo today, so this holds react-native at 0.86.3 instead of the group's 0.87.1 -- one patch above main's 0.86.2, which is enough to satisfy jest-expo 57.0.5's `@react-native/jest-preset: ^0.86.3` peer requirement (also part of this bump) while keeping AGP at 8.12.0, well under the Gradle-9.4.1 threshold. worklets and reanimated stay at main's 0.10.1/4.5.1, since reanimated 4.6.0 requires worklets 0.12.1 as a hard dependency, and downgrading one without the other isn't a valid pairing. gesture-handler, safe-area-context, screens, and jest-expo keep the bump's versions -- none of them touch this trio. Verified: full mobile Jest suite (555 tests, 58 suites), tsc --noEmit, expo lint, npm ci (lockfile back in sync), the repo's own dependency-advisories gate (0 shipped-code findings, down from 2), and an actual `expo prebuild --platform android` + `./gradlew :app:tasks` run -- it clears both the AGP version-check and the Kotlin compile step that failed under 0.87.1, then stops only on this machine's missing Android SDK, which CI has configured.
Consumer projects need react-native-reanimated/jest/resolver to run Jest against Reanimated, mirroring react-native-worklets which already ships its resolver. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… Jest Mounting an animated component with attached event handlers crashed with "registerEventHandler is not available in JSReanimated". Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
a1f097c to
9dc98db
Compare
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
9dc98db to
484849d
Compare
tshmieldev
left a comment
There was a problem hiding this comment.
Great job, I will actually bring back one comment from the docs and merge it
…reanimated 4.6 Two things the grouped bump could not do on its own: 1. pnpm-workspace.yaml pins `react-native-worklets` to ONE exact version so the worklets babel plugin and runtime never diverge. Renovate is told never to touch that file, so the bump to 0.12.2 in package.json left the override at 0.10.0 — syncpack reds on the split (`pnpm check:versions`, the only step that failed on this PR), and on CI the override silently WON, so the tests there ran reanimated 4.6.0 on worklets 0.10.0. Move it to 0.12.2 (reanimated 4.6.0 peers on 0.12.x) and note the lockstep rule. 2. reanimated 4.6.0 breaks jest in consumer projects: it split the files that used to branch on SHOULD_BE_USE_WEB / IS_JEST at runtime into .native/.web variants, and jest resolves the .native ones — importing the package (its own mock included) throws `[Reanimated] setCSSEventHandler is not available in JSReanimated`, then mutables.native reaches worklets' createShareable (a hard throw on the web build), then registerEventHandler once a component mounts. 61 of 116 RN jest suites failed to run. Upstream's fix (software-mansion/react-native-reanimated#10377, merged 2026-09-08) ships the in-repo jest resolver that resolves a fixed list of native-module-dependent files to their web variants — but no published 4.6.x carries it. Replicate that list verbatim in the composed jest.resolver.js (with the pnpm-safe physical-directory match the worklets branch already uses), with a drop condition to chain the published resolver once the installed reanimated ships it. Verified locally: RN jest 116/116 suites (623 tests), RN vitest 62/62, `expo export` (the only Metro exerciser of the worklets pin) bundles cleanly, and all 19 fast gates pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzfogspAYRnXRzbx7oB1A8
Note
This pull request was authored by AI on behalf of huextrat.
Summary
Since 4.6.0, running Jest against Reanimated in a consumer project is broken: the shared files that used to branch on
SHOULD_BE_USE_WEB/IS_JESTwere split into.native/.webvariants, and under Jest the.nativeones get resolved. Importing the package crashes at initialization with[Reanimated] `setCSSEventHandler` is not available in JSReanimated.beforesetUpTests()can even run, and further crashes follow once components render (mappers.nativehas no frame loop on the Jest runtime,registerEventHandler,findHostInstance, …).This repo's own Jest config already handles this with
packages/react-native-reanimated/jest/resolver.js, which resolves the native-module-dependent files to their web variants — but that resolver is not shipped in the npm package, so consumers have no working setup.This PR:
react-native-reanimated/jest/resolverin the npm package (mirroringreact-native-worklets, which already ships its resolver) and documents it in the testing guide, with the same presentation as the Worklets guide.WorkletEventHandlerto the resolver's web-only list: mounting an animated component with attached event handlers (e.g.useAnimatedScrollHandler) crashed with[Reanimated] registerEventHandler is not available in JSReanimated.— the web variant registers plain JS listeners, as the shared file'sSHOULD_BE_USE_WEBbranch did pre-4.6.The resolver is the only supported Jest setup: it also chains the Worklets resolver, so no
jest.mock('react-native-worklets', …)is needed.Test plan
yarn jestinpackages/react-native-reanimated: 107 suites / 1598 tests pass, including the new regression testhooks.useAnimatedScrollHandler.test.tsx(mount +fireEvent.scroll+ unmount). It fails with the exact pre-fixregisterEventHandlererror whenWorkletEventHandleris removed from the resolver list.resolver: 'react-native-reanimated/jest/resolver', the full suite passes — it fully crashed before these changes.Changelog
Unpublishedsection of each changed package'sCHANGELOG.md, or this PR does not changereact-native-reanimatedorreact-native-worklets.🤖 Generated with Claude Code