vitest-native 0.14.0-rc.9 → 0.14.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 (97) hide show
  1. package/README.md +76 -60
  2. package/dist/cli.d.mts +1 -3
  3. package/dist/cli.mjs +175 -63
  4. package/dist/context.d.mts +45 -0
  5. package/dist/context.mjs +243 -0
  6. package/dist/errors.d.mts +3 -0
  7. package/dist/helpers.cjs +53 -4
  8. package/dist/helpers.d.cts +1 -3
  9. package/dist/helpers.d.mts +1 -3
  10. package/dist/helpers.mjs +2 -3
  11. package/dist/host-5o48Ujzs.mjs +939 -0
  12. package/dist/{index-CzQazgp9.d.cts → index-DqU4YO3D.d.mts} +27 -49
  13. package/dist/index.d.mts +1 -3
  14. package/dist/index.mjs +463 -595
  15. package/dist/jest-compat/error-equality.mjs +127 -0
  16. package/dist/jest-compat/jest-object.mjs +149 -4
  17. package/dist/jest-compat/node-registry.mjs +233 -58
  18. package/dist/jest-compat/setup.mjs +28 -4
  19. package/dist/jest-compat.cjs +227 -52
  20. package/dist/jest-compat.d.cts +5 -6
  21. package/dist/jest-compat.d.mts +5 -6
  22. package/dist/jest-compat.mjs +204 -52
  23. package/dist/matchers.cjs +1 -2
  24. package/dist/matchers.d.cts +0 -2
  25. package/dist/matchers.d.mts +0 -2
  26. package/dist/matchers.mjs +1 -2
  27. package/dist/{memory-FYbP0_gg.mjs → memory-Couw0Esx.mjs} +31 -6
  28. package/dist/native/assets.d.mts +2 -0
  29. package/dist/native/assets.mjs +34 -0
  30. package/dist/native/babel-toolchain.mjs +190 -0
  31. package/dist/native/babel-worker.mjs +47 -0
  32. package/dist/native/boundary.mjs +23 -8
  33. package/dist/native/compile-cache.mjs +21 -9
  34. package/dist/native/coverage-v8.mjs +287 -0
  35. package/dist/native/esm-interop.mjs +216 -0
  36. package/dist/native/expo-native-modules.mjs +7 -1
  37. package/dist/native/globals.mjs +104 -6
  38. package/dist/native/hooks.mjs +271 -60
  39. package/dist/native/loader.mjs +378 -20
  40. package/dist/native/match.d.mts +24 -2
  41. package/dist/native/match.mjs +117 -12
  42. package/dist/native/metro-profile-compiler.mjs +2 -31
  43. package/dist/native/module-reset.mjs +37 -5
  44. package/dist/native/native-modules.d.mts +2 -3
  45. package/dist/native/native-modules.mjs +22 -21
  46. package/dist/native/ownership.d.mts +10 -0
  47. package/dist/native/ownership.mjs +96 -9
  48. package/dist/native/registry-compiler.mjs +6 -0
  49. package/dist/native/registry.mjs +138 -119
  50. package/dist/native/resident-health.mjs +133 -0
  51. package/dist/native/resolve.d.mts +6 -0
  52. package/dist/native/resolve.mjs +100 -9
  53. package/dist/native/rntl-hooks.mjs +157 -6
  54. package/dist/native/rntl-text-host.mjs +64 -0
  55. package/dist/native/runner.mjs +73 -0
  56. package/dist/native/setup.mjs +96 -70
  57. package/dist/native/state-manifest.mjs +14 -8
  58. package/dist/native/transform.d.mts +2 -0
  59. package/dist/native/transform.mjs +476 -59
  60. package/dist/native/worker.mjs +65 -36
  61. package/dist/{pool-DjpOjOf3.mjs → pool-CFSpNfyw.mjs} +37 -11
  62. package/dist/{preset-map-BlBriTA0.mjs → preset-map-CogjYmSw.mjs} +4 -19
  63. package/dist/preset-modules.mjs +2 -11
  64. package/dist/{presets--zrEWQC2.mjs → presets-CXDyg51l.mjs} +65 -82
  65. package/dist/presets.d.mts +1 -1
  66. package/dist/presets.mjs +1 -1
  67. package/dist/report-error.d.mts +20 -0
  68. package/dist/report-error.mjs +145 -0
  69. package/dist/rntl-support.d.mts +12 -0
  70. package/dist/rntl-support.mjs +189 -0
  71. package/dist/{rolldown-runtime-BhDjJH2R.mjs → rolldown-runtime-D70C1uOS.mjs} +1 -2
  72. package/dist/serializer.cjs +1 -2
  73. package/dist/serializer.d.cts +1 -3
  74. package/dist/serializer.d.mts +1 -3
  75. package/dist/serializer.mjs +1 -2
  76. package/dist/setup.mjs +95 -156
  77. package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-CILPFeRX.mjs} +2 -3
  78. package/docs/migrating-from-jest.md +76 -12
  79. package/docs/release-readiness.md +1 -1
  80. package/package.json +119 -102
  81. package/CHANGELOG.md +0 -2491
  82. package/dist/cli.cjs +0 -1951
  83. package/dist/cli.d.cts +0 -3
  84. package/dist/ecosystem-D6e1OVOg.mjs +0 -1019
  85. package/dist/ecosystem-MFwkbnaC.cjs +0 -1099
  86. package/dist/errors-B3lJK46O.cjs +0 -75
  87. package/dist/errors-CxoBUfVJ.mjs +0 -64
  88. package/dist/index-xw43lBlv.d.mts +0 -481
  89. package/dist/memory-6EPHrJA1.cjs +0 -144
  90. package/dist/pool-B4yesGhI.cjs +0 -121
  91. package/dist/preset-map-jSFsNy1Q.cjs +0 -241
  92. package/dist/preset-modules-BoLkaeEN.cjs +0 -53
  93. package/dist/preset-modules-CG8-G82P.mjs +0 -36
  94. package/dist/presets-9f83H0WW.cjs +0 -3939
  95. package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
  96. package/dist/worker-vitest-BfiQB8ND.cjs +0 -62
  97. package/docs/hot-default-design.md +0 -216
@@ -1,43 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
- return target;
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
- key = keys[i];
20
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
- get: ((k) => from[k]).bind(null, key),
22
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
- });
24
- }
25
- return to;
26
- };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- //#endregion
32
- Object.defineProperty(exports, "__exportAll", {
33
- enumerable: true,
34
- get: function() {
35
- return __exportAll;
36
- }
37
- });
38
- Object.defineProperty(exports, "__toESM", {
39
- enumerable: true,
40
- get: function() {
41
- return __toESM;
42
- }
43
- });
@@ -1,62 +0,0 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- const require_errors = require("./errors-B3lJK46O.cjs");
3
- let node_path = require("node:path");
4
- node_path = require_rolldown_runtime.__toESM(node_path, 1);
5
- let node_module = require("node:module");
6
- //#region src/native/worker-vitest.ts
7
- /**
8
- * Fail fast when the hot worker would load a different Vitest VERSION from the
9
- * project's.
10
- *
11
- * The worker entry ships inside this package, so its `import 'vitest/worker'`
12
- * resolves from THIS package's location rather than the project's. Where a monorepo
13
- * has more than one Vitest install — a linked package, a hoisted `node_modules`,
14
- * mixed versions across workspaces — the two can differ, and a version difference is
15
- * invisible at runtime: the start handshake succeeds, the run request is accepted,
16
- * and no result is ever reported. Vitest then prints "No test files found" with no
17
- * error at all, and on some paths still exits 0 — a green run that tested nothing.
18
- *
19
- * Only a VERSION difference is an error. Two installs of the same version are two
20
- * module registries but identical code, and they talk to each other perfectly well;
21
- * failing on the paths alone would block working monorepos where the same version is
22
- * simply installed twice.
23
- */
24
- function workerVitestMismatch(workerEntry, projectRoot) {
25
- const resolveVitest = (from) => {
26
- try {
27
- const require_ = (0, node_module.createRequire)(from);
28
- const pkgPath = require_.resolve("vitest/package.json");
29
- return {
30
- path: pkgPath,
31
- version: require_(pkgPath).version
32
- };
33
- } catch {
34
- return null;
35
- }
36
- };
37
- const worker = resolveVitest(workerEntry);
38
- const project = resolveVitest(node_path.default.join(projectRoot, "package.json"));
39
- if (worker === null || project === null || worker.version === project.version) return null;
40
- return {
41
- worker,
42
- project
43
- };
44
- }
45
- /** The error for an explicit hotRuntime whose worker would run a different Vitest. */
46
- function workerVitestMismatchError(mismatch) {
47
- const { worker, project } = mismatch;
48
- return new require_errors.VitestNativeError("HOT_RUNTIME_UNAVAILABLE", `'hotRuntime' cannot run: its worker would load vitest@${worker.version}, but this run is driven by vitest@${project.version}. They talk over Vitest's worker protocol, and a version mismatch reports no results at all rather than failing.\n worker would load: ${worker.path}\n project resolves: ${project.path}\nThis happens when vitest-native and vitest resolve to different node_modules trees (linked packages, hoisted monorepo installs, mixed Vitest versions). Install one Vitest version reachable from vitest-native, or set 'hotRuntime: false'.`);
49
- }
50
- //#endregion
51
- Object.defineProperty(exports, "workerVitestMismatch", {
52
- enumerable: true,
53
- get: function() {
54
- return workerVitestMismatch;
55
- }
56
- });
57
- Object.defineProperty(exports, "workerVitestMismatchError", {
58
- enumerable: true,
59
- get: function() {
60
- return workerVitestMismatchError;
61
- }
62
- });
@@ -1,216 +0,0 @@
1
- # Design: hot runtime as a safe default for greenfield apps
2
-
3
- **Status:** Layers 1–3 shipped (`'auto'` is the default since 2026-09-30; Jest-migration suites admitted since 2026-10-01)
4
- **Basis:** the idiomatic hot-parity validation + default-flip de-risk (`validation/idiomatic/`)
5
-
6
- > Memory update (2026-08-31): explicit hot mode now installs a cgroup-aware,
7
- > worker-total budget. It caps automatic concurrency, recycles one worker at a time
8
- > on local heap or process RSS, and refuses current Vitest's unrecyclable one-worker
9
- > mode unless the user explicitly accepts that risk. The old host-only transitional
10
- > heap formula has been removed.
11
- >
12
- > Architecture bake-off update (2026-08-27): a Vitest-owned selective-persistence
13
- > prototype now passes the bare/Expo/Expo Router correctness matrix, but current hot
14
- > remains faster and lower-RSS at two workers. Hot therefore stays the production
15
- > benchmark while the selective-actual primitive is pursued upstream; see
16
- > `runtime-architecture-bakeoff.md`.
17
- >
18
- > Decision update (2026-08-30): selective persistence is no longer the target for
19
- > React Native. A smaller upstream `isolate: "modules"` prototype reuses stock
20
- > Vitest workers, resets the complete Vite graph/mocks per file and leaves RN in its
21
- > Node CommonJS registry. It passes the real RN/RNTL correctness, coverage,
22
- > two-project and recycling gates and runs within about 15% of current hot on the
23
- > representative 136-file suite. Current hot remains production until that primitive
24
- > is supported and the memory/state work below is complete.
25
- >
26
- > State update (2026-09-01): the current hot runtime now restores an ordered,
27
- > declarative state manifest at every file boundary and verifies the final realm.
28
- > Eleven mutation legs prove timers/stubs, native-boundary state, known RN state,
29
- > environment, process/RN listeners, globals, console, ErrorUtils and Expo state are
30
- > each observable. Normal hot resets the precompiled RN registry's module instances
31
- > per file; resident-RN manifest legs are additionally exercised with the registry
32
- > disabled.
33
- >
34
- > Auto-selection update (2026-09-01): `hotRuntime: "auto"` now selects bounded hot
35
- > only for recyclable, non-migration, stock-pool native configurations. A packed
36
- > consumer gate proves the enable path plus one-worker, Jest-compat and explicit-pool
37
- > fallbacks, including their reason diagnostics. The selection hook runs after other
38
- > Vite config hooks; adversarial legs inject a pool and Jest setup from later plugins
39
- > and prove both are observed before the runtime is chosen.
40
-
41
- ## What the data established
42
-
43
- - **Correctness is not the blocker.** On idiomatic vitest-first apps, hot is
44
- correctness-identical to the default engine — single- and multi-worker, 135→1000
45
- files, with a negative control proving the cross-file bleed probes are sensitive.
46
- The old "hot can't be default because of state bleed" framing is dead for the
47
- greenfield audience.
48
- - **Memory is the real constraint, and it's a tradeoff.** Historical idiomatic
49
- validation observed ~4 MB/file and 2.47 GB at 500 files. The current packed
50
- RN 0.87/RNTL 14 workload grows more slowly but still linearly: 121 MiB after GC at
51
- 136 files and 315 MiB at 406 files. The architectural conclusion is unchanged.
52
- - Current single-worker hot cannot recycle because Vitest batches all files into
53
- one task, so it remains structurally unsafe for sufficiently large suites.
54
- - Recycling at real per-file task boundaries bounds the growth. The validated
55
- module-isolation prototype completed 406 files with a 96 MiB threshold, eight
56
- recycles, 679 MiB peak RSS and 54 MiB final worker heap.
57
- - **Migration suites were out of scope at the time.** hot was not clean for
58
- jest-compat suites. That changed on 2026-10-01: see Layer 3, "The migration
59
- story", for the gate that now covers them and the leaks it found and fixed.
60
- - **Coverage attribution matches isolation.** A packed 40-file RN fixture produces
61
- byte-identical default/hot coverage maps and exact execution counts under both V8
62
- and Istanbul, including an uncovered-function negative control.
63
-
64
- So the question is no longer _whether_ hot is correct enough to default — it is —
65
- but _how_ to default it without the memory footgun or breaking migration suites
66
- (the latter settled by Layer 3's migration gate).
67
-
68
- ## Design principles
69
-
70
- 1. **Safe when enabled.** Turning hot on must never silently grow unbounded.
71
- A current-Vitest one-worker run fails closed unless the explicit
72
- `allowUnboundedMemory` escape hatch is present.
73
- 2. **Staged escalation.** Don't flip the global default for everyone in one step.
74
- Make hot _safe to enable_, then _auto-enable where provably safe_, then make
75
- that selector the default once its gates hold (Layer 3).
76
- 3. **Honest fallbacks.** Where hot can't be made safe (single-worker large, an
77
- explicit pool, a Vitest version mismatch), fall back or warn — never pretend.
78
-
79
- ## Layer 1 — Bounded hot (implemented)
80
-
81
- Explicit hot mode computes one project memory plan before registry compilation:
82
-
83
- - effective memory is the lower valid value of `os.totalmem()` and
84
- `process.constrainedMemory()`;
85
- - soft process RSS is 80% and the fail-closed hard boundary is 90%;
86
- - the plan reserves 256 MiB for the main process and 192 MiB for overlapping old/new
87
- workers during replacement;
88
- - one worker is admitted per remaining 256 MiB envelope, with an automatic maximum
89
- of four;
90
- - the worker-local heap recycle threshold is 65% of its envelope, clamped to
91
- 96–512 MiB.
92
-
93
- The pool samples thread-local `heapUsed` and process-wide RSS. Only one soft-limit
94
- recycle may be in flight, so simultaneous workers cannot all create replacement
95
- overlap. A task is rejected before it starts if RSS has reached the hard boundary.
96
- Explicit `maxWorkers` above the admitted count is capped with a warning; default
97
- concurrency is capped silently and becomes explainable with `diagnostics:true` and
98
- in `vitest-native doctor`.
99
-
100
- **Single-worker is the residual unsafe case in current Vitest.** With
101
- `isolate:false`, Vitest batches every file into one scheduler task, so no pool can
102
- recycle between files. Explicit hot mode therefore fails during config if the plan
103
- or user config selects one worker. A deliberate externally bounded run can opt in
104
- with `hotRuntime: { allowUnboundedMemory: true }`; the runtime warns again if it sees
105
- the actual multi-file batch. This escape hatch disables the automatic worker cap and
106
- process-RSS enforcement. It is not the default and is not described as bounded.
107
-
108
- Docker cgroup v2 probes on Node 20.20.2 established that
109
- `process.constrainedMemory()` exactly reports 512 MiB, 1 GiB and 2 GiB limits where
110
- host memory is misleading. Unit, native, isolation and recycle-soak gates cover the
111
- production controller. A packed Node 22 / RN 0.87 / RNTL 14 gate then ran 405 files:
112
- 512 MiB and 1 GiB both failed during config with `HOT_MEMORY_UNBOUNDED`, while 2 GiB
113
- capped an explicit eight-worker request to four, completed the suite and
114
- demonstrably recycled. None was
115
- OOM-killed. Broader CI/container calibration remains before Layer 2 is promoted.
116
-
117
- ## Layer 2 — `hotRuntime: 'auto'` (implemented)
118
-
119
- A third value that enables hot only when it is both _safe_ and _beneficial_:
120
-
121
- ```ts
122
- reactNative({ engine: "native", hotRuntime: "auto" });
123
- ```
124
-
125
- Enable hot when ALL hold (else fall back to the default per-file engine):
126
-
127
- - ~~**Not a migration suite.**~~ Dropped 2026-10-01 (see Layer 3, "The migration
128
- story"): the jest-compat surface now has its own cross-file isolation gate.
129
- - **Recyclable task boundaries.** On current hot this requires resolved
130
- `maxWorkers >= 2`. With the validated module-isolation scheduler change, one worker
131
- also receives one file per task and can recycle safely.
132
- - **Enough headroom.** Use a constrained-memory-aware total RSS plan, including main
133
- process and old/new worker overlap, rather than a fixed host-memory-per-worker
134
- estimate.
135
- - **No pool takeover.** An explicitly selected pool remains selected; automatic mode
136
- does not replace it with the native hot pool.
137
-
138
- Suite size (hot's win amortizes over many files) is only known after collection,
139
- so `'auto'` keys on config-time signals; a tiny suite still works under hot, just
140
- without a speed win — acceptable.
141
-
142
- ## Layer 3 — `'auto'` as the default (implemented 2026-09-30)
143
-
144
- `hotRuntime` defaults to `'auto'` for the native engine. The gates this section
145
- originally set, and the package-owned evidence for each:
146
-
147
- - **Correctness across files:** the hot isolation suite, the state-manifest
148
- mutation gate (every restore action removed in turn must fail by name), the
149
- hot user-setup gate, and `validate:hot-parity` (no test that passes under
150
- per-file isolation fails under hot).
151
- - **Memory across CI shapes:** the cgroup-aware memory plan, the 100-file soak
152
- with recycling, and the full suites on Linux, macOS and Windows. The packed
153
- cgroup gate runs on Linux only; other providers and cgroup v1 remain open
154
- question 1.
155
- - **The migration story:** suites set up for Jest migration are admitted since
156
- 2026-10-01, on package-owned evidence. `tests-native/hot-jest-compat` runs the
157
- jest-compat surface in one reused worker and in a per-file control: hoisted,
158
- partial, Node-owned and React Native clone-and-override `jest.mock`; runtime
159
- mocks (`doMock`, `setMock`, `dontMock`, `resetModules`); factory-less mocks via
160
- `__mocks__` and automock; spies, fake timers, `jest.setTimeout`, globals,
161
- `process.env`, `requireActual` export mutation and spies on a Node-owned
162
- package's exports; `jest.setSystemTime`; snapshot state; React Native Testing
163
- Library trees left mounted; and a project setup file's top-level `jest.mock`s,
164
- custom matcher, global and console spy, each applied exactly once per file. Building it found three hot-only leaks (a queued `doMock`, a
165
- resident RNTL's missing per-file cleanup, and the shim's relative-path anchoring),
166
- each fixed and mutation-tested. `tests-native/hot-user-setup` covers fake timers
167
- installed by a user setup file. External bake-off apps corroborate but are not the
168
- evidence: their Jest-era setup and shims are theirs, not the package's.
169
- - **A real greenfield app:** covered only by the packed consumer fixtures, which
170
- are small. This is the gate least met; the default's fallback and
171
- `hotRuntime: false` are the mitigation, and a test that passes alone but fails
172
- after other files is the signal to use it.
173
-
174
- Implicitly selected, `'auto'` is quiet: a fallback, or a worker cap from the
175
- memory plan, prints only when `hotRuntime` was set explicitly or `diagnostics` is
176
- on. A Vitest version mismatch between the worker and the project, fatal for an
177
- explicit `hotRuntime`, is one more reason for `'auto'` to fall back.
178
-
179
- ## Memory model (the math we are bounding)
180
-
181
- | config | peak RSS @500 files | bounded? |
182
- | -------------------------- | ------------------- | ------------------------------ |
183
- | default (isolate:true), 4w | 836 MB | yes (recreates per file) |
184
- | hot, 1 worker | 2466 MB | **no** (unbounded, ~4 MB/file) |
185
- | hot + recycle, 4w | 1523 MB | yes (flat to 1000 files) |
186
-
187
- Layer 1 makes the bounded row the out-of-the-box behavior whenever workers ≥ 2.
188
-
189
- ## Guardrails & warnings
190
-
191
- - Single-worker explicit hot → fail closed during config, unless
192
- `allowUnboundedMemory:true` makes the risk deliberate and visible.
193
- - Process RSS at the hard boundary → stop before another worker/task starts and
194
- report `HOT_MEMORY_BUDGET_EXCEEDED`, rather than waiting for exit 137/OOM.
195
- - `'auto'` that declines to enable hot → a one-line diagnostic explaining why
196
- (jest-compat detected / single worker / low memory / Vitest version mismatch)
197
- when `'auto'` was set explicitly or `diagnostics` is on; as the implicit
198
- default it falls back quietly.
199
-
200
- ## Open questions
201
-
202
- 1. Repeat the passing packed Linux cgroup gate across common CI providers, cgroup v1
203
- and different RN/RNTL generations; calibrate from evidence rather than treating
204
- the first constants as permanent.
205
- 2. Reuse an upstream full module-isolation API if it lands. It removes the custom
206
- worker/private module-reset path and gives one-worker runs recyclable file tasks;
207
- a thin memory-aware pool may still be required.
208
-
209
- ## Rollout sequence
210
-
211
- 1. **Layer 1 (bounded explicit hot)** — shipped with cgroup-aware worker-total/RSS
212
- budgeting and verified shared-realm restoration; current one-worker batching
213
- fails closed.
214
- 2. **Layer 2 (`'auto'`)** — shipped as an explicit, conservative greenfield opt-in.
215
- 3. **Layer 3 (default flip)** — shipped; see the Layer 3 section for the evidence
216
- against each gate and the one that is least met.