vitest-native 0.9.0 → 0.11.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 +921 -0
- package/README.md +33 -1
- package/dist/cli.cjs +185 -31
- package/dist/cli.mjs +182 -28
- package/dist/ecosystem-BJzJU3Cf.cjs +568 -0
- package/dist/ecosystem-C4qT_vl3.mjs +506 -0
- package/dist/errors-B3lJK46O.cjs +75 -0
- package/dist/errors-CxoBUfVJ.mjs +64 -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-CEgRDdhd.d.cts → index-CrMeE8rd.d.mts} +14 -9
- package/dist/{index-j-0tueBr.d.mts → index-DIMbjH8R.d.cts} +15 -7
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +307 -91
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +102 -7
- package/dist/jest-compat.cjs +4 -4
- package/dist/jest-compat.d.cts +0 -1
- package/dist/jest-compat.d.mts +0 -1
- package/dist/jest-compat.mjs +2 -2
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/hooks.mjs +152 -13
- package/dist/native/loader.mjs +36 -11
- package/dist/native/match.d.mts +33 -0
- package/dist/native/match.mjs +94 -22
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +110 -13
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +21 -0
- package/dist/native/setup.mjs +4 -2
- package/dist/native/transform.mjs +108 -3
- package/dist/native/worker.mjs +59 -16
- package/dist/{pool-DzsEo9vv.cjs → pool-BU-1ecIF.cjs} +7 -6
- package/dist/{pool-CJmjRgsB.mjs → pool-Bcxn9a3I.mjs} +4 -3
- package/dist/{preset-map-CG4FMtsl.cjs → preset-map-BoG19dLa.cjs} +1 -1
- package/dist/{preset-map-CNsZKfvu.mjs → preset-map-DuX0ocdn.mjs} +1 -1
- package/dist/{presets-C4faM3ds.cjs → presets-CwO_c4aL.cjs} +224 -55
- package/dist/{presets-CuDrNA_W.mjs → presets-IStcJEOa.mjs} +216 -53
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/{chunk-CjcI7cDX.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
- package/dist/{chunk-CZWwpsFl.cjs → rolldown-runtime-C0BPl7ul.cjs} +1 -1
- package/dist/serializer.cjs +34 -4
- package/dist/serializer.mjs +34 -4
- package/dist/setup.d.mts +1 -1
- package/dist/setup.mjs +237 -74
- package/docs/release-readiness.md +22 -5
- package/docs/versioning.md +133 -0
- package/package.json +38 -46
- package/dist/ecosystem-BIWaVwYL.cjs +0 -294
- package/dist/ecosystem-EFtHnKS9.mjs +0 -256
- package/dist/index.cjs +0 -788
- package/dist/index.d.cts +0 -14
- package/dist/presets.cjs +0 -18
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2702
- package/dist/setup.d.cts +0 -1
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-CNsZKfvu.mjs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
//#region src/validate.ts
|
|
6
|
-
const KNOWN_OPTIONS = [
|
|
7
|
-
"platform",
|
|
8
|
-
"presets",
|
|
9
|
-
"mocks",
|
|
10
|
-
"diagnostics",
|
|
11
|
-
"assetExts",
|
|
12
|
-
"engine",
|
|
13
|
-
"transform",
|
|
14
|
-
"hotRuntime"
|
|
15
|
-
];
|
|
16
|
-
const KNOWN_HOT_RUNTIME_OPTIONS = [
|
|
17
|
-
"recycleAfterFiles",
|
|
18
|
-
"memoryLimit",
|
|
19
|
-
"preserveGlobals"
|
|
20
|
-
];
|
|
21
|
-
function assertStringArray(value, option) {
|
|
22
|
-
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.length === 0)) throw new TypeError(`[vitest-native] "${option}" must be an array of non-empty strings.`);
|
|
23
|
-
}
|
|
24
|
-
function assertNonNegativeInteger(value, option) {
|
|
25
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new TypeError(`[vitest-native] "${option}" must be a non-negative safe integer.`);
|
|
26
|
-
}
|
|
27
|
-
function validateOptions(options) {
|
|
28
|
-
if (options.engine !== void 0 && options.engine !== "auto" && options.engine !== "mock" && options.engine !== "native") throw new TypeError(`[vitest-native] "engine" must be "auto", "mock", or "native".`);
|
|
29
|
-
if (options.platform !== void 0 && options.platform !== "ios" && options.platform !== "android") throw new TypeError(`[vitest-native] "platform" must be "ios" or "android".`);
|
|
30
|
-
if (options.diagnostics !== void 0 && typeof options.diagnostics !== "boolean") throw new TypeError(`[vitest-native] "diagnostics" must be a boolean.`);
|
|
31
|
-
if (options.assetExts !== void 0) assertStringArray(options.assetExts, "assetExts");
|
|
32
|
-
if (options.transform !== void 0) assertStringArray(options.transform, "transform");
|
|
33
|
-
if (options.presets !== void 0 && !Array.isArray(options.presets)) throw new TypeError(`[vitest-native] "presets" must be an array.`);
|
|
34
|
-
if (options.mocks !== void 0 && (options.mocks === null || Array.isArray(options.mocks) || typeof options.mocks !== "object")) throw new TypeError(`[vitest-native] "mocks" must be a plain object.`);
|
|
35
|
-
const hotRuntime = options.hotRuntime;
|
|
36
|
-
if (hotRuntime === void 0 || typeof hotRuntime === "boolean") return;
|
|
37
|
-
if (hotRuntime === null || Array.isArray(hotRuntime) || typeof hotRuntime !== "object") throw new TypeError(`[vitest-native] "hotRuntime" must be a boolean or an options object.`);
|
|
38
|
-
const hotOptions = hotRuntime;
|
|
39
|
-
for (const key of Object.keys(hotOptions)) if (!KNOWN_HOT_RUNTIME_OPTIONS.includes(key)) throw new TypeError(`[vitest-native] Unknown hotRuntime option "${key}".`);
|
|
40
|
-
if (hotOptions.recycleAfterFiles !== void 0) assertNonNegativeInteger(hotOptions.recycleAfterFiles, "hotRuntime.recycleAfterFiles");
|
|
41
|
-
if (hotOptions.memoryLimit !== void 0) assertNonNegativeInteger(hotOptions.memoryLimit, "hotRuntime.memoryLimit");
|
|
42
|
-
if (hotOptions.preserveGlobals !== void 0) assertStringArray(hotOptions.preserveGlobals, "hotRuntime.preserveGlobals");
|
|
43
|
-
}
|
|
44
|
-
function satisfiesMinimum(version, minimum) {
|
|
45
|
-
const parse = (v) => v.replace(/^[^0-9]*/, "").split(/[-+]/)[0].split(".").map(Number);
|
|
46
|
-
const [aMaj, aMin = 0, aPat = 0] = parse(version);
|
|
47
|
-
const [bMaj, bMin = 0, bPat = 0] = parse(minimum);
|
|
48
|
-
if (aMaj !== bMaj) return aMaj > bMaj;
|
|
49
|
-
if (aMin !== bMin) return aMin > bMin;
|
|
50
|
-
return aPat >= bPat;
|
|
51
|
-
}
|
|
52
|
-
function validatePeerDependency(pkgName, minimumVersion, projectRoot, maximumMajorExclusive, minimumByMajor) {
|
|
53
|
-
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
54
|
-
try {
|
|
55
|
-
const { version } = req(req.resolve(`${pkgName}/package.json`));
|
|
56
|
-
const major = Number(version.replace(/^[^0-9]*/, "").split(".")[0]);
|
|
57
|
-
const requiredMinimum = minimumByMajor?.[major] ?? minimumVersion;
|
|
58
|
-
if (!satisfiesMinimum(version, requiredMinimum)) return `vitest-native requires ${pkgName} >= ${requiredMinimum} for ${major}.x, but found ${version}. Please upgrade.`;
|
|
59
|
-
if (maximumMajorExclusive !== void 0 && major >= maximumMajorExclusive) return `vitest-native supports ${pkgName} >= ${minimumVersion} and < ${maximumMajorExclusive}, but found ${version}.`;
|
|
60
|
-
return null;
|
|
61
|
-
} catch {
|
|
62
|
-
return `vitest-native requires ${pkgName} >= ${minimumVersion}, but it was not found. Please install it.`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function warnUnknownOptions(options) {
|
|
66
|
-
for (const key of Object.keys(options)) if (!KNOWN_OPTIONS.includes(key)) {
|
|
67
|
-
const suggestion = findClosest(key, KNOWN_OPTIONS);
|
|
68
|
-
const hint = suggestion ? ` Did you mean '${suggestion}'?` : "";
|
|
69
|
-
console.warn(`[vitest-native] Unknown option '${key}'.${hint}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function findClosest(input, candidates) {
|
|
73
|
-
let best = null;
|
|
74
|
-
let bestDist = Infinity;
|
|
75
|
-
for (const c of candidates) {
|
|
76
|
-
const d = levenshtein(input.toLowerCase(), c.toLowerCase());
|
|
77
|
-
if (d < bestDist && d <= 3) {
|
|
78
|
-
bestDist = d;
|
|
79
|
-
best = c;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return best;
|
|
83
|
-
}
|
|
84
|
-
function levenshtein(a, b) {
|
|
85
|
-
const m = a.length;
|
|
86
|
-
const n = b.length;
|
|
87
|
-
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
88
|
-
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
89
|
-
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
90
|
-
for (let i = 1; i <= m; i++) for (let j = 1; j <= n; j++) dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
91
|
-
return dp[m][n];
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/peer-requirements.ts
|
|
95
|
-
const PEER_REQUIREMENTS = [
|
|
96
|
-
{
|
|
97
|
-
name: "vitest",
|
|
98
|
-
minimum: "4.0.0",
|
|
99
|
-
maximumMajor: 6
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "vite",
|
|
103
|
-
minimum: "6.4.2",
|
|
104
|
-
maximumMajor: 9,
|
|
105
|
-
minimumByMajor: {
|
|
106
|
-
6: "6.4.2",
|
|
107
|
-
7: "7.3.2",
|
|
108
|
-
8: "8.0.5"
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: "react",
|
|
113
|
-
minimum: "18.0.0"
|
|
114
|
-
}
|
|
115
|
-
];
|
|
116
|
-
/** Can this project run the native engine? (Both transform deps resolvable.) */
|
|
117
|
-
function isNativeCapable(projectRoot) {
|
|
118
|
-
try {
|
|
119
|
-
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
120
|
-
req.resolve("@react-native/babel-preset");
|
|
121
|
-
req.resolve("@babel/core");
|
|
122
|
-
return true;
|
|
123
|
-
} catch {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/** Resolve the concrete engine for a run. Pure; never throws. */
|
|
128
|
-
function detectEngine(requested, projectRoot, opts) {
|
|
129
|
-
const nativeAvailable = isNativeCapable(projectRoot);
|
|
130
|
-
if (requested === "native") return {
|
|
131
|
-
engine: "native",
|
|
132
|
-
nativeAvailable,
|
|
133
|
-
notice: null
|
|
134
|
-
};
|
|
135
|
-
if (requested === "mock") return {
|
|
136
|
-
engine: "mock",
|
|
137
|
-
nativeAvailable,
|
|
138
|
-
notice: null
|
|
139
|
-
};
|
|
140
|
-
const prefersNative = opts?.autoPrefersNative ?? true;
|
|
141
|
-
if (prefersNative && nativeAvailable) return {
|
|
142
|
-
engine: "native",
|
|
143
|
-
nativeAvailable,
|
|
144
|
-
notice: null
|
|
145
|
-
};
|
|
146
|
-
if (prefersNative) return {
|
|
147
|
-
engine: "mock",
|
|
148
|
-
nativeAvailable: false,
|
|
149
|
-
notice: "[vitest-native] @react-native/babel-preset not found — using the mock engine. Install it (and @babel/core) to run real React Native, or set engine:'mock' to silence this."
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
engine: "mock",
|
|
153
|
-
nativeAvailable,
|
|
154
|
-
notice: null
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/native/ecosystem.ts
|
|
159
|
-
/**
|
|
160
|
-
* Packages that must never be auto-inlined even though they depend on React
|
|
161
|
-
* Native. The test library and the renderers underneath it are infrastructure the
|
|
162
|
-
* engine itself wires up; pulling a second copy of them into the module graph has
|
|
163
|
-
* corrupted rendering before, in ways that surface as unrelated act() and
|
|
164
|
-
* host-component failures.
|
|
165
|
-
*/
|
|
166
|
-
const NEVER_INLINE = new Set([
|
|
167
|
-
"@testing-library/react-native",
|
|
168
|
-
"react-test-renderer",
|
|
169
|
-
"test-renderer",
|
|
170
|
-
"react-native"
|
|
171
|
-
]);
|
|
172
|
-
/** Manifest fields that make a package part of the React Native ecosystem. */
|
|
173
|
-
function dependsOnReactNative(manifest) {
|
|
174
|
-
for (const field of ["dependencies", "peerDependencies"]) {
|
|
175
|
-
const deps = manifest[field];
|
|
176
|
-
if (deps && typeof deps === "object" && "react-native" in deps) return true;
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Every package manifest from the project up to the filesystem root.
|
|
182
|
-
*
|
|
183
|
-
* A workspace does not always declare its dependencies where the tests run: an app
|
|
184
|
-
* package may inherit React Native libraries from the repository root, and a Vitest
|
|
185
|
-
* `root` can point at a directory above or below the package that owns them. Reading
|
|
186
|
-
* only the project's own manifest silently found nothing in those layouts and sent
|
|
187
|
-
* the user back to maintaining `transform: [...]` by hand.
|
|
188
|
-
*
|
|
189
|
-
* Over-collecting is safe and under-collecting is not: a package that is listed but
|
|
190
|
-
* never imported costs nothing, because inlining only applies to files that are
|
|
191
|
-
* actually loaded.
|
|
192
|
-
*/
|
|
193
|
-
function manifestsFrom(projectRoot) {
|
|
194
|
-
const manifests = [];
|
|
195
|
-
let dir = path.resolve(projectRoot);
|
|
196
|
-
for (;;) {
|
|
197
|
-
try {
|
|
198
|
-
const raw = fs.readFileSync(path.join(dir, "package.json"), "utf8");
|
|
199
|
-
manifests.push(JSON.parse(raw));
|
|
200
|
-
} catch {}
|
|
201
|
-
const parent = path.dirname(dir);
|
|
202
|
-
if (parent === dir) return manifests;
|
|
203
|
-
dir = parent;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Packages in the project that declare React Native in their own manifest.
|
|
208
|
-
*
|
|
209
|
-
* These are the ones published the way the React Native ecosystem publishes:
|
|
210
|
-
* untranspiled JSX, Flow, or TypeScript, on the assumption that Metro will compile
|
|
211
|
-
* them. Node cannot run that source, which is why they previously had to be listed
|
|
212
|
-
* by hand in `transform: [...]` — a list every project had to discover the hard way,
|
|
213
|
-
* one `SyntaxError: Unexpected token '<'` at a time.
|
|
214
|
-
*
|
|
215
|
-
* A package's own manifest is the authority here rather than a heuristic on its
|
|
216
|
-
* name: `react-native-*` misses `@gorhom/bottom-sheet` and would wrongly claim
|
|
217
|
-
* `react-native` itself, while the manifest states the relationship exactly.
|
|
218
|
-
*
|
|
219
|
-
* Declared dependencies are read from the project and every manifest above it, so a
|
|
220
|
-
* workspace that declares its React Native libraries at the repository root is covered
|
|
221
|
-
* too. Resolving each name is cheap and package-manager-agnostic, where walking the
|
|
222
|
-
* installed tree depends on the store layout. Transitive dependencies that nothing
|
|
223
|
-
* declares stay available through `transform: [...]`.
|
|
224
|
-
*
|
|
225
|
-
* Excluded: packages a preset already shadows (their real source never loads), the
|
|
226
|
-
* test infrastructure in NEVER_INLINE, and anything the consumer listed explicitly
|
|
227
|
-
* in `transform` — that option keeps its existing meaning and takes precedence.
|
|
228
|
-
*/
|
|
229
|
-
function detectEcosystemPackages(projectRoot, explicit = []) {
|
|
230
|
-
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
231
|
-
const skip = new Set([
|
|
232
|
-
...NEVER_INLINE,
|
|
233
|
-
...Object.keys(AUTO_DETECT_PRESETS),
|
|
234
|
-
...explicit
|
|
235
|
-
]);
|
|
236
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
237
|
-
for (const manifest of manifestsFrom(projectRoot)) for (const field of [
|
|
238
|
-
"dependencies",
|
|
239
|
-
"devDependencies",
|
|
240
|
-
"optionalDependencies"
|
|
241
|
-
]) {
|
|
242
|
-
const deps = manifest[field];
|
|
243
|
-
if (deps && typeof deps === "object") for (const name of Object.keys(deps)) candidates.add(name);
|
|
244
|
-
}
|
|
245
|
-
if (candidates.size === 0) return [];
|
|
246
|
-
const detected = [];
|
|
247
|
-
for (const name of candidates) {
|
|
248
|
-
if (skip.has(name) || name.startsWith("@react-native/")) continue;
|
|
249
|
-
try {
|
|
250
|
-
if (dependsOnReactNative(req(`${name}/package.json`))) detected.push(name);
|
|
251
|
-
} catch {}
|
|
252
|
-
}
|
|
253
|
-
return detected.sort();
|
|
254
|
-
}
|
|
255
|
-
//#endregion
|
|
256
|
-
export { validatePeerDependency as a, validateOptions as i, detectEngine as n, warnUnknownOptions as o, PEER_REQUIREMENTS as r, detectEcosystemPackages as t };
|