Repository navigation
Upgrading from 0.15
- A cold cache builds React Native's precompiled modules before the first test file, as
registryBuildnow defaults to'wait'. To keep the old behaviour, set
reactNative({ registryBuild: 'background' }). - The hot runtime picks its worker count from the machine: one per performance core on Apple
silicon, at most 6. To keep four workers, settest.maxWorkers: 4. - Under the native engine, installed packages share the React your tests render with. If the
run now fails withPRESET_REACT_MISMATCH, install one copy ofreact. - jest-compat's
jest.useFakeTimers()fakesqueueMicrotask, as Jest does. To keep it real,
calljest.useFakeTimers({ doNotFake: ['queueMicrotask'] }). - The navigation preset's
useLinkProps()returnsrole: "link"instead of
accessibilityRole, so snapshots of links change. Check the diff, then runvitest -uto
re-record them. - The screens preset's
useTransitionProgress()progress starts at 0, not 1, as in
react-native-screens, so snapshots that printed it change. Check the diff, then runvitest -u
to re-record them. - Each entry below that starts with "Behaviour change:" has the details.
Minor Changes
-
e5c5d6c: The
SOURCE_EVALUATED_TWICEend-of-run summary prints one line per installed package, anddiagnosticslists every file. Native engine. No action needed.- Files of one installed package that Node and Vite both loaded the same way now print as one line, with the package, counts, test files and one fix. Before, a package's TypeScript source printed a line per file. The header adds the grouped count:
from 14 cause(s), 1 after grouping by installed package:. - With
reactNative({ diagnostics: true }), the summary lists every file and how Node reached it.
- Files of one installed package that Node and Vite both loaded the same way now print as one line, with the package, counts, test files and one fix. Before, a package's TypeScript source printed a line per file. The header adds the grouped count:
-
cf83b91: Behaviour change: the hot runtime picks its worker count from the machine. With no
maxWorkersset, it runs one worker per performance core where the operating system reports core classes (macOS on Apple silicon), at most 6 until a larger layout is measured, and four elsewhere, as before. On a Mac with 6 performance and 6 efficiency cores it now runs 6 workers instead of 4. The memory plan still bounds the count, and the startup line names how it was chosen, for exampleworkers: 6 (automatic: 6, one per performance core, at most 6; …). To keep four workers, settest.maxWorkers: 4;--maxWorkersandVITEST_MAX_WORKERSstill set the count explicitly too. -
b93dacd: Behaviour change: jest-compat's
jest.useFakeTimers()fakesqueueMicrotask, as Jest does. A callback queued with it, such as ascheduleOnRNcall through react-native-worklets' Jest mock, now runs when the timers run instead of at once.process.nextTickstays real. A project whosetest.fakeTimerssetstoFakeortoNotFakekeeps its own list. To keep the old behaviour, calljest.useFakeTimers({ doNotFake: ['queueMicrotask'] }). -
5d237e3: The navigation preset's link props, prevent-remove context, navigator helpers and header heights match React Navigation 7.
useLinkProps()returnsrole: "link", notaccessibilityRole, so a link's snapshot changes.usePreventRemoveContext()returns an empty context, notnull.useNavigationBuilder().navigationhasemitand is its own object, the same on every render.- native-stack's new
useAnimatedHeaderHeight()is anAnimated.Valueat the library's default (44 on an iOS phone, 56 on Android).useHeaderHeight()gives the same height, andgetDefaultHeaderHeight()the library's formula, instead of 64.
Update snapshots with
accessibilityRole="link"fromuseLinkProps, and tests that expectednullor 64 from these. -
827f123: Behaviour change: under the native engine, an installed package with its own copy of React now gets the React your tests render with. Node used each package's nearest copy, so a package that nests React, such as a
use-sync-external-storeshim, ran its hooks against a React the renderer never set up. Node'srequireandimportnow serve React,react-isand the test renderers as one copy, the onereact-nativeresolves, as Vite already did.initandmigratewrite the sameresolve.dedupelist.Install one copy of
reactif the run now fails withPRESET_REACT_MISMATCH: the project or React Native Testing Library resolves another copy. With one copy, nothing changes. -
8a142aa: Behaviour change: on a cold cache, the native engine builds React Native's precompiled modules before the first test file, as
registryBuildnow defaults to'wait'. No action needed;reactNative({ registryBuild: 'background' })keeps the previous behaviour.- Under
'background', the first files compiled React Native inside their tests and could reachtestTimeout. - Projects for the same platform share one build; different platforms build separately. If a build fails, each project falls back to per-file loading without compiling again.
- A wait over 5 s prints one line to stderr; a build that hangs falls back to per-file loading after 120 s. Warm runs, CI runs and the hot runtime are unchanged.
Thanks @YevheniiKotyrlo for the report and the side-by-side reproduction (#873).
- Under
-
1b2b7d5: The screens preset's
useTransitionProgress()returns Animated values, andTabs,featureFlagsandcompatibilityFlagshave the package's shape.progress,closingandgoingForwardwere numbers, so a screen that calledprogress.interpolate(…)failed. They are nowAnimated.Values from the engine's React Native, kept across renders and starting at 0 as in react-native-screens (progresswas1).Tabsis{ Host, Screen }, and the flags carry the package's defaults. Update a test that read these values as numbers or rendered<Tabs>directly.
Patch Changes
-
3323a65: Requiring many images from one folder reads that folder once, not once per image. Each asset's scale variants (
icon@2x.png,icon@3x.png,icon.ios.png) come from a listing of its folder. That listing was read and parsed again for every asset. A design system with hundreds of icons in one folder paid for it hundreds of times in every worker. The folder is now listed once and read again only after it changes. Asset ids and descriptors are unchanged. No action needed. -
e6f9a82: @gorhom/bottom-sheet's
useBottomSheetScrollableCreator,useScrollHandler, the gesture and scroll handler hooks, and its constants (ANIMATION_CONFIGS,KEYBOARD_BEHAVIOR,INITIAL_LAYOUT_VALUEand the rest) exist under both engines. The library's own Jest mock, which the native engine serves, leaves them out. ItsuseBottomSheetInternal()answered every read with one{ value: 0 }stub, soenableOverDragand the other booleans were objects. ItsuseBottomSheet()gave animated values without listeners ormodify(). The engine now adds the missing names. These hooks now give the package's default props and initial states, with animated values at the library mock's0.useBottomSheetScrollableCreator()keeps its identity across re-renders, as in the package.createBottomSheetScrollableComponentnow returns a memoised component that takes a ref. No action needed. -
5149f61: Under the native engine, a package imported without being listed in dependencies is now one module, not two. Vite loaded such an installed React Native package, or a workspace library a React Native package imports, and Node loaded it again. Each copy kept its own state, and the
SOURCE_EVALUATED_TWICEguard reported its files. List the package independenciesto make the dependency explicit.- Installed React Native packages are found whether or not they are listed; the list is rebuilt after an install.
- A workspace library is covered when it is imported unconditionally (a top-level
import,export … fromorrequire()). Withdiagnosticson, the run names each such import.
-
ed25fed: Under the native engine, an Expo module's native-module mock that calls
jest.fnorjest.requireActualloads without the jest-compat layer. expo-font'smocks/ExpoFontLoader.tsis one. Withoutvitest-native/jest-compatthe mock threw as it loaded and the module fell back to the generic stub:Font.getLoadedFonts()returned a promise instead of[]. Such a file now loads as the package's own test support, with ajestof its own;globalThis.jestis never set. No action needed.- Not covered: a project's local Expo module (
modules/<name>) without apackage.jsonof its own, ascreate-expo-module --localusually makes it; its mock still needsvitest-native/jest-compat. Add one with anamebeside itsexpo-module.config.json.
- Not covered: a project's local Expo module (
-
2d2765d:
jest.useFakeTimers()works in a project that setstest.fakeTimers.toNotFake. Calls withdoNotFakeorlegacyFakeTimersthrew "config.toFake and config.toNotFake cannot be used together". They now run, and a call'sdoNotFakereplaces the project's list, as a call'sdoNotFakereplaces the project's in Jest. The project'sfakeTimersis read from the config Vitest resolved, so a workspace project that inherits it is covered too. No action needed. -
524bf1f: When projects in one
sequence.groupOrderrun different worker counts, the hot-runtime-off message now recommends the sametest.maxWorkersfor every project. It used to suggest a separategroupOrder, which runs the groups one after another; that is now the named alternative. When the memory plan lowered only the hot project's count, the message names the admitted count. When--maxWorkersorVITEST_MAX_WORKERSset the count, it asks for a value no higher than that.hotRuntime: truegives the same single remedy inHOT_RUNTIME_OVERRIDDEN. See the hot runtime guide. No action needed. -
5e018f4: A project that uses
vitest-native/jest-compatwithoutreactNative(), as a react-native-web suite does for the Jest API alone, runs its tests again. Since 0.15.0 the jest-compat setup loaded React Native's Flow source through Node, and every test file failed at startup withSyntaxError: Unexpected token 'typeof'. No action needed.- The setup fills
View.prototypeonly when the mock or the native engine is configured, where it behaves as before. With no engine, it no longer loadsreact-native.
- The setup fills
-
d0cbc84:
jest.mockunderjestMockTransform()now works with Vitest's defaultglobals: false. A test file that importedtestorexpectfromvitestbut notvifailed before any test ran, withReferenceError: vi is not defined. The transform now importsviitself in each file it rewrites, unless the file already imports it. Stack traces keep the file's own line numbers. No action needed.- A file that declares its own
vikeeps it, and the rewritten calls reach Vitest asvitest. - A file that binds both
viandvitestto something other than an import fromvitest, where the rewritten calls run, fails withJEST_MOCK_VI_UNAVAILABLE, which names the file.
- A file that declares its own
-
c74b339: react-native-keyboard-controller's
useAnimatedKeyboard,KeyboardState,KeyboardContext,KEYBOARD_BORDER_RADIUS,KEYBOARD_HAS_ROUNDED_CORNERSandKeyboardController.setTranslucentexist under the native engine. The library's own Jest mock, which the engine serves, leaves them out. Its shared values also lacked listeners andmodify(), anduseKeyboardContext()returned the animation values only. The engine now adds what the mock lacks: shared values with Reanimated 4's shape, and auseKeyboardContext()that readsKeyboardContextwith the package's default. No action needed. -
e2ec70d: A cancelled test run under the native engine no longer stalls at exit while workers write Node's compile cache. Each worker wrote its V8 compile-cache entries as it exited, inside Vitest's pool close, and on a loaded Windows machine that held a cancelled cold run open for several seconds. vitest-native no longer turns the cache on; React Native loads from its precompiled modules. Setting
NODE_COMPILE_CACHEstill turns Node's cache on. Deletenode_modules/.cache/vitest-native/v8, which is no longer used. -
fae2a3f: A root
__mocks__mock reaches every installed copy of a package, andjest.mockandjest.unmockapply per copy, as under Jest. No action needed.- A nested copy, such as
multiformats, gets the mock throughimportandrequire; a package's own relative import of its mocked file stays real. - A
jest.mockfactory orjest.unmockchanges only the copy the test file resolves; other copies, workspace links included, keep the__mocks__file. - Under
experimental.nodeMocks, installed packages' imports of a mocked ES-module package or dualimport/requiresubpath get the mock instead of "its factory is async and has not settled". An unsettled factory fails such an import by name and advises once.
- A nested copy, such as
-
46c51dd: A package that fails to load because a partial
jest.mocklacks an export it uses now names the mock and the export. Before, only the package's error was reported, such as(0 , _expoModulesCore.requireOptionalNativeModule) is not a functionwhenexpo-constantsloads under a partialjest.mock('expo-modules-core'). The error is nowJEST_MOCK_MISSING_EXPORT, with the original as its cause.Add the export to the mock, or build the mock on the real module:
jest.mock('x', () => ({ ...jest.requireActual('x'), … })).- The export is never filled in. The mock stays the whole module, as under Jest.
- Not covered:
vi.mock, a module Vite evaluates (the test file and the ES modules it imports), React Native's own precompiled modules, and a package that destructures itsrequire.
-
a833f71: A dependency of an installed React Native package your project does not declare now fails by name when Node cannot run it. That dependency is not compiled, so JSX, Flow or TypeScript in it failed with a bare
SyntaxError, and an ES module build with extensionless imports withERR_MODULE_NOT_FOUND. It now fails withUNDECLARED_DEPENDENCY_UNCOMPILED, naming the dependency and the package that depends on it. Add the dependency totransform, or declare the parent package in your dependencies.- A package installed twice at different versions now has both copies' dependencies compiled.
- A package no longer compiles its optional peers' dependencies along with its own, including a peer only a sibling declares.
-
124f811: Under jest-compat,
ref instanceof Viewworks and a method added toView.prototypereaches View refs, as under React Native's Jest preset. No action needed.instanceof Viewused to throw "Right-hand side of 'instanceof' is not callable", because React Native's View is not a class. It is now true for View, Animated.View and Pressable refs, and false for Text and ScrollView refs.- View refs inherit from
View.prototype, so a method a suite defines there (react-native-paper's Menu tests addquerySelector) can be called on a ref.
Thank you
Thank you to @swey and @YevheniiKotyrlo for the issues and pull requests in this release.
What's Changed
- docs: publish the architecture decision records by @danfry1 in #864
- fix(presets): the screens preset's useTransitionProgress returns Animated values by @danfry1 in #853
- docs(site): a Writing tests guide page by @danfry1 in #879
- fix(presets): bottom-sheet serves its public API and a default context under both engines by @danfry1 in #856
- perf(native): test workers leave Node's compile cache off by @danfry1 in #878
- Add an agent guide with per-lane knowledge by @danfry1 in #860
- fix(presets): navigation link props, prevent-remove context, builder helpers and header height match React Navigation 7 by @danfry1 in #865
- fix(native): a workspace library a React Native workspace package imports undeclared is one module by @danfry1 in #705
- test(conformance): a function that throws when the probe calls it fails the export by @danfry1 in #858
- fix(native): an installed React Native package the run does not declare is Node's by @danfry1 in #718
- feat(native): the guard's end-of-run summary groups by installed package and lists every file under diagnostics by @danfry1 in #809
- fix(jest-compat): jest.useFakeTimers() fakes queueMicrotask, as Jest does by @danfry1 in #869
- fix(jest-compat): instanceof View and View.prototype additions reach View refs by @danfry1 in #848
- feat(native): Node serves React and its renderers as one copy by @danfry1 in #801
- fix(presets): keyboard-controller's mock has the package's public API under the native engine by @danfry1 in #855
- fix(native): a root mocks mock of an ES-module package reaches Node's imports under nodeMocks by @danfry1 in #897
- ci: run the supported Expo SDKs at their newest patch on every push to main by @danfry1 in #846
- Apply root mocks to every installed copy of a package by @danfry1 in #904
- Take the Expo latest-supported SDK list from the supported range by @danfry1 in #908
- docs: running React Native and node projects in one Vitest run by @danfry1 in #910
- Re-measure the bug museum on main and record landed fixes by @danfry1 in #903
- Build the registry before a cold run by default by @danfry1 in #912
- Recommend matching maxWorkers when the hot runtime turns off for a group conflict by @danfry1 in #916
- Refuse an npm older than 11.20 in the Expo consumer runs by @danfry1 in #915
- Decide jest.mock, jest.unmock and root mocks per package copy as Jest does by @danfry1 in #914
- Run the e2e docs checks and fail when a listed file does not run by @danfry1 in #918
- Print a notice when a cold run waits more than 5 s for the registry by @danfry1 in #919
- Make jest.mock work with globals: false under jestMockTransform by @danfry1 in #921
- Share one registry build between concurrent waits for the same entry by @danfry1 in #922
- Name the jest.mock and the export when a module loads under a partial mock by @danfry1 in #923
- Let jest.useFakeTimers() run under a project test.fakeTimers.toNotFake by @danfry1 in #925
- Name uncompiled dependencies of undeclared installed packages, and walk each installed copy by @danfry1 in #924
- fix(jest-compat): run the setup without an engine by @swey in #926
- Assert the engine-less jest-compat setup loads no react-native file by @danfry1 in #932
- fix(native): load an Expo package's native-module mock without jest-compat by @swey in #415
- List an asset's folder once, not once per asset in it by @danfry1 in #933
- docs(changesets): edit the pending entries as 0.16 release notes by @danfry1 in #940
- Choose the hot runtime's automatic worker count from the host by @danfry1 in #937
- chore(release): 0.16.0-rc.1 by @danfry1 in #945
- Stop a stuck native test file or step before the CI job's limit by @danfry1 in #947
- build(deps): bump the github-actions group across 1 directory with 4 updates by @dependabot[bot] in #948
- chore: release 0.16.0 by @danfry1 in #954
- Show the roadmap and invite issue reports from the README and the site by @danfry1 in #959
Full Changelog: v0.15.1...v0.16.0