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.
- package/CHANGELOG.md +339 -0
- package/README.md +138 -48
- package/dist/cli.cjs +70 -5
- package/dist/cli.d.cts +2 -3
- package/dist/cli.d.mts +2 -3
- package/dist/cli.mjs +70 -5
- package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
- package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
- package/dist/errors.d.mts +12 -0
- package/dist/helpers.cjs +6 -3
- package/dist/helpers.d.cts +8 -9
- package/dist/helpers.d.mts +8 -9
- package/dist/helpers.mjs +6 -3
- package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
- package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +537 -118
- package/dist/jest-compat/aliases.d.mts +5 -0
- package/dist/jest-compat/aliases.mjs +65 -0
- package/dist/jest-compat/caller.mjs +53 -0
- package/dist/jest-compat/setup.mjs +72 -36
- package/dist/jest-compat.cjs +1 -3
- package/dist/jest-compat.d.cts +4 -5
- package/dist/jest-compat.d.mts +4 -5
- package/dist/jest-compat.mjs +1 -1
- package/dist/matchers.d.cts +9 -9
- package/dist/matchers.d.mts +9 -9
- package/dist/memory-6EPHrJA1.cjs +144 -0
- package/dist/memory-FYbP0_gg.mjs +126 -0
- package/dist/native/boundary.mjs +13 -2
- package/dist/native/bounded-process.mjs +165 -0
- package/dist/native/export-condition-recovery-preload.mjs +5 -0
- package/dist/native/export-condition-recovery.mjs +195 -0
- package/dist/native/globals.mjs +133 -5
- package/dist/native/hooks.mjs +131 -71
- package/dist/native/loader.mjs +41 -28
- package/dist/native/match.d.mts +3 -0
- package/dist/native/match.mjs +38 -2
- package/dist/native/metro-profile-compiler.mjs +234 -0
- package/dist/native/metro-profile.mjs +115 -0
- package/dist/native/module-reset.mjs +111 -6
- package/dist/native/ownership.d.mts +105 -0
- package/dist/native/ownership.mjs +474 -0
- package/dist/native/registry-compiler.mjs +43 -0
- package/dist/native/registry-process.mjs +124 -0
- package/dist/native/registry.mjs +139 -32
- package/dist/native/reset.mjs +305 -135
- package/dist/native/resolve.d.mts +20 -3
- package/dist/native/resolve.mjs +32 -12
- package/dist/native/rntl-hooks.mjs +76 -0
- package/dist/native/setup.mjs +81 -32
- package/dist/native/state-manifest.d.mts +22 -0
- package/dist/native/state-manifest.mjs +136 -0
- package/dist/native/transform.mjs +29 -8
- package/dist/native/worker.mjs +52 -4
- package/dist/pool-B4yesGhI.cjs +121 -0
- package/dist/pool-DjpOjOf3.mjs +119 -0
- package/dist/{presets-CoNf4ByH.cjs → presets-BYHmi7-W.cjs} +117 -18
- package/dist/{presets-DGProTaA.mjs → presets-DC-eM5IA.mjs} +117 -18
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +58 -12
- package/dist/serializer.cjs +4 -2
- package/dist/serializer.d.cts +3 -4
- package/dist/serializer.d.mts +3 -4
- package/dist/serializer.mjs +4 -2
- package/dist/setup.mjs +61 -50
- package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
- package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
- package/docs/hot-default-design.md +175 -88
- package/docs/migrating-from-jest.md +12 -5
- package/docs/migrating-from-vitest-react-native.md +4 -4
- package/docs/release-readiness.md +39 -13
- package/docs/versioning.md +19 -18
- package/package.json +42 -31
- package/dist/pool-BU-1ecIF.cjs +0 -122
- package/dist/pool-Bcxn9a3I.mjs +0 -118
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
# Design: hot runtime as a safe default for greenfield apps
|
|
2
2
|
|
|
3
|
-
**Status:**
|
|
3
|
+
**Status:** Layers 1–3 shipped (`'auto'` is the default since 2026-09-30; Jest-migration suites admitted since 2026-10-01)
|
|
4
4
|
**Basis:** the idiomatic hot-parity validation + default-flip de-risk (`validation/idiomatic/`)
|
|
5
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
|
+
|
|
6
41
|
## What the data established
|
|
7
42
|
|
|
8
43
|
- **Correctness is not the blocker.** On idiomatic vitest-first apps, hot is
|
|
@@ -10,120 +45,172 @@
|
|
|
10
45
|
files, with a negative control proving the cross-file bleed probes are sensitive.
|
|
11
46
|
The old "hot can't be default because of state bleed" framing is dead for the
|
|
12
47
|
greenfield audience.
|
|
13
|
-
- **Memory is the real constraint, and it's a tradeoff.**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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).
|
|
25
67
|
|
|
26
68
|
## Design principles
|
|
27
69
|
|
|
28
70
|
1. **Safe when enabled.** Turning hot on must never silently grow unbounded.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
The
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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_:
|
|
72
120
|
|
|
73
121
|
```ts
|
|
74
|
-
reactNative({ engine: "native", hotRuntime: "auto" })
|
|
122
|
+
reactNative({ engine: "native", hotRuntime: "auto" });
|
|
75
123
|
```
|
|
76
124
|
|
|
77
125
|
Enable hot when ALL hold (else fall back to the default per-file engine):
|
|
78
126
|
|
|
79
|
-
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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.
|
|
85
137
|
|
|
86
138
|
Suite size (hot's win amortizes over many files) is only known after collection,
|
|
87
139
|
so `'auto'` keys on config-time signals; a tiny suite still works under hot, just
|
|
88
140
|
without a speed win — acceptable.
|
|
89
141
|
|
|
90
|
-
## Layer 3 —
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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.
|
|
96
178
|
|
|
97
179
|
## Memory model (the math we are bounding)
|
|
98
180
|
|
|
99
|
-
| config
|
|
100
|
-
|
|
|
101
|
-
| default (isolate:true), 4w | 836 MB
|
|
102
|
-
| hot, 1 worker
|
|
103
|
-
| hot + recycle, 4w
|
|
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) |
|
|
104
186
|
|
|
105
187
|
Layer 1 makes the bounded row the out-of-the-box behavior whenever workers ≥ 2.
|
|
106
188
|
|
|
107
189
|
## Guardrails & warnings
|
|
108
190
|
|
|
109
|
-
- Single-worker hot
|
|
110
|
-
|
|
111
|
-
|
|
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.
|
|
112
195
|
- `'auto'` that declines to enable hot → a one-line diagnostic explaining why
|
|
113
|
-
(jest-compat detected / single worker / low memory
|
|
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.
|
|
114
199
|
|
|
115
200
|
## Open questions
|
|
116
201
|
|
|
117
|
-
1.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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.
|
|
123
208
|
|
|
124
209
|
## Rollout sequence
|
|
125
210
|
|
|
126
|
-
1. **Layer 1 (bounded hot)** —
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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.
|
|
@@ -111,8 +111,11 @@ Same entry is needed when a `vi.mock('<lib>')` must intercept an otherwise-exter
|
|
|
111
111
|
|
|
112
112
|
### 2f. Jest config options
|
|
113
113
|
`jest.config.js` keys (`setupFilesAfterEnv`, `moduleNameMapper`, `testEnvironment`, etc.) move to the
|
|
114
|
-
Vitest config: `setupFiles`, `resolve.alias`, `test.environment: 'node'`.
|
|
115
|
-
|
|
114
|
+
Vitest config: `setupFiles`, `resolve.alias`, `test.environment: 'node'`. A suite on
|
|
115
|
+
`testEnvironment: 'jsdom'` keeps it as `test.environment: 'jsdom'` (`'happy-dom'` works too): React
|
|
116
|
+
Native renders there alongside the DOM, with either engine and with or without the hot runtime.
|
|
117
|
+
`jest.setTimeout(ms)` is a no-op under the shim (use `test.testTimeout` in config or per-test
|
|
118
|
+
`{ timeout }`).
|
|
116
119
|
|
|
117
120
|
---
|
|
118
121
|
|
|
@@ -137,9 +140,13 @@ few or none.
|
|
|
137
140
|
that was silently a no-op. Move it to top level with a valid override, or drop it.
|
|
138
141
|
|
|
139
142
|
The `jest.requireActual('react-native')` clone-and-override pattern is supported (RN's module is
|
|
140
|
-
writable under the compat layer).
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
writable under the compat layer). `jest.requireActual` and `jest.requireMock` also apply the
|
|
144
|
+
project's `resolve.alias` string entries, so a partial mock of `'@/services/api'` works the way
|
|
145
|
+
`babel-plugin-module-resolver` or jest-expo's path mapping made it work under Jest. Configure the
|
|
146
|
+
alias with a string `find` (`{ "@": path.resolve(__dirname, "src") }`); regex aliases and custom
|
|
147
|
+
resolvers cannot be applied to `requireActual`, and an unresolved specifier says so. **Coming from
|
|
148
|
+
jest-expo:** `migrate` translates its presets, and expo-router's own testing library runs as written —
|
|
149
|
+
see the [Expo guide](https://danfry1.github.io/vitest-native/guide/expo).
|
|
143
150
|
|
|
144
151
|
---
|
|
145
152
|
|
|
@@ -89,10 +89,10 @@ Your existing tests render against real React Native exactly as before.
|
|
|
89
89
|
tests. A CI-gated cross-check keeps the mock behaviorally honest against real RN.
|
|
90
90
|
- **Presets** auto-shadow common native libraries (Reanimated, Gesture Handler,
|
|
91
91
|
Safe Area, Navigation, …) the way `jest` mocks them — no per-lib wiring.
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
process-wide pollution between files. It uses Vitest's
|
|
95
|
-
|
|
92
|
+
- A **hot runtime**, on by default where the run can be bounded
|
|
93
|
+
(`hotRuntime: 'auto'`), keeps RN warm across files while resetting app/test
|
|
94
|
+
modules and common process-wide pollution between files. It uses Vitest's
|
|
95
|
+
custom worker APIs; `hotRuntime: false` opts out.
|
|
96
96
|
|
|
97
97
|
## Gotchas (the margins)
|
|
98
98
|
|
|
@@ -19,15 +19,16 @@ semver, which are experimental, and how the peer ranges below are allowed to mov
|
|
|
19
19
|
|
|
20
20
|
## Blocking compatibility matrix
|
|
21
21
|
|
|
22
|
-
- Node 20.19 on Linux.
|
|
23
|
-
- Node 22.13 on Linux, macOS, and Windows.
|
|
22
|
+
- Node 20.19 on Linux, with RNTL 12 and with RNTL 13.
|
|
23
|
+
- Node 22.13 on Linux, macOS, and Windows; Node 24 on Linux.
|
|
24
24
|
- Patched Vite lines ^6.4.2, ^7.3.2, and ^8.0.5 through packed consumers.
|
|
25
|
-
- Vitest
|
|
26
|
-
|
|
27
|
-
- React Native 0.81–0.
|
|
25
|
+
- Vitest 5 (the lockfile release and the newest 5.x) against React Native 0.81–0.87, and the newest
|
|
26
|
+
Vitest 4.x against the oldest and newest of that range.
|
|
27
|
+
- React Native 0.81–0.87 in the full native matrix (`.github/workflows/native-rn-matrix.yml`, the
|
|
28
|
+
source the published fidelity range is generated from).
|
|
28
29
|
- React Native 0.86 in a pinned packed Android consumer.
|
|
29
30
|
- React Native Testing Library 12, 13, and 14.
|
|
30
|
-
- Expo
|
|
31
|
+
- Expo 57, a hoisted npm-workspace monorepo, and a pnpm-workspace monorepo.
|
|
31
32
|
|
|
32
33
|
Required Vite, Vitest, and React peer mismatches fail during configuration. Unsupported future major
|
|
33
34
|
versions are rejected rather than allowed to fail later inside private runner internals.
|
|
@@ -35,15 +36,40 @@ versions are rejected rather than allowed to fail later inside private runner in
|
|
|
35
36
|
## Blocking release gates
|
|
36
37
|
|
|
37
38
|
1. Dependency pinning, lint, formatting, and TypeScript checks.
|
|
38
|
-
2. Mock suite and React Native conformance tests.
|
|
39
|
-
3. Native iOS and Android suites.
|
|
39
|
+
2. Mock suite and React Native conformance tests, and React Native API coverage of the pinned RN.
|
|
40
|
+
3. Native iOS and Android suites, on the forks pool and with the navigation preset.
|
|
40
41
|
4. Hot-runtime full suite, cross-file isolation suite, and generated 100-file soak.
|
|
41
42
|
5. End-to-end memory-triggered worker recycling.
|
|
42
|
-
6.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
6. Hot runtime against the default engine: file-for-file parity over a generated app-shaped corpus,
|
|
44
|
+
and identical V8 and Istanbul coverage attribution.
|
|
45
|
+
7. Vitest semantics under the defaults, on Vitest 5 and the Vitest 4 floor: config and CLI flags,
|
|
46
|
+
projects, watch mode, the jsdom and happy-dom environments, `--typecheck`, `vitest bench` and the
|
|
47
|
+
HTML (UI) reporter run as Vitest documents them, with cross-file isolation.
|
|
48
|
+
8. Mock-versus-real-RN behavioral cross-check.
|
|
49
|
+
9. Example app.
|
|
50
|
+
10. `npm pack` followed by isolated installs of bare RN, Expo, monorepo, and current-RN consumers.
|
|
51
|
+
11. Package export and declaration analysis with `@arethetypeswrong/cli`.
|
|
52
|
+
12. Staged npm publishing with provenance; the version remains unavailable until maintainer approval.
|
|
53
|
+
|
|
54
|
+
## How CI enforces this
|
|
55
|
+
|
|
56
|
+
Two checks are required on `main`: `CI verdict` (`ci.yml`) and `RN matrix verdict`
|
|
57
|
+
(`native-rn-matrix.yml`), alongside CodeQL. Each verdict depends on every gate job in its workflow
|
|
58
|
+
and fails if any failed or was cancelled, so adding a matrix leg never needs a branch-protection
|
|
59
|
+
change.
|
|
60
|
+
|
|
61
|
+
- **Docs-only pull requests** skip the gates by a job condition (`.github/scripts/classify-change.sh`).
|
|
62
|
+
GitHub reports a job skipped by a condition as successful, but leaves the checks of a workflow
|
|
63
|
+
skipped by a `paths` filter pending, which would block a required check.
|
|
64
|
+
- **The single-leg packed gates** (consumers, Vitest semantics per major, the hot-runtime and registry
|
|
65
|
+
gates) run as parallel cells of one `Packed gate` job. They used to run in sequence on the Linux
|
|
66
|
+
Node 22 leg, which made that leg the critical path: 9.1 minutes against under 4 for every other
|
|
67
|
+
leg. Standard runners are free for public repositories and no job waited in a queue, so the extra
|
|
68
|
+
jobs cost nothing.
|
|
69
|
+
- **Pushes to `main` run everything**, even though branch protection requires a pull request to be up
|
|
70
|
+
to date first. A pull request's caches are scoped to its merge ref and only its re-runs can restore
|
|
71
|
+
them; the caches every pull request starts from are the ones `main` saves. `pages.yml` also
|
|
72
|
+
publishes the fidelity matrix from the latest successful `main` run of the RN matrix.
|
|
47
73
|
|
|
48
74
|
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20.19+.
|
|
49
75
|
|
package/docs/versioning.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This document is the semver contract: what a major, minor, or patch release is allowed to change.
|
|
4
4
|
|
|
5
5
|
[`release-readiness.md`](./release-readiness.md) is the companion document. It defines what is
|
|
6
|
-
|
|
6
|
+
_tested_ before a release ships. This one defines what is _promised_ about the surface those tests
|
|
7
7
|
cover.
|
|
8
8
|
|
|
9
9
|
Until 1.0, the contract below describes intent and is honoured on a best-effort basis; breaking
|
|
@@ -20,16 +20,16 @@ at all. Anything not listed here is not covered — see [Outside the contract](#
|
|
|
20
20
|
Only the subpaths declared in `exports` are public. Nothing under `dist/` is importable directly,
|
|
21
21
|
and deep paths are not supported even when they happen to resolve.
|
|
22
22
|
|
|
23
|
-
| Subpath
|
|
24
|
-
|
|
|
25
|
-
| `vitest-native`
|
|
26
|
-
| `vitest-native/helpers`
|
|
27
|
-
| `vitest-native/presets`
|
|
28
|
-
| `vitest-native/matchers`
|
|
29
|
-
| `vitest-native/serializer`
|
|
30
|
-
| `vitest-native/jest-compat`
|
|
31
|
-
| `vitest-native/jest-compat/setup`, `/jest-globals`, `/extend-expect-noop` | loadable as setup-file and alias targets
|
|
32
|
-
| `vitest-native/rntl-matchers`
|
|
23
|
+
| Subpath | Covered exports |
|
|
24
|
+
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `vitest-native` | `reactNative`, `presets`, `disabledPresetNames` |
|
|
26
|
+
| `vitest-native/helpers` | `setPlatform`, `setDimensions`, `setColorScheme`, `setInsets`, `mockNativeModule`, `extendPresetMock`, `resetAllMocks` |
|
|
27
|
+
| `vitest-native/presets` | the 17 preset factories, by name |
|
|
28
|
+
| `vitest-native/matchers` | `toHaveAnimatedStyle`, `toHaveAnimatedProps`, `animatedMatchers` |
|
|
29
|
+
| `vitest-native/serializer` | `serializer` |
|
|
30
|
+
| `vitest-native/jest-compat` | `jestMockTransform`, `jestCompatAliases`, `jestCompatSetup` |
|
|
31
|
+
| `vitest-native/jest-compat/setup`, `/jest-globals`, `/extend-expect-noop` | loadable as setup-file and alias targets |
|
|
32
|
+
| `vitest-native/rntl-matchers` | the RNTL matcher type augmentation |
|
|
33
33
|
|
|
34
34
|
The module format of an entry point is part of the contract: an entry that is loadable from
|
|
35
35
|
CommonJS stays loadable from CommonJS. Which entries those are is enforced by `check:exports`, and
|
|
@@ -39,11 +39,11 @@ every subpath is loaded by specifier under both `require` and `import` in
|
|
|
39
39
|
### Plugin options
|
|
40
40
|
|
|
41
41
|
The keys accepted by the plugin function are `engine`, `platform`, `presets`, `mocks`,
|
|
42
|
-
`diagnostics`, `assetExts`, `transform`, `hotRuntime`. Their accepted types and their
|
|
43
|
-
covered. An unknown key is rejected at configuration time, so adding a key is a minor
|
|
44
|
-
or renaming one is a major.
|
|
42
|
+
`diagnostics`, `assetExts`, `metroConfig`, `transform`, `hotRuntime`. Their accepted types and their
|
|
43
|
+
defaults are covered. An unknown key is rejected at configuration time, so adding a key is a minor
|
|
44
|
+
and removing or renaming one is a major.
|
|
45
45
|
|
|
46
|
-
`hotRuntime`
|
|
46
|
+
`hotRuntime` and `metroConfig` are exceptions — see [Experimental](#experimental).
|
|
47
47
|
|
|
48
48
|
### Preset authoring
|
|
49
49
|
|
|
@@ -73,9 +73,9 @@ Changing any of these is a patch or minor, and never requires a major.
|
|
|
73
73
|
error `message` strings. Assert on error `code`, not on text.
|
|
74
74
|
- **What a preset mocks.** Presets track upstream libraries. When `react-native-reanimated` adds an
|
|
75
75
|
export, the preset gains it in a minor; when upstream removes one, the preset drops it in a minor.
|
|
76
|
-
The preset's
|
|
76
|
+
The preset's _existence and name_ are covered; its mocked surface follows upstream.
|
|
77
77
|
- **Mock-engine fidelity details.** The mock engine's job is to match real React Native. A change
|
|
78
|
-
that moves it
|
|
78
|
+
that moves it _closer_ to real RN is a fix, even if a test was relying on the divergence. The
|
|
79
79
|
cross-check corpus and `crosscheck/known-differences.json` record where the two intentionally
|
|
80
80
|
differ.
|
|
81
81
|
- **Anything reachable only by deep import** into `dist/`.
|
|
@@ -88,7 +88,8 @@ are documented, tested, and gated in CI — they are simply not stable, and they
|
|
|
88
88
|
|
|
89
89
|
| Surface | Why |
|
|
90
90
|
| --- | --- |
|
|
91
|
-
| `hotRuntime` and its options | Built on Vitest's experimental custom-pool API, which can change between Vitest minors.
|
|
91
|
+
| `hotRuntime` and its options | Built on Vitest's experimental custom-pool API, which can change between Vitest minors. The default, `'auto'`, falls back to per-file isolation whenever the run cannot be bounded; `false` opts out. |
|
|
92
|
+
| `metroConfig` and its options | Opt-in declarative Metro profile ingestion. Framework loading, custom resolvers and the version matrix remain under investigation. Off by default. |
|
|
92
93
|
|
|
93
94
|
A surface leaves this list by being promoted in a minor, and can change or be removed in a minor
|
|
94
95
|
while it is on it.
|