vitest-native 0.14.0-rc.3 → 0.14.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/README.md +19 -18
- package/dist/cli.cjs +1296 -120
- package/dist/cli.mjs +1296 -120
- package/dist/{ecosystem-DFbU_MPe.mjs → ecosystem-CWnXwWCk.mjs} +1 -1
- package/dist/{ecosystem-DI1AhK_k.cjs → ecosystem-D18-tC1Z.cjs} +1 -1
- package/dist/errors.d.mts +1 -0
- package/dist/index.mjs +253 -48
- package/dist/jest-compat/interop.mjs +78 -4
- package/dist/jest-compat/jest-globals.mjs +5 -2
- package/dist/jest-compat/jest-object.mjs +201 -0
- package/dist/jest-compat/setup.mjs +15 -1
- package/dist/native/boundary.mjs +6 -0
- package/dist/native/hooks.mjs +65 -16
- package/dist/native/loader.mjs +179 -28
- package/dist/native/match.d.mts +10 -0
- package/dist/native/match.mjs +89 -0
- package/dist/native/nitro.mjs +60 -0
- package/dist/native/setup.mjs +50 -12
- package/dist/native/transform.mjs +25 -3
- package/dist/native/tsconfig-paths.d.mts +5 -0
- package/dist/native/tsconfig-paths.mjs +163 -0
- package/dist/preset-map-C9L_UtZa.mjs +164 -0
- package/dist/preset-map-CtNv1AGU.cjs +202 -0
- package/dist/setup.mjs +2 -2
- package/docs/release-readiness.md +11 -0
- package/package.json +1 -1
- package/dist/preset-map-BoG19dLa.cjs +0 -35
- package/dist/preset-map-DuX0ocdn.mjs +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -15,11 +15,29 @@
|
|
|
15
15
|
- **Expo path aliases resolve.** In an Expo project on Vite 8, imports through tsconfig `paths` (the
|
|
16
16
|
template's `@/…`) now resolve as Metro resolves them; a `vite-tsconfig-paths` plugin or a hand-written
|
|
17
17
|
alias for them can go.
|
|
18
|
+
- **Vitest 5 keeps transformed modules on disk.** The plugin turns on Vitest's `fsModuleCache` unless
|
|
19
|
+
your config sets it, keyed so that upgrading vitest-native or any dependency invalidates it. Set
|
|
20
|
+
`test.fsModuleCache: false` to opt out.
|
|
21
|
+
- **react-native-mmkv 3 and later run as themselves.** They detect Vitest and use their own in-memory
|
|
22
|
+
backend, so the `mmkv` preset now applies to mmkv 2 only. Tests get mmkv's real API (v4's `remove`)
|
|
23
|
+
and change listeners instead of the preset's approximation.
|
|
24
|
+
- **jest-compat follows Jest more closely.** A name a `jest.mock` factory leaves out is `undefined`
|
|
25
|
+
instead of an error, `new` on a `jest.fn` with an arrow implementation works, and
|
|
26
|
+
`process.env.JEST_WORKER_ID` is set, so code that checks for Jest takes its test branch.
|
|
18
27
|
- **`hotRuntime: true` is stricter.** Combined with a configured pool, `test.isolate`, or a conflicting
|
|
19
28
|
CLI flag, it now fails at startup with `HOT_RUNTIME_OVERRIDDEN` instead of warning and overriding.
|
|
20
29
|
|
|
21
30
|
### Minor Changes
|
|
22
31
|
|
|
32
|
+
- 52e80aa: Turn on Vitest 5's persistent transform cache, with a complete cache key
|
|
33
|
+
|
|
34
|
+
On Vitest 5 the plugin turns on Vitest's persistent transform cache (`fsModuleCache`) unless the
|
|
35
|
+
config sets it, and contributes its own part of the cache key through Vitest's cache key
|
|
36
|
+
generator: the vitest-native version, the plugin's resolved options, and a digest of the project's
|
|
37
|
+
lockfile. Vitest's own key does not cover plugin versions or what a plugin reads from disk, so
|
|
38
|
+
without this an upgrade could serve modules transformed by the previous version. Warm runs of a
|
|
39
|
+
104-file production Expo suite were about 11% faster. Set `test.fsModuleCache: false` to opt out.
|
|
40
|
+
|
|
23
41
|
- 87d8dd0: Use the hot runtime for suites migrated from Jest under `hotRuntime: 'auto'`
|
|
24
42
|
|
|
25
43
|
`'auto'`, the default, no longer keeps per-file isolation for suites set up with
|
|
@@ -58,6 +76,72 @@
|
|
|
58
76
|
|
|
59
77
|
### Patch Changes
|
|
60
78
|
|
|
79
|
+
- 041fd77: Fix native-engine gaps found running a production Expo app's existing suite
|
|
80
|
+
|
|
81
|
+
- React Native's setup now runs before the project's own setup files. A setup file that imported `react-native` or `@testing-library/react-native` failed on React Native's Flow source whenever the hot runtime was not in use.
|
|
82
|
+
- Importing `expo` (directly, or through packages such as `expo-location`) works: Expo's dev-server message socket is stubbed on every load path, and packages a compiled CommonJS module requires internally stay shadowed by their presets instead of loading the real native packages.
|
|
83
|
+
- `require('#/…')` and `jest.requireActual('#/…')` resolve the project's `resolve.alias` entries and, when Vite resolves them for imports, its tsconfig `paths`.
|
|
84
|
+
- App source required through Node compiles `export * as ns from '…'` when the project's toolchain provides the Babel plugin, as Expo's does.
|
|
85
|
+
- `react-native-nitro-modules` imports under the native engine: its native install step provides a proxy with no hybrid objects, and creating one throws `NITRO_HYBRID_OBJECT_UNAVAILABLE`.
|
|
86
|
+
- `react-native-mmkv` 3 and later run their own built-in test mode, with their real API and change listeners; the `mmkv` preset now applies to mmkv 2 only.
|
|
87
|
+
|
|
88
|
+
- dbb9c74: Match Jest for four behaviours migrated suites depend on in jest-compat
|
|
89
|
+
|
|
90
|
+
- **Getters in a `jest.mock` factory are read lazily.** The CommonJS interop copied the factory's return with an object spread, which ran every getter while the factory was evaluated. A factory such as `() => ({ get IS_WEB() { return mockIsWeb } })` runs during the hoisted imports, before the test file's `let mockIsWeb` is initialised, so it threw `Cannot access 'mockIsWeb' before initialization`, and later changes to the variable were never seen. Accessors are now read from the module on each access, as an importer reads them in Jest.
|
|
91
|
+
- **An export a `jest.mock` factory leaves out is `undefined`.** Jest reads named imports as properties of `module.exports`; Vitest throws `No "x" export is defined on the "m" mock`. Factories passed through `jestMockTransform` now follow Jest. A plain `vi.mock` factory keeps Vitest's strict check.
|
|
92
|
+
- **`new` on a `jest.fn` with an arrow implementation returns the implementation's result.** Jest applies a mock's implementation whether or not it is called with `new`, so `jest.fn().mockImplementation(() => ({ fetch }))` works as a class mock; Vitest constructs the implementation and throws `… is not a constructor`. Mocks created by `jest.fn` and `jest.spyOn` now follow Jest, including `mockReturnValue` and `mockResolvedValue` under `new`, and a `jest.spyOn` spy with no implementation set calls an arrow-function original under `new` (also after `mockReset()`). A mock that already existed, which `jest.spyOn` returns as it is, is left unchanged, and `vi.fn` is unchanged.
|
|
93
|
+
- **`process.env.JEST_WORKER_ID` is set.** The compat setup sets it from Vitest's 1-based `VITEST_POOL_ID` when it is not already set, so code that detects a Jest run (for example `__DEV__ && !process.env.JEST_WORKER_ID`) takes its test branch.
|
|
94
|
+
|
|
95
|
+
- 52e80aa: Run the native engine's ESM loader hooks in-thread where Node supports it
|
|
96
|
+
|
|
97
|
+
The native engine's ESM loader hooks now run in-thread through `module.registerHooks()` where Node
|
|
98
|
+
provides it (22.15+, 23.5+), instead of on a separate loader thread through `module.register()`.
|
|
99
|
+
Every resolve and load of an externalized module previously waited on a synchronous cross-thread
|
|
100
|
+
request; profiled on a 104-file production Expo suite, that wait was 18% of worker CPU time. Older
|
|
101
|
+
Node versions keep the threaded hooks, and `VITEST_NATIVE_LOADER_THREAD=1` forces them.
|
|
102
|
+
|
|
103
|
+
- 52e80aa: Reuse externalized resolutions across test files under the hot runtime
|
|
104
|
+
|
|
105
|
+
Under the hot runtime, externalized imports are no longer re-resolved from scratch for every test
|
|
106
|
+
file. The per-file generation stamp on parent URLs defeated Node's resolve cache; the loader now
|
|
107
|
+
keeps successful resolutions per unstamped parent, so Node stops re-reading package.json scopes to
|
|
108
|
+
decide module formats on every file.
|
|
109
|
+
|
|
110
|
+
- 6100732: Make `migrate` reproduce Jest's effective test set and settings, and report Babel plugins
|
|
111
|
+
|
|
112
|
+
`migrate` translated only an explicit `testMatch`, so a project that took its patterns from a
|
|
113
|
+
preset or from Jest's defaults was migrated to Vitest's default include instead. On a jest-expo
|
|
114
|
+
app this collected about twice as many files as Jest ran and missed some of Jest's own tests.
|
|
115
|
+
The suggested config now uses Jest's effective patterns: the config's `testMatch`, otherwise the
|
|
116
|
+
installed preset's (read from it the way Jest loads it), otherwise Jest's defaults for the
|
|
117
|
+
installed major. `testPathIgnorePatterns` and `modulePathIgnorePatterns` become `test.exclude`
|
|
118
|
+
globs where the regex has an exact glob form (and are reported where it does not), and
|
|
119
|
+
extensions missing from `moduleFileExtensions` are excluded, since Jest never sees those files.
|
|
120
|
+
|
|
121
|
+
Other changes:
|
|
122
|
+
|
|
123
|
+
- Flags that the `test` script passes to Jest are applied over the config as Jest applies them:
|
|
124
|
+
`--testTimeout`, `--maxWorkers`, `--runInBand` and `--config`. `--bail` is reported rather than
|
|
125
|
+
mapped because Vitest's `bail` counts failed tests, not suites.
|
|
126
|
+
- Anchored `moduleNameMapper` keys (`^name$`) become exact `resolve.alias` entries. A mapper whose
|
|
127
|
+
target is a file of the same package, for a specifier that package's `exports` already serves, is
|
|
128
|
+
dropped; a redirect to another package is kept.
|
|
129
|
+
- `transformIgnorePatterns` allowlists with nested and optional groups are now parsed. A package
|
|
130
|
+
goes into `transform` only when it ships a `.js` file under its entry point that is not standard
|
|
131
|
+
JavaScript (JSX or Flow) and the engine does not already compile it; the report names that file.
|
|
132
|
+
- Packages that run their own test mode under Vitest (react-native-mmkv 3 and later) are not
|
|
133
|
+
credited to a preset by either command, and the engine-detection baseline both commands use
|
|
134
|
+
is computed with the presets the plugin would actually enable.
|
|
135
|
+
- The project's Babel config is read, and its plugins are sorted into required (macro plugins),
|
|
136
|
+
mapped (`module-resolver` aliases become `resolve.alias`), not needed (worklets/reanimated
|
|
137
|
+
plugins, React Compiler) and unknown. `migrate` adds required plugins through
|
|
138
|
+
`@rolldown/plugin-babel` when Vite 8 and that package are installed, and otherwise prints the
|
|
139
|
+
snippet to add. `doctor` warns about the same plugins.
|
|
140
|
+
- The CLI no longer claims more than the presets do. The report and `doctor` name the modules the
|
|
141
|
+
expo preset shadows instead of saying Expo modules are covered. A manual `__mocks__` file is
|
|
142
|
+
called redundant only when an active preset shadows that module. Asset mappers are compared with
|
|
143
|
+
the extensions the plugin stubs by default.
|
|
144
|
+
|
|
61
145
|
- 2233866: Stop a circular-dependency warning on an Expo project's first run
|
|
62
146
|
|
|
63
147
|
Babel loads its presets and plugins with `require` during a transform, and those requires went
|
package/README.md
CHANGED
|
@@ -536,24 +536,25 @@ export default defineConfig({
|
|
|
536
536
|
|
|
537
537
|
### Available Presets
|
|
538
538
|
|
|
539
|
-
|
|
|
540
|
-
|
|
541
|
-
| `presets.reanimated()`
|
|
542
|
-
| `presets.
|
|
543
|
-
| `presets.
|
|
544
|
-
| `presets.
|
|
545
|
-
| `presets.
|
|
546
|
-
| `presets.screens()`
|
|
547
|
-
| `presets.
|
|
548
|
-
| `presets.
|
|
549
|
-
| `presets.
|
|
550
|
-
| `presets.
|
|
551
|
-
| `presets.
|
|
552
|
-
| `presets.
|
|
553
|
-
| `presets.
|
|
554
|
-
| `presets.
|
|
555
|
-
| `presets.
|
|
556
|
-
| `presets.
|
|
539
|
+
| Preset | Library | What's mocked |
|
|
540
|
+
|--------|---------|---------------|
|
|
541
|
+
| `presets.reanimated()` | `react-native-reanimated` | `useSharedValue`, `useAnimatedStyle`, `withTiming`, `withSpring`, `withDelay`, `withSequence`, `withRepeat`, layout animations (`FadeIn`, `FadeOut`, `SlideInRight`), `Easing`, `interpolate`, `createAnimatedComponent` |
|
|
542
|
+
| `presets.worklets()` | `react-native-worklets` | `runOnJS`, `runOnUI`, `scheduleOnRN`, `scheduleOnUI`, `createWorkletRuntime`, … run synchronously on the JS thread |
|
|
543
|
+
| `presets.gestureHandler()` | `react-native-gesture-handler` | `GestureHandlerRootView`, gesture handlers (Pan, Tap, LongPress, Pinch, Rotation, Fling), `Gesture` API (v2), `GestureDetector`, `Swipeable`, touchable wrappers, state constants |
|
|
544
|
+
| `presets.safeAreaContext()` | `react-native-safe-area-context` | `SafeAreaProvider`, `SafeAreaView`, `useSafeAreaInsets`, `useSafeAreaFrame`, `initialWindowMetrics`, `withSafeAreaInsets` |
|
|
545
|
+
| `presets.navigation()` | `@react-navigation/native`, `@react-navigation/native-stack`, `@react-navigation/bottom-tabs`, `@react-navigation/drawer`, `@react-navigation/elements` | `NavigationContainer`, `useNavigation`, `useRoute`, `useFocusEffect`, `useIsFocused`, `CommonActions`, `StackActions`, `TabActions`, `DrawerActions`, navigators |
|
|
546
|
+
| `presets.screens()` | `react-native-screens` | `enableScreens`, `Screen`, `ScreenContainer`, `ScreenStack` |
|
|
547
|
+
| `presets.asyncStorage()` | `@react-native-async-storage/async-storage` | in-memory store (`getItem`/`setItem`/`multiGet`/`mergeItem`/…) |
|
|
548
|
+
| `presets.expo()` | `expo-constants`, `expo-font`, `expo-asset`, `expo-splash-screen`, `expo-linking`, `expo-status-bar` | constants, fonts, assets, splash screen, linking, status bar |
|
|
549
|
+
| `presets.deviceInfo()` | `react-native-device-info` | string/bool/number getters with sync + async variants |
|
|
550
|
+
| `presets.mmkv()` | `react-native-mmkv` | in-memory `MMKV` + `useMMKV*` hooks, for mmkv 2 only: the library tests itself from v3 (its own in-memory backend under Vitest), so the preset steps aside |
|
|
551
|
+
| `presets.netInfo()` | `@react-native-community/netinfo` | connected-wifi state, `fetch`/`refresh`/`addEventListener`/`useNetInfo`, state-type enums |
|
|
552
|
+
| `presets.svg()` | `react-native-svg` | `Svg`, `Path`, `Circle`, `Rect`, `G`, … as host components |
|
|
553
|
+
| `presets.webview()` | `react-native-webview` | `WebView` (default + named) host component |
|
|
554
|
+
| `presets.vectorIcons()` | `@react-native-vector-icons/common` | `createIconSet` and the dynamic font loader shared by the v10+ scoped icon sets (not the legacy unscoped `react-native-vector-icons`) |
|
|
555
|
+
| `presets.flashList()` | `@shopify/flash-list` | `FlashList` rendering its data through `renderItem`, the ref surface, v2 recycler hooks |
|
|
556
|
+
| `presets.bottomSheet()` | `@gorhom/bottom-sheet` | `BottomSheet`, `BottomSheetModal` + provider, sheet views, scroll/list variants, `BottomSheetTextInput`, backdrop, footer |
|
|
557
|
+
| `presets.keyboardController()` | `react-native-keyboard-controller` | `KeyboardProvider`, `KeyboardAvoidingView`, `KeyboardAwareScrollView`, `KeyboardStickyView`, `KeyboardToolbar`; the imperative `KeyboardController` is inert |
|
|
557
558
|
|
|
558
559
|
Presets apply under **both** engines: the mock engine and `engine: 'native'` (where they shadow each
|
|
559
560
|
library's native runtime — worklets, native modules — exactly as Jest does, while the surrounding tree
|