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.
- package/README.md +76 -60
- package/dist/cli.d.mts +1 -3
- package/dist/cli.mjs +175 -63
- package/dist/context.d.mts +45 -0
- package/dist/context.mjs +243 -0
- package/dist/errors.d.mts +3 -0
- package/dist/helpers.cjs +53 -4
- package/dist/helpers.d.cts +1 -3
- package/dist/helpers.d.mts +1 -3
- package/dist/helpers.mjs +2 -3
- package/dist/host-5o48Ujzs.mjs +939 -0
- package/dist/{index-CzQazgp9.d.cts → index-DqU4YO3D.d.mts} +27 -49
- package/dist/index.d.mts +1 -3
- package/dist/index.mjs +463 -595
- package/dist/jest-compat/error-equality.mjs +127 -0
- package/dist/jest-compat/jest-object.mjs +149 -4
- package/dist/jest-compat/node-registry.mjs +233 -58
- package/dist/jest-compat/setup.mjs +28 -4
- package/dist/jest-compat.cjs +227 -52
- package/dist/jest-compat.d.cts +5 -6
- package/dist/jest-compat.d.mts +5 -6
- package/dist/jest-compat.mjs +204 -52
- package/dist/matchers.cjs +1 -2
- package/dist/matchers.d.cts +0 -2
- package/dist/matchers.d.mts +0 -2
- package/dist/matchers.mjs +1 -2
- package/dist/{memory-FYbP0_gg.mjs → memory-Couw0Esx.mjs} +31 -6
- package/dist/native/assets.d.mts +2 -0
- package/dist/native/assets.mjs +34 -0
- package/dist/native/babel-toolchain.mjs +190 -0
- package/dist/native/babel-worker.mjs +47 -0
- package/dist/native/boundary.mjs +23 -8
- package/dist/native/compile-cache.mjs +21 -9
- package/dist/native/coverage-v8.mjs +287 -0
- package/dist/native/esm-interop.mjs +216 -0
- package/dist/native/expo-native-modules.mjs +7 -1
- package/dist/native/globals.mjs +104 -6
- package/dist/native/hooks.mjs +271 -60
- package/dist/native/loader.mjs +378 -20
- package/dist/native/match.d.mts +24 -2
- package/dist/native/match.mjs +117 -12
- package/dist/native/metro-profile-compiler.mjs +2 -31
- package/dist/native/module-reset.mjs +37 -5
- package/dist/native/native-modules.d.mts +2 -3
- package/dist/native/native-modules.mjs +22 -21
- package/dist/native/ownership.d.mts +10 -0
- package/dist/native/ownership.mjs +96 -9
- package/dist/native/registry-compiler.mjs +6 -0
- package/dist/native/registry.mjs +138 -119
- package/dist/native/resident-health.mjs +133 -0
- package/dist/native/resolve.d.mts +6 -0
- package/dist/native/resolve.mjs +100 -9
- package/dist/native/rntl-hooks.mjs +157 -6
- package/dist/native/rntl-text-host.mjs +64 -0
- package/dist/native/runner.mjs +73 -0
- package/dist/native/setup.mjs +96 -70
- package/dist/native/state-manifest.mjs +14 -8
- package/dist/native/transform.d.mts +2 -0
- package/dist/native/transform.mjs +476 -59
- package/dist/native/worker.mjs +65 -36
- package/dist/{pool-DjpOjOf3.mjs → pool-CFSpNfyw.mjs} +37 -11
- package/dist/{preset-map-BlBriTA0.mjs → preset-map-CogjYmSw.mjs} +4 -19
- package/dist/preset-modules.mjs +2 -11
- package/dist/{presets--zrEWQC2.mjs → presets-CXDyg51l.mjs} +65 -82
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/report-error.d.mts +20 -0
- package/dist/report-error.mjs +145 -0
- package/dist/rntl-support.d.mts +12 -0
- package/dist/rntl-support.mjs +189 -0
- package/dist/{rolldown-runtime-BhDjJH2R.mjs → rolldown-runtime-D70C1uOS.mjs} +1 -2
- package/dist/serializer.cjs +1 -2
- package/dist/serializer.d.cts +1 -3
- package/dist/serializer.d.mts +1 -3
- package/dist/serializer.mjs +1 -2
- package/dist/setup.mjs +95 -156
- package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-CILPFeRX.mjs} +2 -3
- package/docs/migrating-from-jest.md +76 -12
- package/docs/release-readiness.md +1 -1
- package/package.json +119 -102
- package/CHANGELOG.md +0 -2491
- package/dist/cli.cjs +0 -1951
- package/dist/cli.d.cts +0 -3
- package/dist/ecosystem-D6e1OVOg.mjs +0 -1019
- package/dist/ecosystem-MFwkbnaC.cjs +0 -1099
- package/dist/errors-B3lJK46O.cjs +0 -75
- package/dist/errors-CxoBUfVJ.mjs +0 -64
- package/dist/index-xw43lBlv.d.mts +0 -481
- package/dist/memory-6EPHrJA1.cjs +0 -144
- package/dist/pool-B4yesGhI.cjs +0 -121
- package/dist/preset-map-jSFsNy1Q.cjs +0 -241
- package/dist/preset-modules-BoLkaeEN.cjs +0 -53
- package/dist/preset-modules-CG8-G82P.mjs +0 -36
- package/dist/presets-9f83H0WW.cjs +0 -3939
- package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
- package/dist/worker-vitest-BfiQB8ND.cjs +0 -62
- package/docs/hot-default-design.md +0 -216
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// React Native Testing Library behaviour that RNTL only provides under Jest-style
|
|
2
|
+
// globals, installed by both engines' setup files. Plain .mjs, shipped verbatim: the
|
|
3
|
+
// native runtime (native/setup.mjs, native/rntl-hooks.mjs) imports it by relative path,
|
|
4
|
+
// and the mock engine's bundled setup.ts imports the same source. The two copies share
|
|
5
|
+
// state only through the global symbol below, never through module identity.
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import Module from "node:module";
|
|
8
|
+
import { setImmediate as realSetImmediate } from "node:timers";
|
|
9
|
+
|
|
10
|
+
/** RNTL's package entry: `build/index.js` (12, 13) or `dist/index.js` (14). */
|
|
11
|
+
export const RNTL_ENTRY =
|
|
12
|
+
/[\\/]node_modules[\\/]@testing-library[\\/]react-native[\\/](?:build|dist)[\\/]index\.js$/;
|
|
13
|
+
|
|
14
|
+
// Per-file auto-cleanup state, created by installRntlAutoCleanup. When files share a
|
|
15
|
+
// worker, native/rntl-hooks.mjs and native/hooks.mjs add the RNTL entries a file loads
|
|
16
|
+
// to `imported`.
|
|
17
|
+
const AUTO_CLEANUP = Symbol.for("vitest-native.rntl-auto-cleanup");
|
|
18
|
+
|
|
19
|
+
// The key Node's module cache holds `file` under, if it is cached.
|
|
20
|
+
function cacheKeyOf(file) {
|
|
21
|
+
if (Module._cache[file]) return file;
|
|
22
|
+
try {
|
|
23
|
+
const real = fs.realpathSync(file);
|
|
24
|
+
return Module._cache[real] ? real : null;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The RNTL entries the running test file's own module graph imports, read from
|
|
32
|
+
* Vitest's evaluated-module graph: the modules Vite evaluates, and for each module it
|
|
33
|
+
* externalizes to Node, that module and the modules it required directly (a shared
|
|
34
|
+
* test-utils that re-exports RNTL). With `isolate: false` and no hot runtime both the
|
|
35
|
+
* graph and Node's module cache persist across files, so a later file's import loads
|
|
36
|
+
* nothing again; the graph still records that the file imports it.
|
|
37
|
+
*/
|
|
38
|
+
function rntlEntriesInFileGraph() {
|
|
39
|
+
const worker = globalThis.__vitest_worker__;
|
|
40
|
+
const modules = worker?.evaluatedModules;
|
|
41
|
+
if (typeof worker?.filepath !== "string" || typeof modules?.getModuleById !== "function") {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const found = [];
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const queue = [...(modules.getModulesByFile?.(worker.filepath) ?? [])];
|
|
47
|
+
while (queue.length > 0) {
|
|
48
|
+
const node = queue.pop();
|
|
49
|
+
if (!node || seen.has(node)) continue;
|
|
50
|
+
seen.add(node);
|
|
51
|
+
const external = node.meta?.externalize;
|
|
52
|
+
if (typeof external === "string") {
|
|
53
|
+
const key = cacheKeyOf(external);
|
|
54
|
+
if (!key) continue;
|
|
55
|
+
if (RNTL_ENTRY.test(key)) found.push(key);
|
|
56
|
+
for (const child of Module._cache[key].children ?? []) {
|
|
57
|
+
if (RNTL_ENTRY.test(child.id)) found.push(child.id);
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
for (const id of node.imports ?? []) queue.push(modules.getModuleById(id));
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register RNTL's automatic cleanup through Vitest's `afterEach` when RNTL cannot.
|
|
68
|
+
*
|
|
69
|
+
* RNTL's entry registers it only if `afterEach` is a global (12.9 build/index.js:25,
|
|
70
|
+
* 13.3 build/index.js:27, 14.1 dist/index.js:26: `if (typeof afterEach === 'function')`).
|
|
71
|
+
* Vitest defines its globals only with `test.globals: true`, so with Vitest's default
|
|
72
|
+
* every rendered tree stayed mounted for the rest of the file: `screen` and later
|
|
73
|
+
* queries saw earlier tests' screens, and their effects kept running. With globals on,
|
|
74
|
+
* RNTL registers its own hook and nothing is added here.
|
|
75
|
+
*
|
|
76
|
+
* The hook does what RNTL's would, and only when RNTL's would exist:
|
|
77
|
+
* - only if this file loaded RNTL's main entry. Importing
|
|
78
|
+
* `@testing-library/react-native/pure` is RNTL's documented opt-out, so the setup
|
|
79
|
+
* files never load the entry themselves and it is detected lazily, when the hook runs;
|
|
80
|
+
* - not when RNTL_SKIP_AUTO_CLEANUP is set, tested by truthiness as RNTL does
|
|
81
|
+
* (12.9 build/index.js:19, 13.3 :21, 14.1 dist/index.js:20); its
|
|
82
|
+
* `dont-cleanup-after-each` module sets it;
|
|
83
|
+
* - the cleanup each version's own hook calls: 12's synchronous `cleanup`
|
|
84
|
+
* (12.9 build/index.js:29), 13's `cleanupAsync` (13.3 build/index.js:30; its
|
|
85
|
+
* `cleanup` is the synchronous one), and 14's `cleanup`, which is async and has no
|
|
86
|
+
* `cleanupAsync` (14.1 dist/index.js:29, dist/cleanup.js:11);
|
|
87
|
+
* - after one macrotask turn, as RNTL's `flushMicroTasks` (13.3/14.1
|
|
88
|
+
* flush-micro-tasks.js:9) or 12's `flushMicroTasksLegacy` (12.9 :27) wait. RNTL uses
|
|
89
|
+
* the `setImmediate` it captured when it loaded (12.9/13.3 build/helpers/timers.js:67,
|
|
90
|
+
* 14.1 dist/helpers/timers.js:74), not the current one, so a test that ends with fake
|
|
91
|
+
* timers still installed does not hang its cleanup. This hook's own wait uses
|
|
92
|
+
* `node:timers`' `setImmediate`, which Vitest's fake timers never replace: a capture
|
|
93
|
+
* of the global when the setup file runs is not enough, because under
|
|
94
|
+
* `isolate: false` Vitest leaves the previous file's fake timers installed, so the
|
|
95
|
+
* setup file of a later file would capture a fake one and every cleanup would hang. (That RNTL's capture is the
|
|
96
|
+
* real one even when fake timers are on at load is native/rntl-hooks.mjs's `jest`.)
|
|
97
|
+
*
|
|
98
|
+
* Order: Vitest runs `afterEach` hooks in reverse order of registration (its default
|
|
99
|
+
* `sequence.hooks: 'stack'`), and a setup file registers before the test file, so this
|
|
100
|
+
* cleanup runs after the file's own `afterEach` hooks. That is where RNTL's own hook
|
|
101
|
+
* runs under Vitest with `test.globals: true` too, since the entry registers it on
|
|
102
|
+
* import. Jest runs RNTL's cleanup before the file's hooks, so an `afterEach` that
|
|
103
|
+
* expects the tree to be unmounted already sees it still mounted here.
|
|
104
|
+
*
|
|
105
|
+
* RNTL's entry also pairs `beforeAll`/`afterAll` to set React's act environment for the
|
|
106
|
+
* file (12.9 build/index.js:32). Both engines set IS_REACT_ACT_ENVIRONMENT for every
|
|
107
|
+
* file already, so that pair is not reproduced.
|
|
108
|
+
*
|
|
109
|
+
* @param {(fn: () => Promise<void>) => void} afterEach Vitest's `afterEach`.
|
|
110
|
+
* @param {{ trackImports?: boolean }} [options] `trackImports`: set when files share a
|
|
111
|
+
* worker (the hot runtime, or `isolate: false`). RNTL then stays in Node's module
|
|
112
|
+
* cache across files, so the cache cannot tell whether this file loaded it, and a
|
|
113
|
+
* `/pure` file after one that imported the entry would be cleaned up. Instead the
|
|
114
|
+
* entries this file loads are recorded (native/rntl-hooks.mjs for its imports, and
|
|
115
|
+
* noteIfRntlEntryLoaded for Node's requires) and its module graph is read
|
|
116
|
+
* (rntlEntriesInFileGraph).
|
|
117
|
+
*/
|
|
118
|
+
export function installRntlAutoCleanup(afterEach, { trackImports = false } = {}) {
|
|
119
|
+
if (typeof globalThis.afterEach === "function") return;
|
|
120
|
+
const state = { imported: trackImports ? new Set() : null };
|
|
121
|
+
Object.defineProperty(globalThis, AUTO_CLEANUP, {
|
|
122
|
+
configurable: true,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
value: state,
|
|
125
|
+
writable: true,
|
|
126
|
+
});
|
|
127
|
+
afterEach(async () => {
|
|
128
|
+
if (process.env.RNTL_SKIP_AUTO_CLEANUP) return;
|
|
129
|
+
const entries = [];
|
|
130
|
+
const files = state.imported
|
|
131
|
+
? new Set([...state.imported, ...rntlEntriesInFileGraph()])
|
|
132
|
+
: Object.keys(Module._cache);
|
|
133
|
+
for (const file of files) {
|
|
134
|
+
if (!file.endsWith("index.js") || !RNTL_ENTRY.test(file)) continue;
|
|
135
|
+
const rntl = Module._cache[file]?.exports;
|
|
136
|
+
const cleanup = rntl?.cleanupAsync ?? rntl?.cleanup;
|
|
137
|
+
if (typeof cleanup === "function") entries.push(cleanup);
|
|
138
|
+
}
|
|
139
|
+
if (entries.length === 0) return;
|
|
140
|
+
await new Promise((resolve) => realSetImmediate(resolve));
|
|
141
|
+
for (const cleanup of entries) await cleanup();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Record the RNTL entry whose `exports` a `require` just returned, cached or not, if
|
|
147
|
+
* installRntlAutoCleanup is tracking loads for this file. Called with every require's
|
|
148
|
+
* result, so anything that is not an RNTL entry's exports leaves after two property
|
|
149
|
+
* checks; the cache is searched only for an object with RNTL's `render` and `cleanup`.
|
|
150
|
+
* @param {unknown} exports
|
|
151
|
+
*/
|
|
152
|
+
export function noteIfRntlEntryLoaded(exports) {
|
|
153
|
+
if (exports === null || typeof exports !== "object") return;
|
|
154
|
+
if (!globalThis[AUTO_CLEANUP]?.imported) return;
|
|
155
|
+
if (typeof exports.render !== "function" || typeof exports.cleanup !== "function") return;
|
|
156
|
+
for (const key of Object.keys(Module._cache)) {
|
|
157
|
+
if (RNTL_ENTRY.test(key) && Module._cache[key].exports === exports) {
|
|
158
|
+
noteRntlEntryImported(key);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const LOAD_TRACKED = Symbol.for("vitest-native.rntl-load-tracking");
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Report every require's result to noteIfRntlEntryLoaded, for an engine without its
|
|
167
|
+
* own require hook (the mock engine; the native engine calls it from hooks.mjs). Wraps
|
|
168
|
+
* `Module._load` once per worker.
|
|
169
|
+
*/
|
|
170
|
+
export function installRntlLoadTracking() {
|
|
171
|
+
if (Module._load[LOAD_TRACKED]) return;
|
|
172
|
+
const load = Module._load;
|
|
173
|
+
const tracked = function (...args) {
|
|
174
|
+
const exports = load.apply(this, args);
|
|
175
|
+
noteIfRntlEntryLoaded(exports);
|
|
176
|
+
return exports;
|
|
177
|
+
};
|
|
178
|
+
tracked[LOAD_TRACKED] = true;
|
|
179
|
+
Module._load = tracked;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Record that the current file imported the RNTL entry cached under `file`. A no-op
|
|
184
|
+
* unless installRntlAutoCleanup is tracking imports for this file.
|
|
185
|
+
* @param {string} file
|
|
186
|
+
*/
|
|
187
|
+
export function noteRntlEntryImported(file) {
|
|
188
|
+
globalThis[AUTO_CLEANUP]?.imported?.add(file);
|
|
189
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __exportAll = (all, no_symbols) => {
|
|
5
5
|
let target = {};
|
|
@@ -11,5 +11,4 @@ var __exportAll = (all, no_symbols) => {
|
|
|
11
11
|
return target;
|
|
12
12
|
};
|
|
13
13
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
14
|
-
//#endregion
|
|
15
14
|
export { __require as n, __exportAll as t };
|
package/dist/serializer.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// src/serializer.ts
|
|
3
3
|
/**
|
|
4
4
|
* Vitest snapshot serializer for React Native components.
|
|
5
5
|
*
|
|
@@ -146,5 +146,4 @@ const serializer = {
|
|
|
146
146
|
return result;
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
|
-
//#endregion
|
|
150
149
|
exports.serializer = serializer;
|
package/dist/serializer.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/serializer.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Vitest snapshot serializer for React Native components.
|
|
4
3
|
*
|
|
@@ -11,5 +10,4 @@ export interface SnapshotSerializer {
|
|
|
11
10
|
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
11
|
test(val: any): boolean;
|
|
13
12
|
}
|
|
14
|
-
export declare const serializer: SnapshotSerializer;
|
|
15
|
-
//#endregion
|
|
13
|
+
export declare const serializer: SnapshotSerializer;
|
package/dist/serializer.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/serializer.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Vitest snapshot serializer for React Native components.
|
|
4
3
|
*
|
|
@@ -11,5 +10,4 @@ export interface SnapshotSerializer {
|
|
|
11
10
|
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
11
|
test(val: any): boolean;
|
|
13
12
|
}
|
|
14
|
-
export declare const serializer: SnapshotSerializer;
|
|
15
|
-
//#endregion
|
|
13
|
+
export declare const serializer: SnapshotSerializer;
|
package/dist/serializer.mjs
CHANGED