Skip to content

v0.15.1

Latest

Choose a tag to compare

@github-actions github-actions released this 15 Nov 10:56
· 16 commits to main since this release
2430a92

Patch Changes

  • 51d5899: import * as X from 'lib' now carries every part of a component library built by esbuild or tsup with JSX preserved. The library's index re-exports a module the engine compiles, and Node read that module's names from the published file, whose JSX it could not read: the namespace held only default, so X.Root was undefined and rendering it failed with "Element type is invalid". The engine now lists the names a module re-exports from files it compiles. No action needed.

  • 9def928: A snapshot of an Expo component that passes a ref as a prop, like expo-image's Image, is stable again under the native engine. expo-modules-core's createSnapshotFriendlyRef() is React's createRef, so a snapshot printed the view and React's fiber tree behind each ref: thousands of lines with render timings that changed on every run. It now returns the ref jest-expo serves, which prints as "[React.ref]" and still holds its view. Run vitest -u once to rewrite snapshots written with the old output.

  • fbcebbc: Gesture Handler 3's Touchable, RectButton and BorderlessButton can be pressed from Testing Library under the native engine. userEvent.press and fireEvent.press now call onPress once, as a tap on a device does, and a disabled button takes the press without calling it. Before, userEvent found nothing to press and fireEvent missed RectButton. The engine now mocks the native button host beside the package's own jestSetup.js, following its testOnly_onPress convention. Delete a vi.mock that replaced Touchable with Pressable for this. A Touchable is found by role only with accessible, as on iOS; pass it in your wrapper.

    Thanks @believer for reporting this (#351).

  • 21b99dd: hangTimeout no longer stops a run because the machine slept. On macOS, Node's timers count time asleep, so after a sleep mid-run every running test looked past its budget and the run was stopped on wake. Time the machine spends asleep now extends each limit instead, while a test stuck in synchronous code is still caught once its awake time runs out. No action needed.

  • ff4dba7: Under the hot runtime on Node 22, a React Native library whose ES index is an .mjs file beside CommonJS files now loads. No action needed. Builds from esbuild and tsup publish this layout. vitest-native compiles the .mjs index, and its require() of a CommonJS sibling was served the ES wrapper meant for imports, which Node 22 failed to link (ERR_VM_MODULE_LINK_FAILURE: "is from a module not been linked"). Such a require() now returns the sibling's module.exports, the same instance the test file's own import of it reaches, and a new one in each file.

  • 7569bcb: With diagnostics: true, the hot runtime's per-file reset lines now print. No action needed. Lines such as hot reset: dropped N modules were written while Vitest was starting the next file, which drops console output, so they never appeared. Hot-runtime diagnostics from the worker now go to stderr.

  • 2f36bc5: Under the hot runtime, a library that defines a non-configurable global no longer fails every later file in the worker. No action needed. The reset before each file could not delete such a property (the openai SDK defines one for its provider definitions), so it threw hotRuntime state restoration failed before every file after the first. A property no reset can delete or replace now stays for the worker's life, as Node's own process-wide state does, and diagnostics: true names it. Every other global a file adds is still deleted before the next file.

  • 628e964: jest.mock through a renamed jest from @jest/globals now applies. jestMockTransform() recognised only calls on an identifier named jest, so import { jest as mockJest } from '@jest/globals' followed by mockJest.mock(…) was neither hoisted nor registered, and the module stayed real. A jest imported, required or reached as <namespace>.jest under any name is now handled like the global. A call through a further name (const j = mockJest; j.mock(…)) fails with JEST_BINDING_NOT_FOLLOWED instead of being skipped. No action needed.

  • 63d6efa: vitest-native migrate keeps a suite that ran the real Reanimated on the real library. A Jest setup that calls Reanimated's setUpTests() and mocks Reanimated nowhere ran the real library, but migrate called that setup file covered and suggested deleting it, which moved the suite onto the preset's mock, where getAnimatedStyle returns {}. Migrate now writes presets: { reanimated: false } for such a suite, when react-native-reanimated is a declared dependency, and keeps its setup file; "delete" stays for suites that also mock Reanimated. The presets guide shows the two modes side by side (#834).

    Add presets: { reanimated: false } where your Jest setup ran setUpTests() without mocking Reanimated, and keep that setup file.

  • 14a0b13: vitest-native migrate lists the library mocks in your own Jest setup file that the presets cover. A jest.mock('react-native-reanimated', …), a Safe Area mock or a require('react-native-gesture-handler/jestSetup') in a setupFiles or setupFilesAfterEnv file now appears under "Covered by presets — delete", as the migration guide says. A mock that keeps part of the library is listed for review instead. The report also stops calling jest-react-native, which only React Native's (jest-)?react-native pattern produces, not installed, and lists a preset-shadowed transformIgnorePatterns entry under "Mapped automatically" (#795, #796, #797).

    Delete the setup-file lines the report now lists, once the suite passes without them.

  • bca755b: Reanimated's interpolateColor works under the mock engine. It threw PRESET_UNAVAILABLE there with reanimated 4.x, because its file imports React Native, which the mock engine does not transform. When interpolateColor is first called, the preset now compiles reanimated's own file with the project's @babel/core and @babel/plugin-transform-modules-commonjs, which a React Native app has through its Babel preset. It returns what reanimated returns: RGB, HSV and LAB, with colour strings or numbers. A project without that Babel keeps the error, which now names the packages to install. No action needed.

  • 1ad8a8d: The navigation preset now has the React Navigation 7 API it lacked, so tests calling it no longer fail with "is not a function".

    • Container refs gain resetRoot, setParams, setOptions, isFocused, getId, getParent, removeListener and emit; they and useNavigation() gain preload, replaceParams and navigateDeprecated, as mock functions.
    • StackActions.popTo and CommonActions.preload, replaceParams and navigateDeprecated return React Navigation's action objects. StackRouter, TabRouter, DrawerRouter, NavigationProvider, createScreenFactory, createStandardNavigationFactories, NativeStackView and createNativeStackScreen are exported.
    • Existing exports behave as before. No action needed.
  • 17ab16a: A package's .js file with JSX no longer stops the run with Vite's "Failed to parse source for import analysis" error under the native engine. A package that declares no react-native dependency or peer isn't detected, so Vite serves it uncompiled, and Vite skips JSX in .js files. vitest-native now compiles JSX in such a file when Vite's parser rejects it; every file that parses is served unchanged. No action needed. A package that also ships Metro-only source, such as react-native-calendars, still needs reactNative({ transform: ['<package>'] }), and the error now says so.

  • daac3a3: hotRuntime.freshRuntime now works with vitest-native's presets, so it no longer declines when one that uses React is active. No action needed for vitest-native's presets. Each preset builds its mock with the React react-native uses, the test file's own, so hooks and contexts work in every file. A preset module's factory now receives { React } (PresetFactoryContext). Change a custom preset whose factory makes components, contexts or hooks to use it: factory: ({ React }) => …. Under the native engine, a project that resolves a second copy of React now fails with PRESET_REACT_MISMATCH.

  • 0b18493: vitest-native migrate and doctor no longer say components render the same without React Compiler. The compiler is still not needed for tests to run, but it applies to the files projectBabel compiles with Babel. There a memoized child skips re-rendering, so a test that reads a value React does not track during render can see an earlier value. Other files run without it, so a test that counts renders can see more than under babel-jest (#755).

    Set projectBabel: 'always' where a suite depends on React Compiler running on every file, as under babel-jest.

  • 705f7ae: A Reanimated derived value from a render React discards no longer keeps running, and an updater that writes a value it reads no longer recurses. useDerivedValue started following its inputs during render, so a render React discarded (a Suspense throw, an error boundary) kept its updater running on every later write. It now follows them once the component commits, as Reanimated starts its mapper in an effect. An updater that wrote a value it reads overflowed the stack; the write now waits for the next change to one of its inputs. No action needed.

  • ae8bfea: A cancelled run no longer waits for a stopped background build before it exits. No action needed. On Windows, a cold run cancelled with --bail or Ctrl-C could take several more seconds to exit on a busy machine. The background process that precompiles React Native got its input on stdin, and a stop before it had read that input left a write pending that held the run open until Windows finished tearing that process down. Helper processes now read their input from a file in the project's cache directory, which is removed when they end.

  • e477632: A project setup file that imports react-native now runs under sequence.setupFiles: 'parallel'. The engine's own setup file ran alongside the project's, which could import react-native before its require hooks existed and fail with SyntaxError: Unexpected token 'typeof'. Its setup files now always run first, in order, and a project that sets 'parallel' runs its setup files as a list. No action needed.

What's Changed

  • chore(bakeoffs): re-base the external-app baselines on the supported-floor pins by @danfry1 in #832
  • fix(hot-runtime): keep a non-configurable global for the worker instead of failing every later file by @danfry1 in #774
  • fix(native): the engine's setup files run first under sequence.setupFiles: 'parallel' by @danfry1 in #766
  • fix(native): compile JSX in a package's .js file that Vite serves uncompiled by @danfry1 in #767
  • fix(hang-watch): don't count time asleep toward hangTimeout by @danfry1 in #724
  • fix(presets): a Reanimated derived value follows its inputs from commit, and does not run inside itself by @danfry1 in #820
  • fix(cli): say where React Compiler still applies under projectBabel: 'auto' by @danfry1 in #827
  • fix(cli): migrate lists setup-file mocks the presets cover, without allowlist noise by @danfry1 in #799
  • test(native): run tests that start their own Vitest run in the main native config only by @danfry1 in #752
  • fix(bakeoff): say whether passes fell or only the total changed by @danfry1 in #830
  • test(native): two new configs check the build stamp before loading dist/ by @danfry1 in #842
  • test(scripts): validation and report scripts refuse arguments they do not read by @danfry1 in #772
  • fix(native): Gesture Handler 3's buttons can be pressed from Testing Library by @danfry1 in #777
  • fix(jest-compat): jest.mock through a renamed jest from @jest/globals is hoisted and applied by @danfry1 in #843
  • fix(hot): preset factories build their mocks with the test file's React by @danfry1 in #756
  • fix(hot-runtime): print the per-file reset's diagnostics by @danfry1 in #776
  • docs(site): release notes page for 0.15 by @danfry1 in #845
  • fix(hot): a compiled ES index's require() of a CommonJS sibling links on Node 22 by @danfry1 in #850
  • fix(native): an imported namespace carries the names a module re-exports from files the engine compiles by @danfry1 in #769
  • test(native): run the esbuild re-export ES cases under the hot runtime on Node 22 by @danfry1 in #859
  • fix(presets): the navigation preset has React Navigation 7's actions, ref methods and exports by @danfry1 in #829
  • fix(native): give helper processes their input in a file, not on stdin by @danfry1 in #824
  • fix(cli): migrate keeps a suite that ran the real Reanimated on the real library by @danfry1 in #837
  • test: leave end-to-end scratch trees to the run's temporary root by @danfry1 in #871
  • test(native): time close after a cancelled run from inside the run by @danfry1 in #823
  • fix(native): Expo's snapshot-friendly ref prints as "[React.ref]", as under jest-expo by @danfry1 in #852
  • fix(release): publish the bin path in npm's form and check for publish-time corrections by @danfry1 in #839
  • docs(migration): warn that vitest run -u runs every file by @danfry1 in #851
  • fix(presets): reanimated's interpolateColor works under the mock engine by @danfry1 in #862
  • chore: release 0.15.1 by @danfry1 in #872

Full Changelog: v0.15.0...v0.15.1