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.
- package/CHANGELOG.md +1063 -0
- package/README.md +47 -2
- package/dist/cli.cjs +642 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +638 -0
- package/dist/ecosystem-CO5vqExO.mjs +318 -0
- package/dist/ecosystem-IuZ-Gv0R.cjs +356 -0
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-vlK4zxuK.d.mts → index-BJL4cQ-l.d.cts} +22 -7
- package/dist/{index-YjjYELG7.d.cts → index-CvCU0cLl.d.mts} +20 -9
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +563 -232
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +164 -5
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/boundary.mjs +108 -30
- package/dist/native/compile-cache.mjs +10 -5
- package/dist/native/explain.mjs +69 -0
- package/dist/native/hooks.mjs +151 -4
- package/dist/native/loader.mjs +61 -12
- package/dist/native/match.mjs +107 -8
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +540 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +34 -7
- package/dist/native/setup.mjs +19 -3
- package/dist/native/transform.mjs +195 -21
- package/dist/native/worker.mjs +69 -17
- package/dist/pool-Bcxp4Qrg.mjs +118 -0
- package/dist/pool-CFND7plG.cjs +122 -0
- package/dist/{preset-map-DCWaM08s.mjs → preset-map-BpDG_D5m.mjs} +1 -1
- package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-DxilQ4pI.cjs} +1 -1
- package/dist/{presets-7eMfp7o2.cjs → presets-BGTqVH6C.cjs} +227 -52
- package/dist/{presets-23FJ76O4.mjs → presets-CK85x8ey.mjs} +222 -53
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +544 -193
- package/docs/hot-default-design.md +129 -0
- package/docs/migrating-from-jest.md +43 -7
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +24 -6
- package/docs/versioning.md +133 -0
- package/package.json +40 -38
- package/dist/index.cjs +0 -643
- package/dist/index.d.cts +0 -14
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
- package/dist/presets.cjs +0 -17
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2514
- package/dist/setup.d.cts +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Design: hot runtime as a safe default for greenfield apps
|
|
2
|
+
|
|
3
|
+
**Status:** Design proposal (not yet implemented)
|
|
4
|
+
**Basis:** the idiomatic hot-parity validation + default-flip de-risk (`validation/idiomatic/`)
|
|
5
|
+
|
|
6
|
+
## What the data established
|
|
7
|
+
|
|
8
|
+
- **Correctness is not the blocker.** On idiomatic vitest-first apps, hot is
|
|
9
|
+
correctness-identical to the default engine — single- and multi-worker, 135→1000
|
|
10
|
+
files, with a negative control proving the cross-file bleed probes are sensitive.
|
|
11
|
+
The old "hot can't be default because of state bleed" framing is dead for the
|
|
12
|
+
greenfield audience.
|
|
13
|
+
- **Memory is the real constraint, and it's a tradeoff.**
|
|
14
|
+
- Single-worker hot accumulates **~4 MB/file, unbounded** (2466 MB @500 files).
|
|
15
|
+
Recycling cannot fire single-worker (Vitest batches all files into one task),
|
|
16
|
+
so this case is structurally unsafe at large scale.
|
|
17
|
+
- Multi-worker + recycling **bounds it flat** (~1.5 GB @500–1000 files) but at
|
|
18
|
+
~1.8× the default engine, because each worker holds React Native resident.
|
|
19
|
+
- **Migration suites are out of scope.** hot is *not* clean for jest-compat
|
|
20
|
+
suites (the paper bake-off); that's a migration-tooling problem, separate from
|
|
21
|
+
the engine.
|
|
22
|
+
|
|
23
|
+
So the question is no longer *whether* hot is correct enough to default — it is —
|
|
24
|
+
but *how* to default it without the memory footgun or breaking migration suites.
|
|
25
|
+
|
|
26
|
+
## Design principles
|
|
27
|
+
|
|
28
|
+
1. **Safe when enabled.** Turning hot on must never silently grow unbounded.
|
|
29
|
+
Today `hotRuntime: true` on a single worker leaks with only a warning.
|
|
30
|
+
2. **Opt-in escalation.** Don't flip the global default for everyone in one step.
|
|
31
|
+
Make hot *safe to enable*, then *auto-enable where provably safe*, then
|
|
32
|
+
(much later, with real-world data) consider the global default.
|
|
33
|
+
3. **Honest fallbacks.** Where hot can't be made safe (single-worker large, or
|
|
34
|
+
jest-compat suites), fall back or warn — never pretend.
|
|
35
|
+
|
|
36
|
+
## Layer 1 — Bounded hot (safe defaults when `hotRuntime` is enabled)
|
|
37
|
+
|
|
38
|
+
When `hotRuntime` is truthy and the user has NOT set an explicit `memoryLimit` /
|
|
39
|
+
`recycleAfterFiles`, apply a **default per-worker memory bound** so total hot
|
|
40
|
+
memory is bounded regardless of worker count:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
perWorkerMemoryLimit = clamp(
|
|
44
|
+
floor(MEMORY_BUDGET_FRACTION * os.totalmem() / effectiveWorkers),
|
|
45
|
+
MIN_PER_WORKER, // 512 MB — below this, recycling thrashes
|
|
46
|
+
MAX_PER_WORKER, // 2 GB — above this, no point bounding
|
|
47
|
+
)
|
|
48
|
+
// MEMORY_BUDGET_FRACTION = 0.6 (total hot RSS targets ~60% of system memory)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The hot pool already implements its own `memoryLimit` recycling (custom pools
|
|
52
|
+
don't receive Vitest's vm-only `task.memoryLimit`), so this is wiring a default,
|
|
53
|
+
not new machinery. Dividing the budget by worker count keeps total memory bounded
|
|
54
|
+
as workers scale — **up to a point**: once worker count exceeds
|
|
55
|
+
`MEMORY_BUDGET_FRACTION * totalmem / MIN_PER_WORKER`, the `MIN_PER_WORKER` floor
|
|
56
|
+
engages and total memory becomes `workers * MIN_PER_WORKER`, which grows with
|
|
57
|
+
worker count again (e.g. 16 workers × 512 MB = 8 GB regardless of the fraction).
|
|
58
|
+
The floor exists because a per-worker limit below React Native's resident base
|
|
59
|
+
(~600 MB) would thrash (recycle every few files). So a **worker-count cap** is
|
|
60
|
+
still needed for the high-worker / low-memory corner — the budget division alone
|
|
61
|
+
does not bound it there.
|
|
62
|
+
|
|
63
|
+
**Single-worker is the residual unsafe case.** Recycling can't fire when Vitest
|
|
64
|
+
batches all files into one task (`isolate:false` + `maxWorkers:1`). So when hot is
|
|
65
|
+
enabled and workers resolve to 1, the bound is inert — keep the existing one-time
|
|
66
|
+
warning (already shipped) and document "run ≥2 workers for bounded hot memory."
|
|
67
|
+
Do **not** silently rewrite the user's `maxWorkers`.
|
|
68
|
+
|
|
69
|
+
## Layer 2 — `hotRuntime: 'auto'`
|
|
70
|
+
|
|
71
|
+
A third value that enables hot only when it is both *safe* and *beneficial*:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
reactNative({ engine: "native", hotRuntime: "auto" })
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Enable hot when ALL hold (else fall back to the default per-file engine):
|
|
78
|
+
|
|
79
|
+
- **Not a migration suite.** No `jestMockTransform` plugin and no jest-compat
|
|
80
|
+
setup file present (inspect the resolved Vite config in `configResolved`). hot
|
|
81
|
+
isn't clean for jest-compat patterns, so don't auto-enable there.
|
|
82
|
+
- **Multi-worker.** Resolved `maxWorkers >= 2` (so recycling can bound memory).
|
|
83
|
+
- **Enough headroom.** `os.totalmem()` comfortably exceeds
|
|
84
|
+
`effectiveWorkers * RN_RESIDENT_ESTIMATE` (~600 MB/worker).
|
|
85
|
+
|
|
86
|
+
Suite size (hot's win amortizes over many files) is only known after collection,
|
|
87
|
+
so `'auto'` keys on config-time signals; a tiny suite still works under hot, just
|
|
88
|
+
without a speed win — acceptable.
|
|
89
|
+
|
|
90
|
+
## Layer 3 — global default flip (future, gated)
|
|
91
|
+
|
|
92
|
+
Only after `'auto'` has real-world mileage would we consider making `'auto'` the
|
|
93
|
+
default for the native engine. Gating evidence: a real greenfield app validated,
|
|
94
|
+
memory behavior confirmed across CI shapes, and the migration story handled. Not
|
|
95
|
+
part of this proposal.
|
|
96
|
+
|
|
97
|
+
## Memory model (the math we are bounding)
|
|
98
|
+
|
|
99
|
+
| config | peak RSS @500 files | bounded? |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| default (isolate:true), 4w | 836 MB | yes (recreates per file) |
|
|
102
|
+
| hot, 1 worker | 2466 MB | **no** (unbounded, ~4 MB/file) |
|
|
103
|
+
| hot + recycle, 4w | 1523 MB | yes (flat to 1000 files) |
|
|
104
|
+
|
|
105
|
+
Layer 1 makes the bounded row the out-of-the-box behavior whenever workers ≥ 2.
|
|
106
|
+
|
|
107
|
+
## Guardrails & warnings
|
|
108
|
+
|
|
109
|
+
- Single-worker hot with a memory bound set → the existing "recycling INACTIVE"
|
|
110
|
+
warning (PR #55), reworded to mention the unbounded-memory risk and recommend
|
|
111
|
+
≥2 workers.
|
|
112
|
+
- `'auto'` that declines to enable hot → a one-line diagnostic explaining why
|
|
113
|
+
(jest-compat detected / single worker / low memory), so it isn't a silent no-op.
|
|
114
|
+
|
|
115
|
+
## Open questions
|
|
116
|
+
|
|
117
|
+
1. `MEMORY_BUDGET_FRACTION` — 0.6 is a guess; validate against CI shapes
|
|
118
|
+
(2-core/8 GB GitHub runners, memory-constrained containers).
|
|
119
|
+
2. Should `'auto'` also consider `process.env.CI` memory limits (cgroup limits)
|
|
120
|
+
rather than `os.totalmem()`? Containerized CI often has less than the host.
|
|
121
|
+
3. Reuse the upstream `isolate: 'modules'` work if it lands — it would remove the
|
|
122
|
+
custom-pool hacks underneath all of this.
|
|
123
|
+
|
|
124
|
+
## Rollout sequence
|
|
125
|
+
|
|
126
|
+
1. **Layer 1 (bounded hot)** — low risk, high value; makes hot safe to enable for
|
|
127
|
+
anyone today. Ship first.
|
|
128
|
+
2. **Layer 2 (`'auto'`)** — opt greenfield projects in safely.
|
|
129
|
+
3. **Layer 3 (default flip)** — only with the gating evidence above.
|
|
@@ -5,8 +5,9 @@ couple to Jest at several levels (the `jest` global, `@jest/globals`, `jest.mock
|
|
|
5
5
|
`@react-native/jest-preset`, jest-native matchers, recorded snapshots). The `vitest-native/jest-compat`
|
|
6
6
|
layer clears the *API coupling* mechanically; the rest is a small, well-defined per-suite cleanup.
|
|
7
7
|
|
|
8
|
-
This guide is
|
|
9
|
-
|
|
8
|
+
This guide is informed by migration runs against production apps, but support claims come from
|
|
9
|
+
minimal package-owned tests. External apps include custom Jest setup and migration shims, so their
|
|
10
|
+
pass counts are observations rather than capability verdicts.
|
|
10
11
|
|
|
11
12
|
---
|
|
12
13
|
|
|
@@ -101,6 +102,13 @@ Those are Jest/Metro config. vitest-native handles RN + third-party transformati
|
|
|
101
102
|
For *run-real pure-JS* third-party libs under the native engine, use the plugin's `transform: [...]`
|
|
102
103
|
allowlist instead of `transformIgnorePatterns`.
|
|
103
104
|
|
|
105
|
+
One case needs a manual `transform` entry: a library shipping **untranspiled JSX in `.js` files**
|
|
106
|
+
(its `package.json` `"react-native"`/`"module"` field points at `src/`). Under the native engine
|
|
107
|
+
it's external to the Vite graph, so you'll see `Failed to parse source for import analysis … If you
|
|
108
|
+
are using JSX, make sure to name the file with the .jsx or .tsx extension. File: node_modules/<lib>/…`.
|
|
109
|
+
The error names the file — add that package: `reactNative({ engine: 'native', transform: ['<lib>'] })`.
|
|
110
|
+
Same entry is needed when a `vi.mock('<lib>')` must intercept an otherwise-externalized library.
|
|
111
|
+
|
|
104
112
|
### 2f. Jest config options
|
|
105
113
|
`jest.config.js` keys (`setupFilesAfterEnv`, `moduleNameMapper`, `testEnvironment`, etc.) move to the
|
|
106
114
|
Vitest config: `setupFiles`, `resolve.alias`, `test.environment: 'node'`. `jest.setTimeout(ms)` is a
|
|
@@ -108,17 +116,45 @@ no-op under the shim (use `test.testTimeout` in config or per-test `{ timeout }`
|
|
|
108
116
|
|
|
109
117
|
---
|
|
110
118
|
|
|
111
|
-
## 3.
|
|
119
|
+
## 3. Known limits — assertions coupled to Jest's mocks
|
|
120
|
+
|
|
121
|
+
A minority of tests assert on **Jest's React Native mock internals** rather than rendered behavior.
|
|
122
|
+
The native engine runs *real* RN, so these can't be reproduced without re-mocking RN internally
|
|
123
|
+
(which defeats the point). Recognize them so you rewrite or skip rather than chase them. In our runs
|
|
124
|
+
they clustered in **component libraries** (which test RN internals directly); ordinary app suites hit
|
|
125
|
+
few or none.
|
|
126
|
+
|
|
127
|
+
- **`jest.spyOn(View.prototype, 'measure'/'measureInWindow')`** — Jest mocks `View` as a class with
|
|
128
|
+
prototype methods; real RN's `View` is a `forwardRef` with no such prototype, so the spy target is
|
|
129
|
+
`undefined`. Drive layout via `onLayout`/`fireEvent` instead, or accept as known-incompatible.
|
|
130
|
+
- **`jest.mock('react-native/Libraries/…')` of internal submodules** (e.g. `Appearance`,
|
|
131
|
+
`AccessibilityInfo`) then spying them — externalized/resident RN isn't intercepted by a submodule
|
|
132
|
+
mock. Prefer the public API from `react-native`.
|
|
133
|
+
- **`image.props.source.uri` / raw `source`-shape assertions** — real RN normalizes `source`, so the
|
|
134
|
+
raw shape differs. Native = real RN = ground truth; assert on behavior instead.
|
|
135
|
+
- **`jest.mock('react-native', …)` nested inside `beforeAll`/`describe` callbacks** — Jest doesn't
|
|
136
|
+
hoist those (they're inert); vitest-native applies mocks more consistently, which can expose a mock
|
|
137
|
+
that was silently a no-op. Move it to top level with a valid override, or drop it.
|
|
138
|
+
|
|
139
|
+
The `jest.requireActual('react-native')` clone-and-override pattern is supported (RN's module is
|
|
140
|
+
writable under the compat layer). **Expo caveat:** suites importing **Expo core** pull in Expo's
|
|
141
|
+
dev-server/init plumbing (message socket, dev tools) that expects a Metro connection and may not
|
|
142
|
+
collect without extra setup; suites using Expo *modules* via the `expo` preset are unaffected.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 4. Suggested migration recipe
|
|
112
147
|
|
|
113
148
|
1. Add the jest-compat config (section 1). Upgrade RNTL to a supported 12–14 release (2b).
|
|
114
149
|
2. Delete manual third-party native-lib mocks and `@react-native/jest-preset` (2c, 2e).
|
|
115
150
|
3. Convert any **top-level** `jest.mock(...)` to `vi.mock(...)`; leave runtime `jest.*` as-is (2a).
|
|
116
151
|
4. Run `vitest run -u` once to re-record snapshots (2d), then `vitest run` to confirm green.
|
|
117
|
-
5. Triage remaining failures —
|
|
118
|
-
issues (large-suite memory limits,
|
|
119
|
-
|
|
152
|
+
5. Triage remaining failures — a missing query update, a suite-specific mock, or a known
|
|
153
|
+
Jest-mock-coupled assertion (section 3). For runtime issues (large-suite memory limits,
|
|
154
|
+
error-boundary console noise, overriding a preset's mock), see the
|
|
155
|
+
[Troubleshooting](../README.md#troubleshooting) section.
|
|
120
156
|
|
|
121
|
-
##
|
|
157
|
+
## 5. What "done" looks like
|
|
122
158
|
|
|
123
159
|
A migrated suite runs under Vitest with: the jest-compat aliases + setup, RNTL 12–14, no manual
|
|
124
160
|
third-party native mocks, top-level mocks converted, and snapshots re-recorded. You get Vitest's
|
|
@@ -27,7 +27,7 @@ npm i -D vitest-native @react-native/babel-preset @babel/core
|
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Keep your existing `vitest`, `vite`, `react`, `react-native`, and
|
|
30
|
-
`@testing-library/react-native`. Requirements: **Vitest 4.x, Vite ^6.4.2, ^7.3.2, or ^8.0.5, the React
|
|
30
|
+
`@testing-library/react-native`. Requirements: **Vitest 4.x or 5.x, Vite ^6.4.2, ^7.3.2, or ^8.0.5, the React
|
|
31
31
|
version required by your RN release, React Native 0.81–0.86 (validated), and
|
|
32
32
|
RNTL 12–14.** RNTL 14 uses async rendering APIs and requires Node 22.13 or 24+.
|
|
33
33
|
|
|
@@ -4,12 +4,16 @@ This document defines what `vitest-native` means by release-supported. It is del
|
|
|
4
4
|
than "the repository tests pass": published artifacts are installed into representative consumer
|
|
5
5
|
projects, experimental surfaces are labeled, and upstream compatibility is bounded.
|
|
6
6
|
|
|
7
|
+
It covers what is **tested** before a release ships. [`versioning.md`](./versioning.md) covers what
|
|
8
|
+
is **promised** about the surface those tests cover — which exports and options are protected by
|
|
9
|
+
semver, which are experimental, and how the peer ranges below are allowed to move.
|
|
10
|
+
|
|
7
11
|
## Stability labels
|
|
8
12
|
|
|
9
13
|
| Surface | Status | Release promise |
|
|
10
14
|
| --- | --- | --- |
|
|
11
15
|
| Mock engine | Release-supported | Documented behavior and exports are gated on every pull request and release. |
|
|
12
|
-
| Native engine | Release-supported beta | Real RN behavior, iOS/Android resolution, presets, helpers, assets, matchers, and isolation are blocking gates.
|
|
16
|
+
| Native engine | Release-supported beta | Real RN behavior, iOS/Android resolution, presets, helpers, assets, matchers, and isolation are blocking gates. Until 1.0 the [versioning contract](./versioning.md) is honoured best-effort, and a breaking change is called out in release notes. |
|
|
13
17
|
| Hot runtime | Experimental | Correctness is gated, but it depends on Vitest's experimental custom-pool API and can require adaptation between Vitest releases. |
|
|
14
18
|
| Current RN edge | Canary | Tested weekly and in a pinned packed consumer once adopted; an edge failure opens a compatibility issue. |
|
|
15
19
|
|
|
@@ -18,7 +22,8 @@ projects, experimental surfaces are labeled, and upstream compatibility is bound
|
|
|
18
22
|
- Node 20.19 on Linux.
|
|
19
23
|
- Node 22.13 on Linux, macOS, and Windows.
|
|
20
24
|
- Patched Vite lines ^6.4.2, ^7.3.2, and ^8.0.5 through packed consumers.
|
|
21
|
-
- Vitest 4.x
|
|
25
|
+
- Vitest 4.x and 5.x: the lockfile release, the newest supported 4.x release, and 5.x
|
|
26
|
+
(against the oldest and newest supported React Native).
|
|
22
27
|
- React Native 0.81–0.85 in the full native matrix.
|
|
23
28
|
- React Native 0.86 in a pinned packed Android consumer.
|
|
24
29
|
- React Native Testing Library 12, 13, and 14.
|
|
@@ -40,10 +45,23 @@ versions are rejected rather than allowed to fail later inside private runner in
|
|
|
40
45
|
9. Package export and declaration analysis with `@arethetypeswrong/cli`.
|
|
41
46
|
10. Staged npm publishing with provenance; the version remains unavailable until maintainer approval.
|
|
42
47
|
|
|
43
|
-
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20+.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20.19+.
|
|
49
|
+
|
|
50
|
+
Seven of the eleven `exports` subpaths are ESM-only by design — `.`, `./setup`, `./presets`, the
|
|
51
|
+
three `jest-compat` runtime shims, and the types-only `./rntl-matchers`. Each of the runtime ones
|
|
52
|
+
depends on Vitest, which throws when it is reached through `require()`, so shipping a transpiled
|
|
53
|
+
CommonJS build for them produced files that could not be loaded at all. They now declare a single
|
|
54
|
+
ESM target for both conditions: a CommonJS consumer still reaches them, through Node's `require(esm)`
|
|
55
|
+
support. That is why `engines` pins Node >= 20.19 rather than >= 20.
|
|
56
|
+
|
|
57
|
+
The remaining four subpaths ship a real CommonJS build and are checked with `cjs-resolves-to-esm`
|
|
58
|
+
enforced, so a dual entry cannot quietly lose its `.cjs`. Which subpaths are intentionally ESM-only
|
|
59
|
+
is declared in `scripts/check-exports.mjs` and checked against the manifest in both directions;
|
|
60
|
+
deriving that split from the manifest instead was verified not to work, because dropping a `.cjs`
|
|
61
|
+
simply moved the entry into the excused bucket.
|
|
62
|
+
|
|
63
|
+
Resolution is not execution: `tests/package-exports.test.ts` additionally loads every declared
|
|
64
|
+
target, and resolves and loads every subpath by specifier under both `require` and `import`.
|
|
47
65
|
|
|
48
66
|
## Release decision
|
|
49
67
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Versioning and stability
|
|
2
|
+
|
|
3
|
+
This document is the semver contract: what a major, minor, or patch release is allowed to change.
|
|
4
|
+
|
|
5
|
+
[`release-readiness.md`](./release-readiness.md) is the companion document. It defines what is
|
|
6
|
+
*tested* before a release ships. This one defines what is *promised* about the surface those tests
|
|
7
|
+
cover.
|
|
8
|
+
|
|
9
|
+
Until 1.0, the contract below describes intent and is honoured on a best-effort basis; breaking
|
|
10
|
+
changes are called out in release notes. **At 1.0 it becomes binding**, and everything in
|
|
11
|
+
[Covered surface](#covered-surface) is protected by semver.
|
|
12
|
+
|
|
13
|
+
## Covered surface
|
|
14
|
+
|
|
15
|
+
These are the things a major release may break, a minor may only extend, and a patch may not change
|
|
16
|
+
at all. Anything not listed here is not covered — see [Outside the contract](#outside-the-contract).
|
|
17
|
+
|
|
18
|
+
### Entry points
|
|
19
|
+
|
|
20
|
+
Only the subpaths declared in `exports` are public. Nothing under `dist/` is importable directly,
|
|
21
|
+
and deep paths are not supported even when they happen to resolve.
|
|
22
|
+
|
|
23
|
+
| Subpath | Covered exports |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `vitest-native` | `reactNative`, `presets`, `disabledPresetNames` |
|
|
26
|
+
| `vitest-native/helpers` | `setPlatform`, `setDimensions`, `setColorScheme`, `setInsets`, `mockNativeModule`, `resetAllMocks` |
|
|
27
|
+
| `vitest-native/presets` | the 16 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
|
+
|
|
34
|
+
The module format of an entry point is part of the contract: an entry that is loadable from
|
|
35
|
+
CommonJS stays loadable from CommonJS. Which entries those are is enforced by `check:exports`, and
|
|
36
|
+
every subpath is loaded by specifier under both `require` and `import` in
|
|
37
|
+
`tests/package-exports.test.ts`.
|
|
38
|
+
|
|
39
|
+
### Plugin options
|
|
40
|
+
|
|
41
|
+
The keys accepted by the plugin function are `engine`, `platform`, `presets`, `mocks`,
|
|
42
|
+
`diagnostics`, `assetExts`, `transform`, `hotRuntime`. Their accepted types and their defaults are
|
|
43
|
+
covered. An unknown key is rejected at configuration time, so adding a key is a minor and removing
|
|
44
|
+
or renaming one is a major.
|
|
45
|
+
|
|
46
|
+
`hotRuntime` is the exception — see [Experimental](#experimental).
|
|
47
|
+
|
|
48
|
+
### Preset authoring
|
|
49
|
+
|
|
50
|
+
The `Preset` and `PresetModule` types are a public extension point: third-party presets can be
|
|
51
|
+
written and passed to `presets: [...]`. Covered: the shape `{ name, modules, config? }`, that
|
|
52
|
+
`PresetModule.exports` is read at config time, and that `PresetModule.factory` is called only
|
|
53
|
+
inside a Vitest worker.
|
|
54
|
+
|
|
55
|
+
`factory` may gain optional parameters in a minor, since that does not break an existing
|
|
56
|
+
zero-argument factory. Its return type and call site will not change without a major.
|
|
57
|
+
|
|
58
|
+
### Error codes
|
|
59
|
+
|
|
60
|
+
Thrown errors carry a stable `code`. The `code` values and the error classes are covered; the
|
|
61
|
+
human-readable `message` text is not.
|
|
62
|
+
|
|
63
|
+
### CLI
|
|
64
|
+
|
|
65
|
+
The command names `doctor`, `init`, and `migrate`, their documented flags, and their exit codes.
|
|
66
|
+
The wording and layout of what they print is not covered.
|
|
67
|
+
|
|
68
|
+
## Outside the contract
|
|
69
|
+
|
|
70
|
+
Changing any of these is a patch or minor, and never requires a major.
|
|
71
|
+
|
|
72
|
+
- **The wording of any message** — diagnostics, warnings, `doctor`/`init`/`migrate` output, and
|
|
73
|
+
error `message` strings. Assert on error `code`, not on text.
|
|
74
|
+
- **What a preset mocks.** Presets track upstream libraries. When `react-native-reanimated` adds an
|
|
75
|
+
export, the preset gains it in a minor; when upstream removes one, the preset drops it in a minor.
|
|
76
|
+
The preset's *existence and name* are covered; its mocked surface follows upstream.
|
|
77
|
+
- **Mock-engine fidelity details.** The mock engine's job is to match real React Native. A change
|
|
78
|
+
that moves it *closer* to real RN is a fix, even if a test was relying on the divergence. The
|
|
79
|
+
cross-check corpus and `crosscheck/known-differences.json` record where the two intentionally
|
|
80
|
+
differ.
|
|
81
|
+
- **Anything reachable only by deep import** into `dist/`.
|
|
82
|
+
- **Internal cache layout** under `node_modules/.cache/vitest-native`.
|
|
83
|
+
|
|
84
|
+
## Experimental
|
|
85
|
+
|
|
86
|
+
Experimental surfaces are excluded from the contract at every version, including after 1.0. They
|
|
87
|
+
are documented, tested, and gated in CI — they are simply not stable, and they say so.
|
|
88
|
+
|
|
89
|
+
| Surface | Why |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `hotRuntime` and its options | Built on Vitest's experimental custom-pool API, which can change between Vitest minors. Off by default. |
|
|
92
|
+
|
|
93
|
+
A surface leaves this list by being promoted in a minor, and can change or be removed in a minor
|
|
94
|
+
while it is on it.
|
|
95
|
+
|
|
96
|
+
## Upstream support ranges
|
|
97
|
+
|
|
98
|
+
`vitest-native` sits between several fast-moving projects — Node, Vite, Vitest, React, React
|
|
99
|
+
Native, and React Native Testing Library. Treating every peer-range change as a major would make
|
|
100
|
+
the package unable to keep up, which is the main way a tool like this dies. So peer ranges are
|
|
101
|
+
handled explicitly:
|
|
102
|
+
|
|
103
|
+
- **Adding support** for a new upstream version is a **minor**.
|
|
104
|
+
- **Dropping a version that upstream has already end-of-lifed** is a **minor**, announced in the
|
|
105
|
+
release notes. The package does not promise to outlive its own dependencies.
|
|
106
|
+
- **Dropping a version upstream still supports** is a **major**.
|
|
107
|
+
- **Raising the Node floor** is a **minor** when the versions dropped are end-of-life, and a
|
|
108
|
+
**major** otherwise.
|
|
109
|
+
|
|
110
|
+
The currently supported ranges are in [Requirements](../README.md#requirements) and the blocking
|
|
111
|
+
matrix in [`release-readiness.md`](./release-readiness.md#blocking-compatibility-matrix). Those are
|
|
112
|
+
the authoritative lists; this document only says how they may move.
|
|
113
|
+
|
|
114
|
+
## Deprecation
|
|
115
|
+
|
|
116
|
+
1. A deprecated surface keeps working and gains a runtime warning naming the replacement, plus a
|
|
117
|
+
note in the docs and release notes. This happens in a **minor**.
|
|
118
|
+
2. It is removed no earlier than the **next major**.
|
|
119
|
+
|
|
120
|
+
Something can only be removed without this cycle if it never worked — an entry point that always
|
|
121
|
+
threw, for example, is a bug being fixed, not an API being removed.
|
|
122
|
+
|
|
123
|
+
## What 1.0 means
|
|
124
|
+
|
|
125
|
+
1.0 is not a statement that the code has stopped changing. It is a statement that:
|
|
126
|
+
|
|
127
|
+
- the surface above is enumerated, deliberate, and protected by semver;
|
|
128
|
+
- the parts that are not stable are labelled, rather than silently included;
|
|
129
|
+
- the tests and gates in [`release-readiness.md`](./release-readiness.md) are what stand behind the
|
|
130
|
+
promise, and each one checks the thing it claims to check.
|
|
131
|
+
|
|
132
|
+
Reaching it does not require new features. It requires the surface to be exactly what this document
|
|
133
|
+
says it is.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,19 +24,13 @@
|
|
|
24
24
|
"expo",
|
|
25
25
|
"react"
|
|
26
26
|
],
|
|
27
|
-
"main": "./dist/index.
|
|
27
|
+
"main": "./dist/index.mjs",
|
|
28
28
|
"module": "./dist/index.mjs",
|
|
29
29
|
"types": "./dist/index.d.mts",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"default": "./dist/index.mjs"
|
|
35
|
-
},
|
|
36
|
-
"require": {
|
|
37
|
-
"types": "./dist/index.d.cts",
|
|
38
|
-
"default": "./dist/index.cjs"
|
|
39
|
-
}
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
40
34
|
},
|
|
41
35
|
"./helpers": {
|
|
42
36
|
"import": {
|
|
@@ -49,14 +43,8 @@
|
|
|
49
43
|
}
|
|
50
44
|
},
|
|
51
45
|
"./setup": {
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"default": "./dist/setup.mjs"
|
|
55
|
-
},
|
|
56
|
-
"require": {
|
|
57
|
-
"types": "./dist/setup.d.cts",
|
|
58
|
-
"default": "./dist/setup.cjs"
|
|
59
|
-
}
|
|
46
|
+
"types": "./dist/setup.d.mts",
|
|
47
|
+
"default": "./dist/setup.mjs"
|
|
60
48
|
},
|
|
61
49
|
"./serializer": {
|
|
62
50
|
"import": {
|
|
@@ -69,14 +57,8 @@
|
|
|
69
57
|
}
|
|
70
58
|
},
|
|
71
59
|
"./presets": {
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
"default": "./dist/presets.mjs"
|
|
75
|
-
},
|
|
76
|
-
"require": {
|
|
77
|
-
"types": "./dist/presets.d.cts",
|
|
78
|
-
"default": "./dist/presets.cjs"
|
|
79
|
-
}
|
|
60
|
+
"types": "./dist/presets.d.mts",
|
|
61
|
+
"default": "./dist/presets.mjs"
|
|
80
62
|
},
|
|
81
63
|
"./matchers": {
|
|
82
64
|
"import": {
|
|
@@ -109,6 +91,9 @@
|
|
|
109
91
|
"./jest-compat/extend-expect-noop": {
|
|
110
92
|
"types": "./dist/jest-compat/noop.d.mts",
|
|
111
93
|
"import": "./dist/jest-compat/noop.mjs"
|
|
94
|
+
},
|
|
95
|
+
"./rntl-matchers": {
|
|
96
|
+
"types": "./dist/rntl-matchers.d.ts"
|
|
112
97
|
}
|
|
113
98
|
},
|
|
114
99
|
"files": [
|
|
@@ -118,10 +103,9 @@
|
|
|
118
103
|
"CHANGELOG.md"
|
|
119
104
|
],
|
|
120
105
|
"engines": {
|
|
121
|
-
"node": ">=20"
|
|
106
|
+
"node": ">=20.19.0"
|
|
122
107
|
},
|
|
123
108
|
"sideEffects": [
|
|
124
|
-
"./dist/setup.cjs",
|
|
125
109
|
"./dist/setup.mjs",
|
|
126
110
|
"./dist/jest-compat/setup.mjs",
|
|
127
111
|
"./dist/native/*.mjs"
|
|
@@ -132,7 +116,7 @@
|
|
|
132
116
|
"peerDependencies": {
|
|
133
117
|
"react": ">=18",
|
|
134
118
|
"vite": "^6.4.2 || ^7.3.2 || ^8.0.5",
|
|
135
|
-
"vitest": ">=4 <
|
|
119
|
+
"vitest": ">=4 <6",
|
|
136
120
|
"@testing-library/react-native": ">=12 <15",
|
|
137
121
|
"@react-native/babel-preset": "*",
|
|
138
122
|
"@babel/core": "*"
|
|
@@ -160,31 +144,41 @@
|
|
|
160
144
|
"@testing-library/react-native": "14.0.0",
|
|
161
145
|
"@types/node": "25.3.5",
|
|
162
146
|
"@types/react": "19.2.14",
|
|
163
|
-
"@vitest/coverage-v8": "4.1.
|
|
147
|
+
"@vitest/coverage-v8": "4.1.9",
|
|
164
148
|
"expo-constants": "56.0.16",
|
|
165
149
|
"expo-status-bar": "56.0.4",
|
|
166
150
|
"ext-platform-lib": "file:./tests-native/fixtures/ext-platform-lib",
|
|
167
151
|
"ext-rn-named-lib": "file:./tests-native/fixtures/ext-rn-named-lib",
|
|
168
|
-
"
|
|
152
|
+
"generic-mainfield-lib": "file:./tests-native/fixtures/generic-mainfield-lib",
|
|
153
|
+
"react": "^19.2.8",
|
|
169
154
|
"react-native": "^0.86.0",
|
|
170
155
|
"react-native-gesture-handler": "3.0.0",
|
|
171
156
|
"react-native-keyboard-controller": "1.21.11",
|
|
172
157
|
"react-native-reanimated": "4.3.1",
|
|
173
158
|
"react-native-safe-area-context": "5.8.0",
|
|
174
159
|
"react-native-worklets": "0.9.1",
|
|
175
|
-
"react-test-renderer": "^19.2.
|
|
160
|
+
"react-test-renderer": "^19.2.8",
|
|
161
|
+
"resident-singleton": "file:./tests-native/fixtures/resident-singleton",
|
|
162
|
+
"rn-condition-lib": "file:./tests-native/fixtures/rn-condition-lib",
|
|
163
|
+
"rn-ecosystem-lib": "file:./tests-native/fixtures/rn-ecosystem-lib",
|
|
164
|
+
"rn-mainfield-lib": "file:./tests-native/fixtures/rn-mainfield-lib",
|
|
165
|
+
"rn-platform-flow-lib": "file:./tests-native/fixtures/rn-platform-flow-lib",
|
|
166
|
+
"rn-singleton-lib": "file:./tests-native/fixtures/rn-singleton-lib",
|
|
176
167
|
"test-renderer": "^1.2.0",
|
|
177
168
|
"tsdown": "0.21.10",
|
|
178
169
|
"typescript": "6.0.3",
|
|
170
|
+
"untranspiled-jsx-lib": "file:./tests-native/fixtures/untranspiled-jsx-lib",
|
|
179
171
|
"vite": "^8.0.5",
|
|
180
|
-
"vitest": "
|
|
172
|
+
"vitest": "4.1.9"
|
|
181
173
|
},
|
|
182
174
|
"scripts": {
|
|
183
|
-
"build": "tsdown",
|
|
175
|
+
"build": "tsdown && node scripts/copy-static-types.mjs",
|
|
184
176
|
"test": "vitest run",
|
|
185
177
|
"test:native": "vitest run --config tests-native/vitest.config.mts",
|
|
178
|
+
"test:native:forks": "vitest run --config tests-native/vitest.forks.config.mts",
|
|
186
179
|
"test:native:navigation": "vitest run --config tests-native/vitest.navigation.config.mts",
|
|
187
180
|
"test:native:android": "vitest run --config tests-native/vitest.android.config.mts",
|
|
181
|
+
"test:native:advice": "vitest run --config tests-native/vitest.advice.config.mts",
|
|
188
182
|
"test:native:hot": "vitest run --config tests-native/vitest.hot.config.mts",
|
|
189
183
|
"test:native:hot:isolation": "vitest run --config tests-native/vitest.hot-isolation.config.mts",
|
|
190
184
|
"test:native:hot:soak": "node scripts/test-hot-soak.mjs",
|
|
@@ -193,13 +187,21 @@
|
|
|
193
187
|
"format": "oxfmt --write src/ tests/ consumer-tests/ scripts/",
|
|
194
188
|
"format:check": "oxfmt --check src/ tests/ consumer-tests/ scripts/",
|
|
195
189
|
"check-compat": "bun scripts/check-compat.ts",
|
|
190
|
+
"check:size": "node scripts/check-package-size.mjs",
|
|
191
|
+
"check:exports": "node scripts/check-exports.mjs",
|
|
196
192
|
"typecheck": "tsc --noEmit",
|
|
197
193
|
"clean": "rm -rf dist",
|
|
198
|
-
"prepublishOnly": "bun run build && bun run test && bun run test:native && bun run test:native:navigation && bun run test:native:android && bun run test:native:hot && bun run test:native:hot:isolation && bun run test:native:hot:soak && bun run
|
|
199
|
-
"crosscheck": "node scripts/crosscheck.mjs"
|
|
194
|
+
"prepublishOnly": "bun run build && bun run check:size && bun run test && bun run test:native && bun run test:native:forks && bun run test:native:navigation && bun run test:native:android && bun run test:native:advice && bun run test:native:hot && bun run test:native:hot:isolation && bun run test:native:hot:soak && bun run validate:hot-parity && bun run fidelity:check && bun run test:consumers && bun run lint && bun run typecheck",
|
|
195
|
+
"crosscheck": "node scripts/crosscheck.mjs",
|
|
196
|
+
"fidelity:report": "node scripts/fidelity-report.mjs",
|
|
197
|
+
"fidelity:check": "node scripts/fidelity-report.mjs --check && node scripts/fidelity-matrix.mjs --check",
|
|
198
|
+
"validate:hot-parity": "node validation/idiomatic/scale/run-compare.mjs"
|
|
200
199
|
},
|
|
201
200
|
"dependencies": {
|
|
202
|
-
"flow-remove-types": "^2.
|
|
203
|
-
"magic-string": "^
|
|
201
|
+
"flow-remove-types": "^2.322.0",
|
|
202
|
+
"magic-string": "^1.1.0"
|
|
203
|
+
},
|
|
204
|
+
"bin": {
|
|
205
|
+
"vitest-native": "./dist/cli.mjs"
|
|
204
206
|
}
|
|
205
207
|
}
|