vitest-native 0.14.1 → 0.15.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 (89) hide show
  1. package/README.md +11 -10
  2. package/dist/cli.d.mts +9 -1
  3. package/dist/cli.mjs +2609 -361
  4. package/dist/context.d.mts +19 -0
  5. package/dist/context.mjs +47 -1
  6. package/dist/docs-url.d.mts +4 -0
  7. package/dist/docs-url.mjs +9 -0
  8. package/dist/errors.d.mts +21 -1
  9. package/dist/hang-watch-setup.mjs +55 -0
  10. package/dist/hang-watch.d.mts +56 -0
  11. package/dist/hang-watch.mjs +343 -0
  12. package/dist/helpers.cjs +24 -53
  13. package/dist/helpers.mjs +22 -1
  14. package/dist/host-D0r3P_T1.mjs +1985 -0
  15. package/dist/{index-aNBCTfA5.d.mts → index-JOR602XU.d.mts} +105 -2
  16. package/dist/index.d.mts +2 -1
  17. package/dist/index.mjs +723 -149
  18. package/dist/jest-compat/aliases.d.mts +1 -0
  19. package/dist/jest-compat/aliases.mjs +11 -0
  20. package/dist/jest-compat/interop.mjs +1 -1
  21. package/dist/jest-compat/jest-object.mjs +23 -5
  22. package/dist/jest-compat/node-registry.mjs +836 -68
  23. package/dist/jest-compat/setup.mjs +205 -12
  24. package/dist/jest-compat.cjs +383 -47
  25. package/dist/jest-compat.d.cts +19 -2
  26. package/dist/jest-compat.d.mts +19 -2
  27. package/dist/jest-compat.mjs +232 -47
  28. package/dist/matchers.d.cts +0 -1
  29. package/dist/matchers.d.mts +0 -1
  30. package/dist/native/assets.mjs +3 -1
  31. package/dist/native/babel-caller.d.mts +13 -0
  32. package/dist/native/babel-caller.mjs +24 -0
  33. package/dist/native/babel-toolchain.mjs +27 -3
  34. package/dist/native/boundary.mjs +45 -8
  35. package/dist/native/bounded-process.mjs +63 -5
  36. package/dist/native/bridge-client.mjs +133 -0
  37. package/dist/native/bridge-server.mjs +215 -0
  38. package/dist/native/bridge-thread.mjs +79 -0
  39. package/dist/native/bridge.mjs +512 -0
  40. package/dist/native/compile-error.mjs +120 -0
  41. package/dist/native/explain.mjs +3 -2
  42. package/dist/native/expo-module-mocks.mjs +2 -0
  43. package/dist/native/export-condition-recovery.mjs +20 -99
  44. package/dist/native/hooks.mjs +256 -133
  45. package/dist/native/jest-resolvers.mjs +94 -0
  46. package/dist/native/library-jest.mjs +352 -0
  47. package/dist/native/loader.mjs +167 -73
  48. package/dist/native/match.mjs +67 -7
  49. package/dist/native/module-reset.mjs +44 -49
  50. package/dist/native/ownership-ledger.d.mts +87 -0
  51. package/dist/native/ownership-ledger.mjs +524 -0
  52. package/dist/native/ownership.d.mts +20 -0
  53. package/dist/native/ownership.mjs +114 -0
  54. package/dist/native/registry-compiler.mjs +39 -5
  55. package/dist/native/registry-process.mjs +327 -28
  56. package/dist/native/registry.mjs +752 -200
  57. package/dist/native/resident-health.mjs +1 -0
  58. package/dist/native/resolve.d.mts +7 -0
  59. package/dist/native/resolve.mjs +119 -4
  60. package/dist/native/rntl-hooks.mjs +9 -5
  61. package/dist/native/rntl-text-host.mjs +5 -15
  62. package/dist/native/root-spelling.d.mts +6 -0
  63. package/dist/native/root-spelling.mjs +77 -0
  64. package/dist/native/runner.mjs +2 -19
  65. package/dist/native/setup.mjs +119 -38
  66. package/dist/native/shared-resolver.d.mts +141 -0
  67. package/dist/native/shared-resolver.mjs +719 -0
  68. package/dist/native/test-runner.mjs +26 -0
  69. package/dist/native/transform.mjs +18 -22
  70. package/dist/native/worker.mjs +9 -4
  71. package/dist/node-dispatch.mjs +293 -0
  72. package/dist/{preset-map-CogjYmSw.mjs → preset-map-DdAexIwz.mjs} +113 -2
  73. package/dist/{presets-CXDyg51l.mjs → presets-_EaSw29m.mjs} +710 -130
  74. package/dist/presets.d.mts +1 -1
  75. package/dist/presets.mjs +1 -1
  76. package/dist/rntl-matchers.d.ts +11 -15
  77. package/dist/rntl-support.mjs +28 -13
  78. package/dist/root-mocks-BNXeosbR.mjs +155 -0
  79. package/dist/serializer.cjs +7 -5
  80. package/dist/serializer.d.cts +7 -5
  81. package/dist/serializer.d.mts +7 -5
  82. package/dist/serializer.mjs +7 -5
  83. package/dist/setup.mjs +26 -27
  84. package/docs/migrating-from-jest.md +9 -232
  85. package/docs/migrating-from-vitest-react-native.md +4 -4
  86. package/docs/release-readiness.md +9 -11
  87. package/docs/versioning.md +38 -9
  88. package/package.json +59 -33
  89. package/dist/host-BAAAlSkO.mjs +0 -1028
@@ -201,12 +201,13 @@ interface PresetModule {
201
201
  /**
202
202
  * Named exports read from the installed package, for a package whose API changes
203
203
  * between releases; replaces `exports` when present. Called once at Vite config time
204
- * with the project root and platform. `null` means the package is not installed, so
205
- * the module is not shadowed at all.
204
+ * with the project root, platform and engine. `null` means the package is not
205
+ * installed, so the module is not shadowed at all.
206
206
  */
207
207
  exportsFor?: (context: {
208
208
  projectRoot: string;
209
209
  platform: "ios" | "android";
210
+ engine: "mock" | "native";
210
211
  }) => string[] | null;
211
212
  }
212
213
  interface Preset {
@@ -303,6 +304,24 @@ interface VitestNativeOptions {
303
304
  mocks?: Record<string, any>;
304
305
  /** Log plugin activity. Default: false */
305
306
  diagnostics?: boolean;
307
+ /**
308
+ * Compile project source with the project's own Babel config where it needs a
309
+ * plugin or option that Vite's Oxc transform does not cover (legacy decorators,
310
+ * macros, a custom plugin), as Metro and babel-jest do. Packages in node_modules
311
+ * are not affected.
312
+ *
313
+ * - `'auto'` (default): a project file compiles with Babel only when the config
314
+ * Babel loads for it has a plugin, preset or option outside what Oxc and the
315
+ * engine already cover; an unknown plugin counts as outside. Every other file
316
+ * keeps Oxc. The plugins that caused it are named once at startup.
317
+ * - `'always'`: every project file the config applies to compiles with Babel, as
318
+ * under babel-jest.
319
+ * - `'never'`: project source compiles with Oxc only.
320
+ *
321
+ * A Babel plugin already in the Vite config (such as `@rolldown/plugin-babel`)
322
+ * compiles that source itself, and this steps aside for it.
323
+ */
324
+ projectBabel?: "auto" | "always" | "never";
306
325
  /** Additional asset file extensions, loaded as Metro loads assets (e.g. ['.lottie', '.m4b']) */
307
326
  assetExts?: string[];
308
327
  /**
@@ -359,6 +378,39 @@ interface VitestNativeOptions {
359
378
  include?: string[];
360
379
  exclude?: string[];
361
380
  };
381
+ /**
382
+ * `engine: 'native'` only. Behaviour changes that are not the default yet. Each is
383
+ * decided (made the default, or removed) by the date in `src/flags.ts`.
384
+ */
385
+ experimental?: {
386
+ /**
387
+ * `engine: 'native'` only. A `vi.mock` applies to the modules Node loads too, as a
388
+ * `jest.mock` does under Jest: an installed package's own `require` or `import` of
389
+ * the mocked module gets the test's mocked module, the same instance (#322). That
390
+ * holds for a factory, an automock, `{ spy: true }` and a `__mocks__` file. What
391
+ * Node cannot be served fails by name, `MOCK_NOT_SEEN_BY_NODE`, instead of loading
392
+ * the real module: an async factory that has not settled, an automock or `__mocks__`
393
+ * file the test has not imported yet, a `vi.doMock` or `vi.doUnmock` not applied
394
+ * yet, and a package Vite and Node resolve to different files. A module Node
395
+ * already loaded keeps what it required, as under Jest without
396
+ * `jest.resetModules()`, and an ES module reads each export of the mock once, when
397
+ * it loads (a getter on a factory's result is not a live binding there). Default:
398
+ * `false`, and on with `ownershipModel: 'resolution'`, which refuses it set to
399
+ * `false`.
400
+ */
401
+ nodeMocks?: boolean;
402
+ /**
403
+ * `'resolver'`: Vite, Node's CommonJS loader and its ESM loader resolve every bare
404
+ * request through one shared resolver, from one set of inputs, so a package loaded
405
+ * by both module systems is one module. Where a package's `exports` map has both
406
+ * `import` and `require` builds, both sides load the `require` one. Native engine
407
+ * only. `'resolution'` adds the bridge: Node's \`require\` of a file Vite owns gets
408
+ * Vite's own instance, evaluated then if Vite has not yet, so the order a test loads
409
+ * files in cannot split a module. `'resolution'` turns `nodeMocks` on: a mocked module
410
+ * the bridge or Node reaches is the test's mock. See https://danfry1.github.io/vitest-native/guide/plugin-options#experimental.
411
+ */
412
+ ownershipModel?: "resolver" | "resolution";
413
+ };
362
414
  /**
363
415
  * `engine: 'native'` only. Built on Vitest's experimental custom-pool API.
364
416
  * Run tests in persistent
@@ -436,6 +488,57 @@ interface VitestNativeOptions {
436
488
  * Default: `'device'`.
437
489
  */
438
490
  nativeModules?: "device" | "permissive";
491
+ /**
492
+ * `engine: 'native'` only. What a run does when React Native's precompiled registry
493
+ * is not in the cache yet (first install, an upgrade of React Native or
494
+ * vitest-native, a Babel toolchain change, a cleared cache).
495
+ *
496
+ * - `'background'` *(default)*: the run starts at once and the registry compiles in
497
+ * a low-priority background process. Test files that start before it is ready
498
+ * load React Native file by file; files that start after use it. When Vitest
499
+ * closes, a build still running gets up to half of `teardownTimeout` to finish,
500
+ * so the next run starts warm.
501
+ * - `'wait'`: compile the registry before the run starts, as in earlier versions.
502
+ *
503
+ * The hot runtime, CI runs and `experimental.ownershipModel` always wait.
504
+ */
505
+ registryBuild?: "background" | "wait";
506
+ /**
507
+ * Fail the run when no test makes progress for this many milliseconds, naming the files
508
+ * and tests that were running. Default: 60 000, or twice the larger of `testTimeout` and
509
+ * `hookTimeout` if that is longer. `false` turns it off. Off while a debugger is attached.
510
+ *
511
+ * Vitest's `testTimeout` runs on the test's own worker, so a test stuck in synchronous
512
+ * code (a loop that never ends) never reaches it, and the run waits forever with nothing
513
+ * on screen. This watch runs in Vitest's main process, which stays responsive, so it can
514
+ * still say where the run stopped.
515
+ */
516
+ hangTimeout?: number | false;
517
+ /**
518
+ * `engine: 'native'` only. What happens when one file is evaluated by both Node and
519
+ * Vite in a worker. Such a file exists twice, and module state written through one
520
+ * copy is not seen by the other; nothing else reports it.
521
+ *
522
+ * - `'warn'`: report each such file once per worker, naming both sides, the route
523
+ * and the fix.
524
+ * - `'error'`: throw `SOURCE_EVALUATED_TWICE` at the second evaluation and fail the
525
+ * test file. A second Node copy never runs; a second Vite copy has run its top level
526
+ * when it is seen, and its import throws.
527
+ *
528
+ * The object form adds `allow`, the only exemption: a file or directory (resolved
529
+ * against the Vitest root) and the reason it is deliberate. Detection cannot be turned
530
+ * off.
531
+ *
532
+ * Default: `'warn'`.
533
+ * See https://danfry1.github.io/vitest-native/guide/errors#SOURCE_EVALUATED_TWICE.
534
+ */
535
+ ownership?: "warn" | "error" | {
536
+ mode?: "warn" | "error";
537
+ allow?: {
538
+ path: string;
539
+ reason: string;
540
+ }[];
541
+ };
439
542
  }
440
543
  declare function reanimated(): Preset;
441
544
  declare function gestureHandler(): Preset;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-aNBCTfA5.mjs";
1
+ import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-JOR602XU.mjs";
2
2
  import { Plugin } from "vite";
3
+ import "./context.mjs";
3
4
  /**
4
5
  * Preset names switched off by the object form of the `presets` option.
5
6
  *