Skip to content

fix: restore Jest support in consumer projects - #10377

Merged
tshmieldev merged 5 commits into
software-mansion:mainfrom
huextrat:fix/jest-support
Sep 8, 2026
Merged

tshmieldev merged 5 commits into
software-mansion:mainfrom
huextrat:fix/jest-support

Conversation

@huextrat

@huextrat huextrat commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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_JEST were split into .native/.web variants, and under Jest the .native ones get resolved. Importing the package crashes at initialization with [Reanimated] `setCSSEventHandler` is not available in JSReanimated. before setUpTests() can even run, and further crashes follow once components render (mappers.native has 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:

  • Ships react-native-reanimated/jest/resolver in the npm package (mirroring react-native-worklets, which already ships its resolver) and documents it in the testing guide, with the same presentation as the Worklets guide.
  • Adds WorkletEventHandler to 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's SHOULD_BE_USE_WEB branch 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 jest in packages/react-native-reanimated: 107 suites / 1598 tests pass, including the new regression test hooks.useAnimatedScrollHandler.test.tsx (mount + fireEvent.scroll + unmount). It fails with the exact pre-fix registerEventHandler error when WorkletEventHandler is removed from the resolver list.
  • Validated against a real ~1700-test consumer app suite (Expo / jest-expo): with resolver: 'react-native-reanimated/jest/resolver', the full suite passes — it fully crashed before these changes.

Changelog

  • I added an entry to the Unpublished section of each changed package's CHANGELOG.md, or this PR does not change react-native-reanimated or react-native-worklets.

🤖 Generated with Claude Code

huextrat added a commit to huextrat/react-native-reanimated that referenced this pull request Aug 22, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b600481a-319b-401e-99d1-7dd1994ba37a

📥 Commits

Reviewing files that changed from the base of the PR and between 484849d and 566bd91.

📒 Files selected for processing (1)
  • docs/docs-reanimated/docs/guides/testing-with-jest.mdx

📝 Walkthrough

Walkthrough

The Jest resolver now maps WorkletEventHandler to its web implementation and is included in the published package. The Jest setup guide documents this resolver. A regression test verifies scroll-handler event delivery with an offset of 42. The changelog records these Jest fixes.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 48484

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)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: restoring Jest support for consumer projects.
Description check ✅ Passed The description is directly related to the changeset. It explains the Jest resolver packaging, documentation, WorkletEventHandler fix, regression test, and validation results.

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 path_filters to narrow the review scope.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tjzel
tjzel requested a review from tshmieldev September 1, 2026 12:56
siddharth705 added a commit to Fynora/finora that referenced this pull request Sep 2, 2026
…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.
siddharth705 added a commit to Fynora/finora that referenced this pull request Sep 3, 2026
…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.
Comment thread packages/react-native-reanimated/__tests__/initializers.native.test.ts Outdated
Comment thread packages/react-native-reanimated/src/initializers.native.ts Outdated
Comment thread docs/docs-reanimated/docs/guides/testing-with-jest.mdx Outdated
Comment thread packages/react-native-worklets/src/mock.ts Outdated
Comment thread packages/react-native-reanimated/jest/resolver.js Outdated
Comment thread packages/react-native-reanimated/__tests__/initializers.native.test.ts Outdated
Comment thread packages/react-native-reanimated/CHANGELOG.md
Comment thread packages/react-native-worklets/__tests__/mock.test.ts Outdated
Comment thread packages/react-native-worklets/CHANGELOG.md Outdated
huextrat and others added 3 commits September 8, 2026 14:50
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>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@tshmieldev tshmieldev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, I will actually bring back one comment from the docs and merge it

@tshmieldev
tshmieldev merged commit 12113ef into software-mansion:main Sep 8, 2026
15 of 16 checks passed
bettersoftware-io added a commit to bettersoftware-io/ReactiveTraderCloudClone that referenced this pull request Sep 13, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants