vitest-native 0.14.0-rc.5 → 0.14.0-rc.6

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 CHANGED
@@ -37,9 +37,42 @@
37
37
  `require()`, `jest.requireActual`'s dependencies and React Native's own requires of a mocked internal;
38
38
  `jest.isolateModules` and `jest.isolateModulesAsync` work. TypeScript app files that Node loads are
39
39
  compiled with the project's Babel config, as babel-jest compiles them.
40
+ - **Unistyles and Skia are mocked automatically.** The new `unistyles` and `skia` presets are
41
+ auto-detected. Remove Unistyles' `react-native-unistyles/mocks` setup file, whose `jest.mock()` calls
42
+ would replace the preset (`vitest-native migrate` removes it), and a hand-written Skia mock, which the
43
+ preset replaces. Skia's preset loads CanvasKit before each test file, about 20–30 ms;
44
+ `presets: { skia: false }` turns it off.
45
+ - **Presets of your own are listed by path.** A preset object of a project's own passed to `presets`
46
+ used to shadow its packages with undefined exports; it is now refused at startup. List the module that
47
+ exports it instead: `presets: { './test/presets/my-lib.ts': true }`.
40
48
 
41
49
  ### Minor Changes
42
50
 
51
+ - f107c6a: A `unistyles` preset for `react-native-unistyles` 3, which resolves styles in native code and could not load in tests. It is auto-detected when the package is installed. It covers everything Unistyles' own Jest mock does (themes from `StyleSheet.configure`, `StyleSheet.create`, `useUnistyles`, `withUnistyles`, `UnistylesRuntime`), and it follows the library's source where that mock does less:
52
+
53
+ - styles resolve as the device parses them: breakpoint values and `mq` keys against the screen, `_web` styles dropped;
54
+ - variants and compound variants apply by the device's rules, selected with `useVariants`;
55
+ - `StyleSheet.configure()` validates its input and picks the theme with the device runtime's messages; adaptive themes follow the colour scheme, and `setTheme`, `updateTheme` and `setAdaptiveThemes` take effect;
56
+ - `useUnistyles()`, `withUnistyles`, `Display`, `Hide` and `ScopedTheme` re-render on a theme or screen change;
57
+ - `ScopedTheme` scopes a theme to its children, and `withUnistyles` applies `uniProps`;
58
+ - `Display` and `Hide` follow `mq` against the screen size;
59
+ - `StyleSheet.flatten`, `compose`, `absoluteFill` and `hairlineWidth` are React Native's, as on a device;
60
+ - `resetAllMocks()` returns the theme to what `StyleSheet.configure()` set.
61
+
62
+ `vitest-native migrate` now deletes a library's own test setup file (such as `react-native-unistyles/mocks`) when a detected preset shadows that library, since its `jest.mock()` calls would replace the preset.
63
+
64
+ - 12a6dc5: A `skia` preset for Skia, which threw at import in tests ("Native Skia Module failed to correctly install JSI Bindings"). It covers both of Skia's package names, `react-native-skia` (2.15.0 and 3.x) and `@shopify/react-native-skia` (up to 2.14.0), shadows whichever is installed, and works under both engines.
65
+
66
+ - It loads CanvasKit, Skia compiled to WebAssembly, and serves Skia's own test mock over it, so the `Skia` API computes with real Skia, and `Canvas` and its drawing render as Views.
67
+ - Its named exports are read from the installed version's ESM build, since Skia's API changes between releases.
68
+ - It adds Skia's Reanimated helpers (`usePathValue`, `useTexture`, …), which the mock leaves out, and makes `matchFont` return a font.
69
+
70
+ The `Preset` type gains an optional async `prepare()`, which completes before any of the user's setup files or test files load, and `PresetModule` an optional `exportsFor()`, which reads the module's named exports from the installed package (or returns `null` when it is not installed, leaving it unshadowed). The skia preset uses both.
71
+
72
+ The project root given to test workers now follows `test.root` (or `--root`), as Vitest's does; a run started from a parent directory resolved packages from that directory in every worker.
73
+
74
+ - 51c351d: Presets of a project's own now work. A preset object passed to `presets: [...]` shadowed its packages with modules whose every export was undefined, under both engines: each test worker rebuilds the presets by name from vitest-native's own, and a preset's factories, being functions, cannot reach a worker from the config. A preset is now listed by the path of a module that default-exports it (or a function returning it): `presets: { './test/presets/my-lib.ts': true }` beside auto-detection, or `presets: ['./test/presets/my-lib.ts']` in a full list. The plugin reads its name and export names while loading the config, and each worker imports it, through Vitest so a TypeScript module loads. A preset object that is not exactly what one of vitest-native's factories returned, such as a built-in preset copied or extended, is refused at configuration time, naming the module form.
75
+
43
76
  - 6724815: Native engine: native module lookups answer the way a device does
44
77
 
45
78
  `NativeModules[name]` and `TurboModuleRegistry.get(name)` returned a stub for every name, so a module that no app registers looked present. Library feature detection then took the wrong branch: expo-constants checks `NativeModules.EXDevLauncher` and, finding it, threw at import while parsing the stub's `manifestString` as JSON.
@@ -145,6 +178,12 @@
145
178
 
146
179
  ### Patch Changes
147
180
 
181
+ - 61ae436: Preset mocks keep their behaviour through `vi.resetAllMocks()` and `mockReset: true`. A gesture-handler gesture built before a reset, such as `Gesture.Pan()` at module scope, keeps chaining. In the mock engine, `Platform.select()` follows `Platform.OS` after a reset, so a setup file's `setPlatform('android')` is no longer undone for `select()` while `Platform.OS` stays `"android"`. `Platform.select()` also picks by key presence, as React Native does, so an explicit `ios: undefined` selects `undefined`.
182
+
183
+ - de438fc: The reanimated preset's animation builders keep chaining after `vi.resetAllMocks()` or `mockReset: true`, so `LinearTransition.springify().damping(20)` and `SharedTransition.duration(300).custom(...)` no longer throw.
184
+
185
+ - df06716: Under the native engine, an imported BMP image's `width` and `height` are read as Metro 0.87.1 reads them. An OS/2 bitmap (12-byte header) now has its real dimensions instead of a misread width, and a file whose header size is not a bitmap's registers without dimensions, as other unreadable images do.
186
+
148
187
  - dc2543b: `migrate` writes Jest's mock-clearing behaviour correctly:
149
188
 
150
189
  - Jest's `resetMocks` becomes `test.mockReset`, Vitest's name for it. It was written as `test.resetMocks`, which Vitest ignores.
package/README.md CHANGED
@@ -555,6 +555,8 @@ export default defineConfig({
555
555
  | `presets.flashList()` | `@shopify/flash-list` | `FlashList` rendering its data through `renderItem`, the ref surface, v2 recycler hooks |
556
556
  | `presets.bottomSheet()` | `@gorhom/bottom-sheet` | `BottomSheet`, `BottomSheetModal` + provider, sheet views, scroll/list variants, `BottomSheetTextInput`, backdrop, footer |
557
557
  | `presets.keyboardController()` | `react-native-keyboard-controller` | `KeyboardProvider`, `KeyboardAvoidingView`, `KeyboardAwareScrollView`, `KeyboardStickyView`, `KeyboardToolbar`; the imperative `KeyboardController` is inert |
558
+ | `presets.unistyles()` | `react-native-unistyles`, `react-native-unistyles/reanimated` | Unistyles 3: `StyleSheet.configure`/`create` with themes, variants and compound variants, `useUnistyles`, `withUnistyles`, `UnistylesRuntime` theme switching, `mq` with `Display`/`Hide`; matches the library's own Jest mock and follows its source where that mock does less |
559
+ | `presets.skia()` | `react-native-skia`, `@shopify/react-native-skia` | Skia's own test mock (`Mock(CanvasKit)`) over CanvasKit, Skia compiled to WebAssembly: the `Skia` API computes with real Skia, `Canvas` and its drawing render as Views; plus Skia's Reanimated helpers (`usePathValue`, `useTexture`, …) and a `matchFont` that returns a font |
558
560
 
559
561
  Presets apply under **both** engines: the mock engine and `engine: 'native'` (where they shadow each
560
562
  library's native runtime — worklets, native modules — exactly as Jest does, while the surrounding tree
package/dist/cli.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
4
- const require_ecosystem = require("./ecosystem-Bg7DgFeG.cjs");
5
- const require_preset_map = require("./preset-map-mzfu_YUy.cjs");
4
+ const require_ecosystem = require("./ecosystem-DTozsAyV.cjs");
5
+ const require_preset_map = require("./preset-map-B-T1CcPr.cjs");
6
6
  const require_memory = require("./memory-6EPHrJA1.cjs");
7
7
  let node_fs = require("node:fs");
8
8
  node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
@@ -1531,14 +1531,19 @@ function analyzeJestConfig(root) {
1531
1531
  for (const key of ["setupFiles", "setupFilesAfterEnv"]) {
1532
1532
  const files = take(key);
1533
1533
  if (!files?.length) continue;
1534
- for (const f of files) if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1535
- else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1536
- else if (f.startsWith("<rootDir>")) {
1537
- setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1538
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1539
- } else {
1540
- setupFiles.push(JSON.stringify(f));
1541
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1534
+ for (const f of files) {
1535
+ const setupPackage = /^(@[^/]+\/[^/]+|[^@./][^/]*)\//.exec(f)?.[1];
1536
+ const setupPreset = setupPackage ? require_preset_map.presetShadowing(setupPackage) : void 0;
1537
+ if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1538
+ else if (setupPreset && active.includes(setupPreset)) presetCovered.push(`${key}: '${f}' — ${setupPackage}'s own test setup; the auto-detected ${setupPreset} preset shadows ${setupPackage}, and this file's jest.mock() calls would replace it; delete.`);
1539
+ else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1540
+ else if (f.startsWith("<rootDir>")) {
1541
+ setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1542
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1543
+ } else {
1544
+ setupFiles.push(JSON.stringify(f));
1545
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1546
+ }
1542
1547
  }
1543
1548
  }
1544
1549
  const mapper = take("moduleNameMapper");
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { d as validatePeerDependency, l as PEER_REQUIREMENTS, n as detectEngine, o as formatNativeOwnershipManifest, r as createNativeOwnershipPolicy, t as detectEcosystemPackages } from "./ecosystem-lBGWAeOw.mjs";
3
- import { a as presetShadowing, n as DEFAULT_ASSET_EXTS, o as testsItself, r as PRESET_MODULES, t as AUTO_DETECT_PRESETS } from "./preset-map-mriqY254.mjs";
2
+ import { d as validatePeerDependency, l as PEER_REQUIREMENTS, n as detectEngine, o as formatNativeOwnershipManifest, r as createNativeOwnershipPolicy, t as detectEcosystemPackages } from "./ecosystem-BzWGVo_T.mjs";
3
+ import { a as presetShadowing, n as DEFAULT_ASSET_EXTS, o as testsItself, r as PRESET_MODULES, t as AUTO_DETECT_PRESETS } from "./preset-map-DO-dKDgr.mjs";
4
4
  import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-FYbP0_gg.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import fs from "node:fs";
@@ -1527,14 +1527,19 @@ function analyzeJestConfig(root) {
1527
1527
  for (const key of ["setupFiles", "setupFilesAfterEnv"]) {
1528
1528
  const files = take(key);
1529
1529
  if (!files?.length) continue;
1530
- for (const f of files) if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1531
- else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1532
- else if (f.startsWith("<rootDir>")) {
1533
- setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1534
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1535
- } else {
1536
- setupFiles.push(JSON.stringify(f));
1537
- automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1530
+ for (const f of files) {
1531
+ const setupPackage = /^(@[^/]+\/[^/]+|[^@./][^/]*)\//.exec(f)?.[1];
1532
+ const setupPreset = setupPackage ? presetShadowing(setupPackage) : void 0;
1533
+ if (/react-native\/jest\/setup/.test(f)) presetCovered.push(`${key}: '${f}' — the plugin injects its own setup; delete.`);
1534
+ else if (setupPreset && active.includes(setupPreset)) presetCovered.push(`${key}: '${f}' — ${setupPackage}'s own test setup; the auto-detected ${setupPreset} preset shadows ${setupPackage}, and this file's jest.mock() calls would replace it; delete.`);
1535
+ else if (/jest-expo/.test(f)) attention.push(`${key}: '${f}' — ${expoPresetCoverage()}.`);
1536
+ else if (f.startsWith("<rootDir>")) {
1537
+ setupFiles.push(absolutePath(f.replace(/^<rootDir>\/?/, "./")));
1538
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1539
+ } else {
1540
+ setupFiles.push(JSON.stringify(f));
1541
+ automatic.push(`${key}: '${f}' → test.setupFiles (its jest.* calls run under the jest-compat shim).`);
1542
+ }
1538
1543
  }
1539
1544
  }
1540
1545
  const mapper = take("moduleNameMapper");
@@ -1,5 +1,5 @@
1
1
  import { n as VitestNativeTypeError } from "./errors-CxoBUfVJ.mjs";
2
- import { t as AUTO_DETECT_PRESETS } from "./preset-map-mriqY254.mjs";
2
+ import { t as AUTO_DETECT_PRESETS } from "./preset-map-DO-dKDgr.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
@@ -1,6 +1,6 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
2
  const require_errors = require("./errors-B3lJK46O.cjs");
3
- const require_preset_map = require("./preset-map-mzfu_YUy.cjs");
3
+ const require_preset_map = require("./preset-map-B-T1CcPr.cjs");
4
4
  let node_fs = require("node:fs");
5
5
  node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
6
6
  let node_path = require("node:path");
package/dist/errors.d.mts CHANGED
@@ -32,6 +32,7 @@ export type VitestNativeErrorCode =
32
32
  | "HOT_STATE_RESTORE_FAILED"
33
33
  | "HOT_CJS_CACHE_RESET"
34
34
  | "PRESET_UNAVAILABLE"
35
+ | "PRESET_NOT_PREPARED"
35
36
  | "WRONG_ENGINE_FOR_HELPER"
36
37
  | "HELPERS_BEFORE_SETUP"
37
38
  | "JEST_API_UNSUPPORTED"
package/dist/helpers.cjs CHANGED
@@ -23,9 +23,6 @@ function setPlatform(os) {
23
23
  const platform = getMock().Platform;
24
24
  platform.OS = os;
25
25
  platform.Version = os === "ios" ? "17.0" : 34;
26
- platform.select.mockImplementation((specifics) => {
27
- return specifics[os] ?? specifics.default;
28
- });
29
26
  }
30
27
  function setDimensions(dims) {
31
28
  const native = getNativeControl();
@@ -123,9 +120,6 @@ function resetAllMocks() {
123
120
  clearMockFns(mock);
124
121
  mock.Platform.OS = "ios";
125
122
  mock.Platform.Version = "17.0";
126
- mock.Platform.select.mockImplementation((specifics) => {
127
- return specifics.ios ?? specifics.default;
128
- });
129
123
  for (const value of Object.values(mock)) {
130
124
  const candidate = value;
131
125
  if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
package/dist/helpers.mjs CHANGED
@@ -22,9 +22,6 @@ function setPlatform(os) {
22
22
  const platform = getMock().Platform;
23
23
  platform.OS = os;
24
24
  platform.Version = os === "ios" ? "17.0" : 34;
25
- platform.select.mockImplementation((specifics) => {
26
- return specifics[os] ?? specifics.default;
27
- });
28
25
  }
29
26
  function setDimensions(dims) {
30
27
  const native = getNativeControl();
@@ -122,9 +119,6 @@ function resetAllMocks() {
122
119
  clearMockFns(mock);
123
120
  mock.Platform.OS = "ios";
124
121
  mock.Platform.Version = "17.0";
125
- mock.Platform.select.mockImplementation((specifics) => {
126
- return specifics.ios ?? specifics.default;
127
- });
128
122
  for (const value of Object.values(mock)) {
129
123
  const candidate = value;
130
124
  if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
@@ -1,5 +1,4 @@
1
1
  import { Mock } from "vitest";
2
- //#endregion
3
2
  //#region src/types.d.ts
4
3
  /** Static methods available on the Image component mock. */
5
4
  interface ImageStatic {
@@ -200,10 +199,26 @@ interface PresetModule {
200
199
  factory: () => Record<string, any>;
201
200
  /** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
202
201
  exports: string[];
202
+ /**
203
+ * Named exports read from the installed package, for a package whose API changes
204
+ * between releases; replaces `exports` when present. Called once at Vite config time
205
+ * with the project root and platform. `null` means the package is not installed, so
206
+ * the module is not shadowed at all.
207
+ */
208
+ exportsFor?: (context: {
209
+ projectRoot: string;
210
+ platform: "ios" | "android";
211
+ }) => string[] | null;
203
212
  }
204
213
  interface Preset {
205
214
  name: string;
206
215
  modules: Record<string, PresetModule>;
216
+ /**
217
+ * Optional async work the setup file awaits before each test file, ahead of any
218
+ * `factory`. For a mock that needs something only an async API provides: the skia
219
+ * preset loads CanvasKit (Skia's WebAssembly build) here.
220
+ */
221
+ prepare?: () => Promise<void>;
207
222
  /**
208
223
  * Optional JSON-serializable configuration for the preset. Presets are rebuilt
209
224
  * inside Vitest worker processes from their `name`, so any options passed to a
@@ -251,17 +266,22 @@ interface VitestNativeOptions {
251
266
  * way. Listing every other detected preset back by hand just to drop one is
252
267
  * both tedious and a thing that silently rots as dependencies change.
253
268
  *
254
- * Only built-in presets are supported (reanimated, gestureHandler,
255
- * safeAreaContext, navigation, asyncStorage, screens, expo). For custom
256
- * module mocking, use vi.mock() in a setup file.
269
+ * Preset modules of your own are listed by path: a module whose default export is a
270
+ * `Preset` or a function returning one. In an array they sit beside vitest-native's
271
+ * presets (`presets.reanimated()`, ...); in the object form a path set to `true`
272
+ * adds one to the auto-detected presets. A preset object of your own cannot be
273
+ * listed directly, because its factories run in the test workers, which a function
274
+ * in the config cannot reach; the plugin imports the module there instead. A
275
+ * relative path resolves from the project root.
257
276
  *
258
277
  * @example
259
278
  * ```ts
260
279
  * import { reactNative, presets } from 'vitest-native';
261
- * reactNative({ presets: [presets.reanimated(), presets.navigation()] })
280
+ * reactNative({ presets: { navigation: false, './test/presets/my-lib.ts': true } })
281
+ * reactNative({ presets: [presets.reanimated(), './test/presets/my-lib.ts'] })
262
282
  * ```
263
283
  */
264
- presets?: Preset[] | Record<string, boolean>;
284
+ presets?: (Preset | string)[] | Record<string, boolean>;
265
285
  /**
266
286
  * `engine: 'mock'` only. Plain-data overrides merged into the react-native
267
287
  * module mock.
@@ -448,8 +468,14 @@ declare function keyboardController(): Preset;
448
468
  //#endregion
449
469
  //#region src/presets/worklets.d.ts
450
470
  declare function worklets(): Preset;
471
+ //#endregion
472
+ //#region src/presets/unistyles.d.ts
473
+ declare function unistyles(): Preset;
474
+ //#endregion
475
+ //#region src/presets/skia.d.ts
476
+ declare function skia(): Preset;
451
477
  declare namespace index_d_exports {
452
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
478
+ export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
453
479
  }
454
480
  //#endregion
455
- export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };
481
+ export { VitestNativeOptions as C, ReactNativeMock as S, navigation as _, keyboardController as a, reanimated as b, vectorIcons as c, netInfo as d, mmkv as f, asyncStorage as g, screens as h, worklets as i, webview as l, expo as m, skia as n, bottomSheet as o, deviceInfo as p, unistyles as r, flashList as s, index_d_exports as t, svg as u, safeAreaContext as v, Preset as x, gestureHandler as y };
@@ -1,4 +1,5 @@
1
1
  import { Mock } from "vitest";
2
+ //#endregion
2
3
  //#region src/types.d.ts
3
4
  /** Static methods available on the Image component mock. */
4
5
  interface ImageStatic {
@@ -199,10 +200,26 @@ interface PresetModule {
199
200
  factory: () => Record<string, any>;
200
201
  /** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
201
202
  exports: string[];
203
+ /**
204
+ * Named exports read from the installed package, for a package whose API changes
205
+ * between releases; replaces `exports` when present. Called once at Vite config time
206
+ * with the project root and platform. `null` means the package is not installed, so
207
+ * the module is not shadowed at all.
208
+ */
209
+ exportsFor?: (context: {
210
+ projectRoot: string;
211
+ platform: "ios" | "android";
212
+ }) => string[] | null;
202
213
  }
203
214
  interface Preset {
204
215
  name: string;
205
216
  modules: Record<string, PresetModule>;
217
+ /**
218
+ * Optional async work the setup file awaits before each test file, ahead of any
219
+ * `factory`. For a mock that needs something only an async API provides: the skia
220
+ * preset loads CanvasKit (Skia's WebAssembly build) here.
221
+ */
222
+ prepare?: () => Promise<void>;
206
223
  /**
207
224
  * Optional JSON-serializable configuration for the preset. Presets are rebuilt
208
225
  * inside Vitest worker processes from their `name`, so any options passed to a
@@ -250,17 +267,22 @@ interface VitestNativeOptions {
250
267
  * way. Listing every other detected preset back by hand just to drop one is
251
268
  * both tedious and a thing that silently rots as dependencies change.
252
269
  *
253
- * Only built-in presets are supported (reanimated, gestureHandler,
254
- * safeAreaContext, navigation, asyncStorage, screens, expo). For custom
255
- * module mocking, use vi.mock() in a setup file.
270
+ * Preset modules of your own are listed by path: a module whose default export is a
271
+ * `Preset` or a function returning one. In an array they sit beside vitest-native's
272
+ * presets (`presets.reanimated()`, ...); in the object form a path set to `true`
273
+ * adds one to the auto-detected presets. A preset object of your own cannot be
274
+ * listed directly, because its factories run in the test workers, which a function
275
+ * in the config cannot reach; the plugin imports the module there instead. A
276
+ * relative path resolves from the project root.
256
277
  *
257
278
  * @example
258
279
  * ```ts
259
280
  * import { reactNative, presets } from 'vitest-native';
260
- * reactNative({ presets: [presets.reanimated(), presets.navigation()] })
281
+ * reactNative({ presets: { navigation: false, './test/presets/my-lib.ts': true } })
282
+ * reactNative({ presets: [presets.reanimated(), './test/presets/my-lib.ts'] })
261
283
  * ```
262
284
  */
263
- presets?: Preset[] | Record<string, boolean>;
285
+ presets?: (Preset | string)[] | Record<string, boolean>;
264
286
  /**
265
287
  * `engine: 'mock'` only. Plain-data overrides merged into the react-native
266
288
  * module mock.
@@ -447,8 +469,14 @@ declare function keyboardController(): Preset;
447
469
  //#endregion
448
470
  //#region src/presets/worklets.d.ts
449
471
  declare function worklets(): Preset;
472
+ //#endregion
473
+ //#region src/presets/unistyles.d.ts
474
+ declare function unistyles(): Preset;
475
+ //#endregion
476
+ //#region src/presets/skia.d.ts
477
+ declare function skia(): Preset;
450
478
  declare namespace index_d_exports {
451
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
479
+ export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
452
480
  }
453
481
  //#endregion
454
- export { gestureHandler as _, flashList as a, ReactNativeMock as b, svg as c, deviceInfo as d, expo as f, safeAreaContext as g, navigation as h, bottomSheet as i, netInfo as l, asyncStorage as m, worklets as n, vectorIcons as o, screens as p, keyboardController as r, webview as s, index_d_exports as t, mmkv as u, reanimated as v, VitestNativeOptions as x, Preset as y };
482
+ export { VitestNativeOptions as C, ReactNativeMock as S, navigation as _, keyboardController as a, reanimated as b, vectorIcons as c, netInfo as d, mmkv as f, asyncStorage as g, screens as h, worklets as i, webview as l, expo as m, skia as n, bottomSheet as o, deviceInfo as p, unistyles as r, flashList as s, index_d_exports as t, svg as u, safeAreaContext as v, Preset as x, gestureHandler as y };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as ReactNativeMock, t as index_d_exports, x as VitestNativeOptions, y as Preset } from "./index-D7-7BtcM.mjs";
1
+ import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-BSyUeoga.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/plugin.d.ts
4
4
  /**