vitest-native 0.8.0 → 0.10.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +1063 -0
  2. package/README.md +47 -2
  3. package/dist/cli.cjs +642 -0
  4. package/dist/cli.d.cts +4 -0
  5. package/dist/cli.d.mts +4 -0
  6. package/dist/cli.mjs +638 -0
  7. package/dist/ecosystem-CO5vqExO.mjs +318 -0
  8. package/dist/ecosystem-IuZ-Gv0R.cjs +356 -0
  9. package/dist/errors-Dm5yLNTF.mjs +64 -0
  10. package/dist/errors-flXDIeWk.cjs +75 -0
  11. package/dist/errors.d.mts +46 -0
  12. package/dist/errors.mjs +78 -0
  13. package/dist/helpers.cjs +6 -23
  14. package/dist/helpers.d.cts +0 -6
  15. package/dist/helpers.d.mts +0 -6
  16. package/dist/helpers.mjs +6 -23
  17. package/dist/{index-vlK4zxuK.d.mts → index-BJL4cQ-l.d.cts} +22 -7
  18. package/dist/{index-YjjYELG7.d.cts → index-CvCU0cLl.d.mts} +20 -9
  19. package/dist/index.d.mts +8 -6
  20. package/dist/index.mjs +563 -232
  21. package/dist/jest-compat/interop.mjs +15 -0
  22. package/dist/jest-compat/setup.mjs +164 -5
  23. package/dist/matchers.cjs +16 -7
  24. package/dist/matchers.mjs +16 -7
  25. package/dist/native/boundary.mjs +108 -30
  26. package/dist/native/compile-cache.mjs +10 -5
  27. package/dist/native/explain.mjs +69 -0
  28. package/dist/native/hooks.mjs +151 -4
  29. package/dist/native/loader.mjs +61 -12
  30. package/dist/native/match.mjs +107 -8
  31. package/dist/native/module-reset.mjs +63 -0
  32. package/dist/native/registry.mjs +540 -0
  33. package/dist/native/reset.mjs +18 -12
  34. package/dist/native/resolve.d.mts +22 -0
  35. package/dist/native/resolve.mjs +21 -13
  36. package/dist/native/runner.mjs +34 -7
  37. package/dist/native/setup.mjs +19 -3
  38. package/dist/native/transform.mjs +195 -21
  39. package/dist/native/worker.mjs +69 -17
  40. package/dist/pool-Bcxp4Qrg.mjs +118 -0
  41. package/dist/pool-CFND7plG.cjs +122 -0
  42. package/dist/{preset-map-DCWaM08s.mjs → preset-map-BpDG_D5m.mjs} +1 -1
  43. package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-DxilQ4pI.cjs} +1 -1
  44. package/dist/{presets-7eMfp7o2.cjs → presets-BGTqVH6C.cjs} +227 -52
  45. package/dist/{presets-23FJ76O4.mjs → presets-CK85x8ey.mjs} +222 -53
  46. package/dist/presets.d.mts +2 -2
  47. package/dist/presets.mjs +2 -2
  48. package/dist/rntl-matchers.d.ts +35 -0
  49. package/dist/serializer.cjs +33 -3
  50. package/dist/serializer.mjs +33 -3
  51. package/dist/setup.mjs +544 -193
  52. package/docs/hot-default-design.md +129 -0
  53. package/docs/migrating-from-jest.md +43 -7
  54. package/docs/migrating-from-vitest-react-native.md +1 -1
  55. package/docs/release-readiness.md +24 -6
  56. package/docs/versioning.md +133 -0
  57. package/package.json +40 -38
  58. package/dist/index.cjs +0 -643
  59. package/dist/index.d.cts +0 -14
  60. package/dist/pool-B7LBfcMQ.mjs +0 -67
  61. package/dist/pool-p54QV1dQ.cjs +0 -69
  62. package/dist/presets.cjs +0 -17
  63. package/dist/presets.d.cts +0 -2
  64. package/dist/setup.cjs +0 -2514
  65. package/dist/setup.d.cts +0 -1
@@ -0,0 +1,64 @@
1
+ //#region src/errors.mjs
2
+ /**
3
+ * The error types this package throws.
4
+ *
5
+ * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
6
+ * verbatim and import this by relative path, and the test suite loads those same files
7
+ * from src — so the module has to resolve identically in both trees. A .ts source would
8
+ * only exist in one of them.
9
+ *
10
+ * WHAT SURVIVES WHERE, measured rather than assumed:
11
+ *
12
+ * - In the main process, and in a user's own try/catch inside a test, everything is
13
+ * intact.
14
+ * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
15
+ * `stack`. `code` and every other own property is dropped.
16
+ *
17
+ * So the message must stay self-sufficient: nothing may move out of it into a field on
18
+ * the assumption a reader will see it.
19
+ *
20
+ * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
21
+ * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
22
+ * prototype check would quietly fail across that seam. Shape does not care.
23
+ */
24
+ const PREFIX = "[vitest-native]";
25
+ /** Guarantees the prefix exactly once, however the caller wrote the message. */
26
+ function withPrefix(message) {
27
+ return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
28
+ }
29
+ function buildMessage(message, options) {
30
+ const base = withPrefix(message);
31
+ return options?.docs ? `${base}\nSee ${options.docs}` : base;
32
+ }
33
+ /**
34
+ * Error options, omitted entirely when there is no cause.
35
+ *
36
+ * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
37
+ * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
38
+ * print an empty cause and to make these errors shaped differently from every other
39
+ * error in the process. Passing nothing keeps them identical.
40
+ */
41
+ function errorOptions(options) {
42
+ return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
43
+ }
44
+ /** A failure originating in vitest-native. */
45
+ var VitestNativeError = class extends Error {
46
+ constructor(code, message, options) {
47
+ super(buildMessage(message, options), errorOptions(options));
48
+ this.name = "VitestNativeError";
49
+ this.code = code;
50
+ }
51
+ };
52
+ /**
53
+ * A vitest-native failure that is also a type error — a badly typed option, say.
54
+ * Extends TypeError so `instanceof TypeError` keeps working for consumers.
55
+ */
56
+ var VitestNativeTypeError = class extends TypeError {
57
+ constructor(code, message, options) {
58
+ super(buildMessage(message, options), errorOptions(options));
59
+ this.name = "VitestNativeTypeError";
60
+ this.code = code;
61
+ }
62
+ };
63
+ //#endregion
64
+ export { VitestNativeTypeError as n, VitestNativeError as t };
@@ -0,0 +1,75 @@
1
+ //#region src/errors.mjs
2
+ /**
3
+ * The error types this package throws.
4
+ *
5
+ * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
6
+ * verbatim and import this by relative path, and the test suite loads those same files
7
+ * from src — so the module has to resolve identically in both trees. A .ts source would
8
+ * only exist in one of them.
9
+ *
10
+ * WHAT SURVIVES WHERE, measured rather than assumed:
11
+ *
12
+ * - In the main process, and in a user's own try/catch inside a test, everything is
13
+ * intact.
14
+ * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
15
+ * `stack`. `code` and every other own property is dropped.
16
+ *
17
+ * So the message must stay self-sufficient: nothing may move out of it into a field on
18
+ * the assumption a reader will see it.
19
+ *
20
+ * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
21
+ * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
22
+ * prototype check would quietly fail across that seam. Shape does not care.
23
+ */
24
+ const PREFIX = "[vitest-native]";
25
+ /** Guarantees the prefix exactly once, however the caller wrote the message. */
26
+ function withPrefix(message) {
27
+ return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
28
+ }
29
+ function buildMessage(message, options) {
30
+ const base = withPrefix(message);
31
+ return options?.docs ? `${base}\nSee ${options.docs}` : base;
32
+ }
33
+ /**
34
+ * Error options, omitted entirely when there is no cause.
35
+ *
36
+ * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
37
+ * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
38
+ * print an empty cause and to make these errors shaped differently from every other
39
+ * error in the process. Passing nothing keeps them identical.
40
+ */
41
+ function errorOptions(options) {
42
+ return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
43
+ }
44
+ /** A failure originating in vitest-native. */
45
+ var VitestNativeError = class extends Error {
46
+ constructor(code, message, options) {
47
+ super(buildMessage(message, options), errorOptions(options));
48
+ this.name = "VitestNativeError";
49
+ this.code = code;
50
+ }
51
+ };
52
+ /**
53
+ * A vitest-native failure that is also a type error — a badly typed option, say.
54
+ * Extends TypeError so `instanceof TypeError` keeps working for consumers.
55
+ */
56
+ var VitestNativeTypeError = class extends TypeError {
57
+ constructor(code, message, options) {
58
+ super(buildMessage(message, options), errorOptions(options));
59
+ this.name = "VitestNativeTypeError";
60
+ this.code = code;
61
+ }
62
+ };
63
+ //#endregion
64
+ Object.defineProperty(exports, "VitestNativeError", {
65
+ enumerable: true,
66
+ get: function() {
67
+ return VitestNativeError;
68
+ }
69
+ });
70
+ Object.defineProperty(exports, "VitestNativeTypeError", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return VitestNativeTypeError;
74
+ }
75
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Types for errors.mjs. Hand-written because the implementation is plain .mjs — see the
3
+ * comment there for why it cannot be TypeScript.
4
+ */
5
+
6
+ /**
7
+ * Stable identifiers for the failures this package raises. They are part of the public
8
+ * surface: renaming one is a breaking change for anyone branching on it.
9
+ */
10
+ export type VitestNativeErrorCode =
11
+ | "INVALID_OPTION"
12
+ | "UNKNOWN_OPTION"
13
+ | "UNSUPPORTED_PEER"
14
+ | "UNSUPPORTED_POOL"
15
+ | "ENGINE_REQUIRES_BABEL"
16
+ | "MOCKS_REQUIRE_MOCK_ENGINE"
17
+ | "TRANSFORM_FAILED"
18
+ | "UNTRANSPILED_PACKAGE"
19
+ | "HOT_WORKER_ENV"
20
+ | "HOT_WORKER_PRELOAD"
21
+ | "HOT_RUNTIME_UNAVAILABLE"
22
+ | "PRESET_UNAVAILABLE"
23
+ | "WRONG_ENGINE_FOR_HELPER"
24
+ | "HELPERS_BEFORE_SETUP"
25
+ | "JEST_API_UNSUPPORTED"
26
+ | "MATCHER_BAD_RECEIVER";
27
+
28
+ export interface VitestNativeErrorOptions {
29
+ cause?: unknown;
30
+ /** A docs URL appended to the message, since fields do not reach the reporter. */
31
+ docs?: string;
32
+ }
33
+
34
+ export declare class VitestNativeError extends Error {
35
+ readonly code: VitestNativeErrorCode;
36
+ constructor(code: VitestNativeErrorCode, message: string, options?: VitestNativeErrorOptions);
37
+ }
38
+
39
+ export declare class VitestNativeTypeError extends TypeError {
40
+ readonly code: VitestNativeErrorCode;
41
+ constructor(code: VitestNativeErrorCode, message: string, options?: VitestNativeErrorOptions);
42
+ }
43
+
44
+ export declare function isVitestNativeError(
45
+ error: unknown,
46
+ ): error is VitestNativeError | VitestNativeTypeError;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The error types this package throws.
3
+ *
4
+ * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
5
+ * verbatim and import this by relative path, and the test suite loads those same files
6
+ * from src — so the module has to resolve identically in both trees. A .ts source would
7
+ * only exist in one of them.
8
+ *
9
+ * WHAT SURVIVES WHERE, measured rather than assumed:
10
+ *
11
+ * - In the main process, and in a user's own try/catch inside a test, everything is
12
+ * intact.
13
+ * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
14
+ * `stack`. `code` and every other own property is dropped.
15
+ *
16
+ * So the message must stay self-sufficient: nothing may move out of it into a field on
17
+ * the assumption a reader will see it.
18
+ *
19
+ * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
20
+ * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
21
+ * prototype check would quietly fail across that seam. Shape does not care.
22
+ */
23
+
24
+ const PREFIX = "[vitest-native]";
25
+
26
+ /** Guarantees the prefix exactly once, however the caller wrote the message. */
27
+ function withPrefix(message) {
28
+ return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
29
+ }
30
+
31
+ function buildMessage(message, options) {
32
+ const base = withPrefix(message);
33
+ return options?.docs ? `${base}\nSee ${options.docs}` : base;
34
+ }
35
+
36
+ /**
37
+ * Error options, omitted entirely when there is no cause.
38
+ *
39
+ * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
40
+ * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
41
+ * print an empty cause and to make these errors shaped differently from every other
42
+ * error in the process. Passing nothing keeps them identical.
43
+ */
44
+ function errorOptions(options) {
45
+ return options && "cause" in options && options.cause !== undefined
46
+ ? { cause: options.cause }
47
+ : undefined;
48
+ }
49
+
50
+ /** A failure originating in vitest-native. */
51
+ export class VitestNativeError extends Error {
52
+ constructor(code, message, options) {
53
+ super(buildMessage(message, options), errorOptions(options));
54
+ this.name = "VitestNativeError";
55
+ this.code = code;
56
+ }
57
+ }
58
+
59
+ /**
60
+ * A vitest-native failure that is also a type error — a badly typed option, say.
61
+ * Extends TypeError so `instanceof TypeError` keeps working for consumers.
62
+ */
63
+ export class VitestNativeTypeError extends TypeError {
64
+ constructor(code, message, options) {
65
+ super(buildMessage(message, options), errorOptions(options));
66
+ this.name = "VitestNativeTypeError";
67
+ this.code = code;
68
+ }
69
+ }
70
+
71
+ /** True for any error this package raised, whichever copy of this module created it. */
72
+ export function isVitestNativeError(error) {
73
+ return (
74
+ error instanceof Error &&
75
+ typeof (/** @type {{ code?: unknown }} */ (error).code) === "string" &&
76
+ (error.name === "VitestNativeError" || error.name === "VitestNativeTypeError")
77
+ );
78
+ }
package/dist/helpers.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_errors = require("./errors-flXDIeWk.cjs");
2
3
  //#region src/helpers.ts
3
4
  /**
4
5
  * Test helpers for vitest-native.
@@ -8,7 +9,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
9
  */
9
10
  function getMock() {
10
11
  const mock = globalThis.__vitest_native_mock;
11
- if (!mock) throw new Error("vitest-native helpers called before setup. Ensure the vitest-native plugin is configured.");
12
+ if (!mock) throw new require_errors.VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
12
13
  return mock;
13
14
  }
14
15
  function getNativeControl() {
@@ -81,21 +82,10 @@ function resetAllMocks() {
81
82
  mock.Platform.select.mockImplementation((specifics) => {
82
83
  return specifics.ios ?? specifics.default;
83
84
  });
84
- if (mock.Dimensions._reset) mock.Dimensions._reset();
85
- else mock.Dimensions.set({
86
- window: {
87
- width: 390,
88
- height: 844,
89
- scale: 3,
90
- fontScale: 1
91
- },
92
- screen: {
93
- width: 390,
94
- height: 844,
95
- scale: 3,
96
- fontScale: 1
97
- }
98
- });
85
+ for (const value of Object.values(mock)) {
86
+ const candidate = value;
87
+ if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
88
+ }
99
89
  if (mock.useWindowDimensions._resetDimensions) mock.useWindowDimensions._resetDimensions({
100
90
  width: 390,
101
91
  height: 844,
@@ -108,15 +98,8 @@ function resetAllMocks() {
108
98
  scale: 3,
109
99
  fontScale: 1
110
100
  });
111
- if (mock.Appearance._reset) mock.Appearance._reset();
112
- else mock.Appearance.setColorScheme("light");
113
101
  if (mock.useColorScheme._resetScheme) mock.useColorScheme._resetScheme("light");
114
102
  else if (mock.useColorScheme._setScheme) mock.useColorScheme._setScheme("light");
115
- if (mock.Keyboard._reset) mock.Keyboard._reset();
116
- if (mock.AppState._reset) mock.AppState._reset();
117
- if (mock.BackHandler._reset) mock.BackHandler._reset();
118
- if (mock.I18nManager._reset) mock.I18nManager._reset();
119
- if (mock.DeviceEventEmitter._reset) mock.DeviceEventEmitter._reset();
120
103
  if (originalNativeModules !== null) {
121
104
  mock.NativeModules = originalNativeModules;
122
105
  originalNativeModules = null;
@@ -1,10 +1,4 @@
1
1
  //#region src/helpers.d.ts
2
- /**
3
- * Test helpers for vitest-native.
4
- *
5
- * These functions mutate the live mock instances created by the setup file.
6
- * Import from 'vitest-native/helpers' in your test files.
7
- */
8
2
  declare function setPlatform(os: "ios" | "android"): void;
9
3
  declare function setDimensions(dims: {
10
4
  width: number;
@@ -1,10 +1,4 @@
1
1
  //#region src/helpers.d.ts
2
- /**
3
- * Test helpers for vitest-native.
4
- *
5
- * These functions mutate the live mock instances created by the setup file.
6
- * Import from 'vitest-native/helpers' in your test files.
7
- */
8
2
  declare function setPlatform(os: "ios" | "android"): void;
9
3
  declare function setDimensions(dims: {
10
4
  width: number;
package/dist/helpers.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as VitestNativeError } from "./errors-Dm5yLNTF.mjs";
1
2
  //#region src/helpers.ts
2
3
  /**
3
4
  * Test helpers for vitest-native.
@@ -7,7 +8,7 @@
7
8
  */
8
9
  function getMock() {
9
10
  const mock = globalThis.__vitest_native_mock;
10
- if (!mock) throw new Error("vitest-native helpers called before setup. Ensure the vitest-native plugin is configured.");
11
+ if (!mock) throw new VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
11
12
  return mock;
12
13
  }
13
14
  function getNativeControl() {
@@ -80,21 +81,10 @@ function resetAllMocks() {
80
81
  mock.Platform.select.mockImplementation((specifics) => {
81
82
  return specifics.ios ?? specifics.default;
82
83
  });
83
- if (mock.Dimensions._reset) mock.Dimensions._reset();
84
- else mock.Dimensions.set({
85
- window: {
86
- width: 390,
87
- height: 844,
88
- scale: 3,
89
- fontScale: 1
90
- },
91
- screen: {
92
- width: 390,
93
- height: 844,
94
- scale: 3,
95
- fontScale: 1
96
- }
97
- });
84
+ for (const value of Object.values(mock)) {
85
+ const candidate = value;
86
+ if (candidate && typeof candidate === "object" && typeof candidate._reset === "function") candidate._reset();
87
+ }
98
88
  if (mock.useWindowDimensions._resetDimensions) mock.useWindowDimensions._resetDimensions({
99
89
  width: 390,
100
90
  height: 844,
@@ -107,15 +97,8 @@ function resetAllMocks() {
107
97
  scale: 3,
108
98
  fontScale: 1
109
99
  });
110
- if (mock.Appearance._reset) mock.Appearance._reset();
111
- else mock.Appearance.setColorScheme("light");
112
100
  if (mock.useColorScheme._resetScheme) mock.useColorScheme._resetScheme("light");
113
101
  else if (mock.useColorScheme._setScheme) mock.useColorScheme._setScheme("light");
114
- if (mock.Keyboard._reset) mock.Keyboard._reset();
115
- if (mock.AppState._reset) mock.AppState._reset();
116
- if (mock.BackHandler._reset) mock.BackHandler._reset();
117
- if (mock.I18nManager._reset) mock.I18nManager._reset();
118
- if (mock.DeviceEventEmitter._reset) mock.DeviceEventEmitter._reset();
119
102
  if (originalNativeModules !== null) {
120
103
  mock.NativeModules = originalNativeModules;
121
104
  originalNativeModules = null;
@@ -1,5 +1,7 @@
1
1
  import { Mock } from "vitest";
2
2
 
3
+ //#region \0rolldown/runtime.js
4
+ //#endregion
3
5
  //#region src/types.d.ts
4
6
  /** Static methods available on the Image component mock. */
5
7
  interface ImageStatic {
@@ -242,9 +244,14 @@ interface VitestNativeOptions {
242
244
  */
243
245
  engine?: "auto" | "mock" | "native";
244
246
  /**
245
- * Built-in third-party library presets. When provided, only these presets
246
- * are used. When omitted, vitest-native auto-detects installed packages
247
- * and enables matching presets automatically.
247
+ * Built-in third-party library presets.
248
+ *
249
+ * An ARRAY replaces auto-detection entirely: only those presets are used.
250
+ *
251
+ * An OBJECT keeps auto-detection and turns individual presets off by name —
252
+ * `{ navigation: false }` — which is what you want when one preset gets in the
253
+ * way. Listing every other detected preset back by hand just to drop one is
254
+ * both tedious and a thing that silently rots as dependencies change.
248
255
  *
249
256
  * Only built-in presets are supported (reanimated, gestureHandler,
250
257
  * safeAreaContext, navigation, asyncStorage, screens, expo). For custom
@@ -256,7 +263,7 @@ interface VitestNativeOptions {
256
263
  * reactNative({ presets: [presets.reanimated(), presets.navigation()] })
257
264
  * ```
258
265
  */
259
- presets?: Preset[];
266
+ presets?: Preset[] | Record<string, boolean>;
260
267
  /**
261
268
  * `engine: 'mock'` only. Plain-data overrides merged into the react-native
262
269
  * module mock.
@@ -301,7 +308,12 @@ interface VitestNativeOptions {
301
308
  * is enforced between Vitest scheduler tasks; a single task containing
302
309
  * multiple files cannot be interrupted.
303
310
  * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets
304
- * or exceeds this value, also between scheduler tasks.
311
+ * or exceeds this value, also between scheduler tasks. When hot is enabled
312
+ * and you set neither `memoryLimit` nor `recycleAfterFiles`, a default
313
+ * per-worker bound of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is applied so
314
+ * memory stays bounded out of the box (multi-worker runs recycle a worker
315
+ * once it crosses the ceiling). Single-worker hot can't recycle, so the
316
+ * bound is inert there — run with `maxWorkers >= 2` for bounded hot memory.
305
317
  * - `preserveGlobals`: exact globalThis property names intentionally owned
306
318
  * by resident external libraries. App/test globals are otherwise removed
307
319
  * between files. Storybook's preview registry is preserved automatically.
@@ -359,8 +371,11 @@ declare function bottomSheet(): Preset;
359
371
  //#endregion
360
372
  //#region src/presets/keyboard-controller.d.ts
361
373
  declare function keyboardController(): Preset;
374
+ //#endregion
375
+ //#region src/presets/worklets.d.ts
376
+ declare function worklets(): Preset;
362
377
  declare namespace index_d_exports {
363
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview };
378
+ export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
364
379
  }
365
380
  //#endregion
366
- export { Preset as _, vectorIcons as a, mmkv as c, screens as d, asyncStorage as f, reanimated as g, gestureHandler as h, flashList as i, deviceInfo as l, safeAreaContext as m, keyboardController as n, webview as o, navigation as p, bottomSheet as r, svg as s, index_d_exports as t, expo as u, ReactNativeMock as v, VitestNativeOptions as y };
381
+ export { reanimated as _, flashList as a, VitestNativeOptions as b, svg as c, expo as d, screens as f, gestureHandler as g, safeAreaContext as h, bottomSheet as i, mmkv as l, navigation as m, worklets as n, vectorIcons as o, asyncStorage as p, keyboardController as r, webview as s, index_d_exports as t, deviceInfo as u, Preset as v, ReactNativeMock as y };
@@ -1,7 +1,5 @@
1
1
  import { Mock } from "vitest";
2
2
 
3
- //#region \0rolldown/runtime.js
4
- //#endregion
5
3
  //#region src/types.d.ts
6
4
  /** Static methods available on the Image component mock. */
7
5
  interface ImageStatic {
@@ -244,9 +242,14 @@ interface VitestNativeOptions {
244
242
  */
245
243
  engine?: "auto" | "mock" | "native";
246
244
  /**
247
- * Built-in third-party library presets. When provided, only these presets
248
- * are used. When omitted, vitest-native auto-detects installed packages
249
- * and enables matching presets automatically.
245
+ * Built-in third-party library presets.
246
+ *
247
+ * An ARRAY replaces auto-detection entirely: only those presets are used.
248
+ *
249
+ * An OBJECT keeps auto-detection and turns individual presets off by name —
250
+ * `{ navigation: false }` — which is what you want when one preset gets in the
251
+ * way. Listing every other detected preset back by hand just to drop one is
252
+ * both tedious and a thing that silently rots as dependencies change.
250
253
  *
251
254
  * Only built-in presets are supported (reanimated, gestureHandler,
252
255
  * safeAreaContext, navigation, asyncStorage, screens, expo). For custom
@@ -258,7 +261,7 @@ interface VitestNativeOptions {
258
261
  * reactNative({ presets: [presets.reanimated(), presets.navigation()] })
259
262
  * ```
260
263
  */
261
- presets?: Preset[];
264
+ presets?: Preset[] | Record<string, boolean>;
262
265
  /**
263
266
  * `engine: 'mock'` only. Plain-data overrides merged into the react-native
264
267
  * module mock.
@@ -303,7 +306,12 @@ interface VitestNativeOptions {
303
306
  * is enforced between Vitest scheduler tasks; a single task containing
304
307
  * multiple files cannot be interrupted.
305
308
  * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets
306
- * or exceeds this value, also between scheduler tasks.
309
+ * or exceeds this value, also between scheduler tasks. When hot is enabled
310
+ * and you set neither `memoryLimit` nor `recycleAfterFiles`, a default
311
+ * per-worker bound of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is applied so
312
+ * memory stays bounded out of the box (multi-worker runs recycle a worker
313
+ * once it crosses the ceiling). Single-worker hot can't recycle, so the
314
+ * bound is inert there — run with `maxWorkers >= 2` for bounded hot memory.
307
315
  * - `preserveGlobals`: exact globalThis property names intentionally owned
308
316
  * by resident external libraries. App/test globals are otherwise removed
309
317
  * between files. Storybook's preview registry is preserved automatically.
@@ -361,8 +369,11 @@ declare function bottomSheet(): Preset;
361
369
  //#endregion
362
370
  //#region src/presets/keyboard-controller.d.ts
363
371
  declare function keyboardController(): Preset;
372
+ //#endregion
373
+ //#region src/presets/worklets.d.ts
374
+ declare function worklets(): Preset;
364
375
  declare namespace index_d_exports {
365
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview };
376
+ export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
366
377
  }
367
378
  //#endregion
368
- export { Preset as _, vectorIcons as a, mmkv as c, screens as d, asyncStorage as f, reanimated as g, gestureHandler as h, flashList as i, deviceInfo as l, safeAreaContext as m, keyboardController as n, webview as o, navigation as p, bottomSheet as r, svg as s, index_d_exports as t, expo as u, ReactNativeMock as v, VitestNativeOptions as y };
379
+ export { reanimated as _, flashList as a, VitestNativeOptions as b, svg as c, expo as d, screens as f, gestureHandler as g, safeAreaContext as h, bottomSheet as i, mmkv as l, navigation as m, worklets as n, vectorIcons as o, asyncStorage as p, keyboardController as r, webview as s, index_d_exports as t, deviceInfo as u, Preset as v, ReactNativeMock as y };
package/dist/index.d.mts CHANGED
@@ -1,14 +1,16 @@
1
- import { _ as Preset, t as index_d_exports, v as ReactNativeMock, y as VitestNativeOptions } from "./index-vlK4zxuK.mjs";
1
+ import { b as VitestNativeOptions, t as index_d_exports, v as Preset, y as ReactNativeMock } from "./index-CvCU0cLl.mjs";
2
2
  import { Plugin } from "vite";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  /**
6
- * Vitest plugin for React Native.
6
+ * Preset names switched off by the object form of the `presets` option.
7
7
  *
8
- * Handles platform-specific module resolution, asset stubs, preset virtual
9
- * modules, and automatic setup-file injection so tests can run against
10
- * React Native code in a Node/JSDOM environment.
8
+ * The array form replaces auto-detection wholesale, which meant that turning ONE
9
+ * preset off required listing every other detected preset by hand — tedious, and a
10
+ * list that silently rots as dependencies change. The object form keeps detection
11
+ * and names only what to drop.
11
12
  */
13
+ declare function disabledPresetNames(presets: unknown): Set<string>;
12
14
  declare function reactNative(options?: VitestNativeOptions): Plugin;
13
15
  //#endregion
14
- export { type Preset, type ReactNativeMock, type VitestNativeOptions, index_d_exports as presets, reactNative };
16
+ export { type Preset, type ReactNativeMock, type VitestNativeOptions, disabledPresetNames, index_d_exports as presets, reactNative };