Skip to content

vitest-native 0.16 ​

0.16 makes a cold native-engine run wait for React Native's precompiled modules again, lets the hot runtime size its workers from the machine, and serves one copy of React to installed packages under the native engine. jest-compat's fake timers now fake queueMicrotask, as Jest does, and the navigation, screens, bottom-sheet and keyboard-controller presets match their libraries more closely.

This page covers what changes for a project on 0.15. Every entry, with the detail behind it, is in the changelog. The supported versions are the same as in 0.15.

Before you upgrade ​

Seven changes can change a run, a test or a snapshot. Each has a setting that keeps the 0.15 behaviour, or a one-time step:

  • A cold cache builds React Native's precompiled modules before the first test file, as registryBuild now defaults to 'wait'. Under 'background', the first files compiled React Native inside their tests and could reach testTimeout. Warm runs, CI runs and the hot runtime are unchanged. To keep the old behaviour, set reactNative({ registryBuild: 'background' }).
  • The hot runtime picks its worker count from the machine when maxWorkers is not set: one worker per performance core on Apple silicon, at most 6, and four elsewhere, as before. The memory plan still bounds the count, and the startup line says how it was chosen. To keep four workers, set test.maxWorkers: 4. See Workers and memory.
  • Under the native engine, installed packages share the React your tests render with. A package that nests its own copy of React, such as a use-sync-external-store shim, now gets the copy react-native resolves, as Vite already gave it. If the run now fails with PRESET_REACT_MISMATCH, install one copy of react.
  • jest-compat's jest.useFakeTimers() fakes queueMicrotask, as Jest does, so a queued callback runs when the timers run. process.nextTick stays real, and a project whose test.fakeTimers sets toFake or toNotFake keeps its own list. To keep it real, call jest.useFakeTimers({ doNotFake: ['queueMicrotask'] }).
  • The navigation preset's useLinkProps() returns role: "link" instead of accessibilityRole, so snapshots of links change. Check the diff, then run vitest -u to re-record them.
  • The navigation preset's usePreventRemoveContext() returns an empty context, not null, and header heights are the library's default (44 on an iOS phone, 56 on Android) instead of 64. Update tests that expected null or 64 from these.
  • The screens preset's useTransitionProgress() returns Animated.Values, and progress starts at 0, not 1, as in react-native-screens. Snapshots that printed it change, and a test that read these values as numbers needs updating. Check the diff, then run vitest -u to re-record the snapshots.

Presets closer to their libraries ​

  • Navigation matches React Navigation 7: usePreventRemoveContext() returns an empty context, not null; useNavigationBuilder().navigation has emit and stays the same object on every render; and native-stack's useAnimatedHeaderHeight(), useHeaderHeight() and getDefaultHeaderHeight() give the library's default height instead of 64.
  • Screens: Tabs is { Host, Screen }, and featureFlags and compatibilityFlags carry the package's defaults.
  • Bottom sheet: useBottomSheetScrollableCreator, useScrollHandler, the gesture and scroll handler hooks, and the library's constants exist under both engines, with the package's default props and initial states.
  • Keyboard controller: useAnimatedKeyboard, KeyboardState, KeyboardContext and the missing constants exist under the native engine, with shared values in Reanimated 4's shape.

Closer to Jest ​

  • A root __mocks__ mock reaches every installed copy of a package, and jest.mock and jest.unmock apply per copy, as under Jest.
  • A partial jest.mock that lacks an export a package uses fails by name, as JEST_MOCK_MISSING_EXPORT, naming the mock and the export.
  • jest.mock under jestMockTransform() works with Vitest's default globals: false.
  • jest.useFakeTimers() works in a project that sets test.fakeTimers.toNotFake.
  • A project that uses vitest-native/jest-compat without reactNative(), as a react-native-web suite does for the Jest API alone, runs its tests again.
  • Under the native engine, an Expo module's native-module mock that calls jest.fn or jest.requireActual loads without the jest-compat layer.
  • Under jest-compat, ref instanceof View works, and a method added to View.prototype reaches View refs, as under React Native's Jest preset.

Native engine ​

  • An installed React Native package imported without being listed in dependencies is one module, not two, and so is a workspace library that a React Native package imports unconditionally (a top-level import, export … from or require()). Vite and Node no longer each load their own copy of it.
  • A dependency of an installed React Native package that your project does not declare fails by name when Node cannot run it, as UNDECLARED_DEPENDENCY_UNCOMPILED. Add it to transform, or declare the parent package in your dependencies. A package's optional peers no longer have their dependencies compiled along with its own, so such a dependency can now fail this way too.
  • The SOURCE_EVALUATED_TWICE summary prints one line per installed package, and diagnostics lists every file.
  • Under the experimental experimental.nodeMocks flag, installed packages' imports of a mocked ES-module package get the mock.
  • vitest-native no longer turns on Node's compile cache, so a cancelled run no longer stalls at exit. Delete node_modules/.cache/vitest-native/v8, which is no longer used.

How 0.16.0 was built ​

The npm tarball is reproducible from the repository. Packing the v0.16.0 tag from its lockfile gives a tarball whose sha512 equals the one on npm. The release workflow checks this on every release: its publish job packs the tag again and refuses to publish unless the tarball is byte-identical to the one the test jobs ran against. The package is also published with npm provenance, which links it to the workflow run that built it.

To check it yourself:

bash
git clone https://github.com/danfry1/vitest-native.git
cd vitest-native
git checkout v0.16.0
bun install --frozen-lockfile
bun run build
cd packages/vitest-native
npm pack --ignore-scripts
echo "sha512-$(openssl dgst -sha512 -binary vitest-native-0.16.0.tgz | base64)"
npm view vitest-native@0.16.0 dist.integrity

The last two lines print the same value.

Thank you ​

Thank you to @swey and @YevheniiKotyrlo for the issues and pull requests in this release.

Released under the MIT License. · llms.txt