Skip to content

v0.16.0

Latest

Choose a tag to compare

@github-actions github-actions released this 02 Dec 23:27
85d0b2d

Upgrading from 0.15

  • A cold cache builds React Native's precompiled modules before the first test file, as
    registryBuild now 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, set test.maxWorkers: 4.
  • Under the native engine, installed packages share the React your tests render with. If the
    run now fails with PRESET_REACT_MISMATCH, install one copy of react.
  • jest-compat's jest.useFakeTimers() fakes queueMicrotask, as Jest does. 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 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 run vitest -u
    to re-record them.
  • Each entry below that starts with "Behaviour change:" has the details.

Minor Changes

  • e5c5d6c: The SOURCE_EVALUATED_TWICE end-of-run summary prints one line per installed package, and diagnostics lists 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.
  • cf83b91: Behaviour change: the hot runtime picks its worker count from the machine. With no maxWorkers set, 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 example workers: 6 (automatic: 6, one per performance core, at most 6; …). To keep four workers, set test.maxWorkers: 4; --maxWorkers and VITEST_MAX_WORKERS still set the count explicitly too.

  • b93dacd: Behaviour change: jest-compat's jest.useFakeTimers() fakes queueMicrotask, as Jest does. A callback queued with it, such as a scheduleOnRN call through react-native-worklets' Jest mock, now runs when the timers run instead of at once. process.nextTick stays real. A project whose test.fakeTimers sets toFake or toNotFake keeps its own list. To keep the old behaviour, call jest.useFakeTimers({ doNotFake: ['queueMicrotask'] }).

  • 5d237e3: The navigation preset's link props, prevent-remove context, navigator helpers and header heights match React Navigation 7.

    • useLinkProps() returns role: "link", not accessibilityRole, so a link's snapshot changes. usePreventRemoveContext() returns an empty context, not null.
    • useNavigationBuilder().navigation has emit and is its own object, the same on every render.
    • native-stack's new useAnimatedHeaderHeight() is an Animated.Value at the library's default (44 on an iOS phone, 56 on Android). useHeaderHeight() gives the same height, and getDefaultHeaderHeight() the library's formula, instead of 64.

    Update snapshots with accessibilityRole="link" from useLinkProps, and tests that expected null or 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-store shim, ran its hooks against a React the renderer never set up. Node's require and import now serve React, react-is and the test renderers as one copy, the one react-native resolves, as Vite already did. init and migrate write the same resolve.dedupe list.

    Install one copy of react if the run now fails with PRESET_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 registryBuild now 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 reach testTimeout.
    • 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).

  • 1b2b7d5: The screens preset's useTransitionProgress() returns Animated values, and Tabs, featureFlags and compatibilityFlags have the package's shape. progress, closing and goingForward were numbers, so a screen that called progress.interpolate(…) failed. They are now Animated.Values from the engine's React Native, kept across renders and starting at 0 as in react-native-screens (progress was 1). Tabs is { 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_VALUE and the rest) exist under both engines. The library's own Jest mock, which the native engine serves, leaves them out. Its useBottomSheetInternal() answered every read with one { value: 0 } stub, so enableOverDrag and the other booleans were objects. Its useBottomSheet() gave animated values without listeners or modify(). 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's 0. useBottomSheetScrollableCreator() keeps its identity across re-renders, as in the package. createBottomSheetScrollableComponent now 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_TWICE guard reported its files. List the package in dependencies to 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 … from or require()). With diagnostics on, the run names each such import.
  • ed25fed: Under the native engine, an Expo module's native-module mock that calls jest.fn or jest.requireActual loads without the jest-compat layer. expo-font's mocks/ExpoFontLoader.ts is one. Without vitest-native/jest-compat the 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 a jest of its own; globalThis.jest is never set. No action needed.

    • Not covered: a project's local Expo module (modules/<name>) without a package.json of its own, as create-expo-module --local usually makes it; its mock still needs vitest-native/jest-compat. Add one with a name beside its expo-module.config.json.

    Thanks @swey for the fix (#415).

  • 2d2765d: jest.useFakeTimers() works in a project that sets test.fakeTimers.toNotFake. Calls with doNotFake or legacyFakeTimers threw "config.toFake and config.toNotFake cannot be used together". They now run, and a call's doNotFake replaces the project's list, as a call's doNotFake replaces the project's in Jest. The project's fakeTimers is 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.groupOrder run different worker counts, the hot-runtime-off message now recommends the same test.maxWorkers for every project. It used to suggest a separate groupOrder, 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 --maxWorkers or VITEST_MAX_WORKERS set the count, it asks for a value no higher than that. hotRuntime: true gives the same single remedy in HOT_RUNTIME_OVERRIDDEN. See the hot runtime guide. No action needed.

  • 5e018f4: 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. Since 0.15.0 the jest-compat setup loaded React Native's Flow source through Node, and every test file failed at startup with SyntaxError: Unexpected token 'typeof'. No action needed.

    • The setup fills View.prototype only when the mock or the native engine is configured, where it behaves as before. With no engine, it no longer loads react-native.

    Thanks @swey for the fix (#926).

  • d0cbc84: jest.mock under jestMockTransform() now works with Vitest's default globals: false. A test file that imported test or expect from vitest but not vi failed before any test ran, with ReferenceError: vi is not defined. The transform now imports vi itself 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 vi keeps it, and the rewritten calls reach Vitest as vitest.
    • A file that binds both vi and vitest to something other than an import from vitest, where the rewritten calls run, fails with JEST_MOCK_VI_UNAVAILABLE, which names the file.
  • c74b339: react-native-keyboard-controller's useAnimatedKeyboard, KeyboardState, KeyboardContext, KEYBOARD_BORDER_RADIUS, KEYBOARD_HAS_ROUNDED_CORNERS and KeyboardController.setTranslucent exist under the native engine. The library's own Jest mock, which the engine serves, leaves them out. Its shared values also lacked listeners and modify(), and useKeyboardContext() returned the animation values only. The engine now adds what the mock lacks: shared values with Reanimated 4's shape, and a useKeyboardContext() that reads KeyboardContext with 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_CACHE still turns Node's cache on. Delete node_modules/.cache/vitest-native/v8, which is no longer used.

  • fae2a3f: A root __mocks__ mock reaches every installed copy of a package, and jest.mock and jest.unmock apply per copy, as under Jest. No action needed.

    • A nested copy, such as multiformats, gets the mock through import and require; a package's own relative import of its mocked file stays real.
    • A jest.mock factory or jest.unmock changes 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 dual import/require subpath 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.
  • 46c51dd: A package that fails to load because a partial jest.mock lacks 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 function when expo-constants loads under a partial jest.mock('expo-modules-core'). The error is now JEST_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 its require.
  • 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 with ERR_MODULE_NOT_FOUND. It now fails with UNDECLARED_DEPENDENCY_UNCOMPILED, naming the dependency and the package that depends on it. Add the dependency to transform, 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 View works and a method added to View.prototype reaches View refs, as under React Native's Jest preset. No action needed.

    • instanceof View used 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 add querySelector) 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