vitest-native 0.13.0 → 0.14.0-rc.2

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 (77) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/README.md +138 -48
  3. package/dist/cli.cjs +70 -5
  4. package/dist/cli.d.cts +2 -3
  5. package/dist/cli.d.mts +2 -3
  6. package/dist/cli.mjs +70 -5
  7. package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
  8. package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
  9. package/dist/errors.d.mts +12 -0
  10. package/dist/helpers.cjs +6 -3
  11. package/dist/helpers.d.cts +8 -9
  12. package/dist/helpers.d.mts +8 -9
  13. package/dist/helpers.mjs +6 -3
  14. package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
  15. package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
  16. package/dist/index.d.mts +4 -4
  17. package/dist/index.mjs +537 -118
  18. package/dist/jest-compat/aliases.d.mts +5 -0
  19. package/dist/jest-compat/aliases.mjs +65 -0
  20. package/dist/jest-compat/caller.mjs +53 -0
  21. package/dist/jest-compat/setup.mjs +72 -36
  22. package/dist/jest-compat.cjs +1 -3
  23. package/dist/jest-compat.d.cts +4 -5
  24. package/dist/jest-compat.d.mts +4 -5
  25. package/dist/jest-compat.mjs +1 -1
  26. package/dist/matchers.d.cts +9 -9
  27. package/dist/matchers.d.mts +9 -9
  28. package/dist/memory-6EPHrJA1.cjs +144 -0
  29. package/dist/memory-FYbP0_gg.mjs +126 -0
  30. package/dist/native/boundary.mjs +13 -2
  31. package/dist/native/bounded-process.mjs +165 -0
  32. package/dist/native/export-condition-recovery-preload.mjs +5 -0
  33. package/dist/native/export-condition-recovery.mjs +195 -0
  34. package/dist/native/globals.mjs +133 -5
  35. package/dist/native/hooks.mjs +131 -71
  36. package/dist/native/loader.mjs +41 -28
  37. package/dist/native/match.d.mts +3 -0
  38. package/dist/native/match.mjs +38 -2
  39. package/dist/native/metro-profile-compiler.mjs +234 -0
  40. package/dist/native/metro-profile.mjs +115 -0
  41. package/dist/native/module-reset.mjs +111 -6
  42. package/dist/native/ownership.d.mts +105 -0
  43. package/dist/native/ownership.mjs +474 -0
  44. package/dist/native/registry-compiler.mjs +43 -0
  45. package/dist/native/registry-process.mjs +124 -0
  46. package/dist/native/registry.mjs +139 -32
  47. package/dist/native/reset.mjs +305 -135
  48. package/dist/native/resolve.d.mts +20 -3
  49. package/dist/native/resolve.mjs +32 -12
  50. package/dist/native/rntl-hooks.mjs +76 -0
  51. package/dist/native/setup.mjs +81 -32
  52. package/dist/native/state-manifest.d.mts +22 -0
  53. package/dist/native/state-manifest.mjs +136 -0
  54. package/dist/native/transform.mjs +29 -8
  55. package/dist/native/worker.mjs +52 -4
  56. package/dist/pool-B4yesGhI.cjs +121 -0
  57. package/dist/pool-DjpOjOf3.mjs +119 -0
  58. package/dist/{presets-CoNf4ByH.cjs → presets-BYHmi7-W.cjs} +117 -18
  59. package/dist/{presets-DGProTaA.mjs → presets-DC-eM5IA.mjs} +117 -18
  60. package/dist/presets.d.mts +1 -1
  61. package/dist/presets.mjs +1 -1
  62. package/dist/rntl-matchers.d.ts +58 -12
  63. package/dist/serializer.cjs +4 -2
  64. package/dist/serializer.d.cts +3 -4
  65. package/dist/serializer.d.mts +3 -4
  66. package/dist/serializer.mjs +4 -2
  67. package/dist/setup.mjs +61 -50
  68. package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
  69. package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
  70. package/docs/hot-default-design.md +175 -88
  71. package/docs/migrating-from-jest.md +12 -5
  72. package/docs/migrating-from-vitest-react-native.md +4 -4
  73. package/docs/release-readiness.md +39 -13
  74. package/docs/versioning.md +19 -18
  75. package/package.json +42 -31
  76. package/dist/pool-BU-1ecIF.cjs +0 -122
  77. package/dist/pool-Bcxn9a3I.mjs +0 -118
package/dist/helpers.mjs CHANGED
@@ -148,9 +148,12 @@ function resetAllMocks() {
148
148
  originalNativeModules = null;
149
149
  }
150
150
  const presetMocks = globalThis.__vitest_native_preset_mocks;
151
- if (presetMocks) for (const mod of Object.values(presetMocks)) {
152
- if (mod?._reset) mod._reset();
153
- if (mod?._resetStore) mod._resetStore();
151
+ if (presetMocks) {
152
+ const built = presetMocks[Symbol.for("vitest-native.presets-built")];
153
+ for (const mod of built ? [...built.values()] : Object.values(presetMocks)) {
154
+ if (mod?._reset) mod._reset();
155
+ if (mod?._resetStore) mod._resetStore();
156
+ }
154
157
  }
155
158
  }
156
159
  //#endregion
@@ -279,6 +279,19 @@ interface VitestNativeOptions {
279
279
  diagnostics?: boolean;
280
280
  /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
281
281
  assetExts?: string[];
282
+ /**
283
+ * Experimental. Read the project's declarative Metro resolution profile in a
284
+ * short-lived, memory-bounded child. Default: false (built-in React Native
285
+ * extension/asset defaults). Pass true or an options object to opt in.
286
+ *
287
+ * Imperative `resolver.resolveRequest` behavior cannot be transferred as data:
288
+ * when the config installs one, the source and asset extensions still apply and
289
+ * a warning names the gap. Main fields and conditions are reported under
290
+ * diagnostics but retain the engine's ownership policy.
291
+ */
292
+ metroConfig?: boolean | {
293
+ configFile?: string;
294
+ };
282
295
  /**
283
296
  * `engine: 'native'` only. Names of additional node_modules packages whose
284
297
  * source the native engine should transform (Flow/TS/JSX stripped) as it
@@ -319,7 +332,8 @@ interface VitestNativeOptions {
319
332
  exclude?: string[];
320
333
  };
321
334
  /**
322
- * `engine: 'native'` only. **Experimental.** Run tests in persistent
335
+ * `engine: 'native'` only. Built on Vitest's experimental custom-pool API.
336
+ * Run tests in persistent
323
337
  * RN-hot workers: React Native's module graph loads once per worker and
324
338
  * stays resident across test files, while each file still gets a fresh
325
339
  * Vitest module runner (per-file isolation of your app/test modules).
@@ -331,12 +345,14 @@ interface VitestNativeOptions {
331
345
  * is enforced between Vitest scheduler tasks; a single task containing
332
346
  * multiple files cannot be interrupted.
333
347
  * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets
334
- * or exceeds this value, also between scheduler tasks. When hot is enabled
335
- * and you set neither `memoryLimit` nor `recycleAfterFiles`, a default
336
- * per-worker bound of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is applied so
337
- * memory stays bounded out of the box (multi-worker runs recycle a worker
338
- * once it crosses the ceiling). Single-worker hot can't recycle, so the
339
- * bound is inert there — run with `maxWorkers >= 2` for bounded hot memory.
348
+ * or exceeds this value, also between scheduler tasks. By default a
349
+ * constrained-memory-aware plan derives this threshold, caps automatic
350
+ * concurrency at four, reserves main-process and worker-replacement RSS,
351
+ * and stops before crossing 90% of the host/container limit.
352
+ * - `allowUnboundedMemory`: explicitly permit configurations where Vitest
353
+ * cannot enforce file-boundary recycling, notably `maxWorkers: 1`. This
354
+ * also disables the automatic worker cap and process-RSS hard stop. Use
355
+ * only when an external scheduler provides the memory boundary.
340
356
  * - `preserveGlobals`: exact globalThis property names intentionally owned
341
357
  * by resident external libraries. App/test globals are otherwise removed
342
358
  * between files. Storybook's preview registry is preserved automatically.
@@ -350,11 +366,19 @@ interface VitestNativeOptions {
350
366
  * stock isolation, against 13.9x with it off. Set false to trade that back,
351
367
  * accepting that a package holding state across files will keep it.
352
368
  *
353
- * Default: false (each file runs in a fresh worker; RN reloads per file).
369
+ * `'auto'` selects the bounded hot runtime when the configuration has recyclable
370
+ * task boundaries (enough memory headroom for at least two workers) and no
371
+ * explicit custom pool; otherwise the run keeps per-file isolation. Set
372
+ * explicitly, it prints the reason for falling back; as the default it falls
373
+ * back quietly (`diagnostics: true` shows the reason).
374
+ *
375
+ * Default: `'auto'`. `false` always runs each file in a fresh worker, with React
376
+ * Native reloaded per file.
354
377
  */
355
- hotRuntime?: boolean | {
378
+ hotRuntime?: boolean | "auto" | {
356
379
  recycleAfterFiles?: number;
357
380
  memoryLimit?: number;
381
+ allowUnboundedMemory?: boolean;
358
382
  preserveGlobals?: string[];
359
383
  esmGeneration?: boolean;
360
384
  };
@@ -278,6 +278,19 @@ interface VitestNativeOptions {
278
278
  diagnostics?: boolean;
279
279
  /** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
280
280
  assetExts?: string[];
281
+ /**
282
+ * Experimental. Read the project's declarative Metro resolution profile in a
283
+ * short-lived, memory-bounded child. Default: false (built-in React Native
284
+ * extension/asset defaults). Pass true or an options object to opt in.
285
+ *
286
+ * Imperative `resolver.resolveRequest` behavior cannot be transferred as data:
287
+ * when the config installs one, the source and asset extensions still apply and
288
+ * a warning names the gap. Main fields and conditions are reported under
289
+ * diagnostics but retain the engine's ownership policy.
290
+ */
291
+ metroConfig?: boolean | {
292
+ configFile?: string;
293
+ };
281
294
  /**
282
295
  * `engine: 'native'` only. Names of additional node_modules packages whose
283
296
  * source the native engine should transform (Flow/TS/JSX stripped) as it
@@ -318,7 +331,8 @@ interface VitestNativeOptions {
318
331
  exclude?: string[];
319
332
  };
320
333
  /**
321
- * `engine: 'native'` only. **Experimental.** Run tests in persistent
334
+ * `engine: 'native'` only. Built on Vitest's experimental custom-pool API.
335
+ * Run tests in persistent
322
336
  * RN-hot workers: React Native's module graph loads once per worker and
323
337
  * stays resident across test files, while each file still gets a fresh
324
338
  * Vitest module runner (per-file isolation of your app/test modules).
@@ -330,12 +344,14 @@ interface VitestNativeOptions {
330
344
  * is enforced between Vitest scheduler tasks; a single task containing
331
345
  * multiple files cannot be interrupted.
332
346
  * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets
333
- * or exceeds this value, also between scheduler tasks. When hot is enabled
334
- * and you set neither `memoryLimit` nor `recycleAfterFiles`, a default
335
- * per-worker bound of `clamp(totalmem * 0.25, 768MB, 1.5GB)` is applied so
336
- * memory stays bounded out of the box (multi-worker runs recycle a worker
337
- * once it crosses the ceiling). Single-worker hot can't recycle, so the
338
- * bound is inert there — run with `maxWorkers >= 2` for bounded hot memory.
347
+ * or exceeds this value, also between scheduler tasks. By default a
348
+ * constrained-memory-aware plan derives this threshold, caps automatic
349
+ * concurrency at four, reserves main-process and worker-replacement RSS,
350
+ * and stops before crossing 90% of the host/container limit.
351
+ * - `allowUnboundedMemory`: explicitly permit configurations where Vitest
352
+ * cannot enforce file-boundary recycling, notably `maxWorkers: 1`. This
353
+ * also disables the automatic worker cap and process-RSS hard stop. Use
354
+ * only when an external scheduler provides the memory boundary.
339
355
  * - `preserveGlobals`: exact globalThis property names intentionally owned
340
356
  * by resident external libraries. App/test globals are otherwise removed
341
357
  * between files. Storybook's preview registry is preserved automatically.
@@ -349,11 +365,19 @@ interface VitestNativeOptions {
349
365
  * stock isolation, against 13.9x with it off. Set false to trade that back,
350
366
  * accepting that a package holding state across files will keep it.
351
367
  *
352
- * Default: false (each file runs in a fresh worker; RN reloads per file).
368
+ * `'auto'` selects the bounded hot runtime when the configuration has recyclable
369
+ * task boundaries (enough memory headroom for at least two workers) and no
370
+ * explicit custom pool; otherwise the run keeps per-file isolation. Set
371
+ * explicitly, it prints the reason for falling back; as the default it falls
372
+ * back quietly (`diagnostics: true` shows the reason).
373
+ *
374
+ * Default: `'auto'`. `false` always runs each file in a fresh worker, with React
375
+ * Native reloaded per file.
353
376
  */
354
- hotRuntime?: boolean | {
377
+ hotRuntime?: boolean | "auto" | {
355
378
  recycleAfterFiles?: number;
356
379
  memoryLimit?: number;
380
+ allowUnboundedMemory?: boolean;
357
381
  preserveGlobals?: string[];
358
382
  esmGeneration?: boolean;
359
383
  };
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-CmETArCM.mjs";
1
+ import { b as ReactNativeMock, t as index_d_exports, x as VitestNativeOptions, y as Preset } from "./index-CEbwa4QU.mjs";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/plugin.d.ts
4
4
  /**
@@ -9,7 +9,7 @@ import { Plugin } from "vite";
9
9
  * list that silently rots as dependencies change. The object form keeps detection
10
10
  * and names only what to drop.
11
11
  */
12
- declare function disabledPresetNames(presets: unknown): Set<string>;
13
- declare function reactNative(options?: VitestNativeOptions): Plugin;
12
+ export declare function disabledPresetNames(presets: unknown): Set<string>;
13
+ export declare function reactNative(options?: VitestNativeOptions): Plugin;
14
14
  //#endregion
15
- export { type Preset, type ReactNativeMock, type VitestNativeOptions, disabledPresetNames, index_d_exports as presets, reactNative };
15
+ export { type Preset, type ReactNativeMock, type VitestNativeOptions, index_d_exports as presets };