vitest-native 0.14.0-rc.1 → 0.14.0-rc.3
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 +54 -0
- package/dist/index.mjs +102 -23
- package/dist/native/hooks.mjs +4 -1
- package/dist/native/resolve.d.mts +6 -0
- package/dist/native/resolve.mjs +22 -2
- package/dist/native/transform.mjs +28 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
`(platform ios, hot runtime)`. If a test passes on its own but fails alongside others, see
|
|
13
13
|
[troubleshooting](https://danfry1.github.io/vitest-native/guide/troubleshooting#a-test-passes-on-its-own-but-fails-when-run-with-other-files);
|
|
14
14
|
`hotRuntime: false` restores per-file isolation.
|
|
15
|
+
- **Expo path aliases resolve.** In an Expo project on Vite 8, imports through tsconfig `paths` (the
|
|
16
|
+
template's `@/…`) now resolve as Metro resolves them; a `vite-tsconfig-paths` plugin or a hand-written
|
|
17
|
+
alias for them can go.
|
|
15
18
|
- **`hotRuntime: true` is stricter.** Combined with a configured pool, `test.isolate`, or a conflicting
|
|
16
19
|
CLI flag, it now fails at startup with `HOT_RUNTIME_OVERRIDDEN` instead of warning and overriding.
|
|
17
20
|
|
|
@@ -55,6 +58,57 @@
|
|
|
55
58
|
|
|
56
59
|
### Patch Changes
|
|
57
60
|
|
|
61
|
+
- 2233866: Stop a circular-dependency warning on an Expo project's first run
|
|
62
|
+
|
|
63
|
+
Babel loads its presets and plugins with `require` during a transform, and those requires went
|
|
64
|
+
through the native engine's CommonJS hook like any other. `babel-plugin-syntax-hermes-parser` and
|
|
65
|
+
`hermes-parser`, which `@react-native/babel-preset` uses, keep an `@flow` header in their published
|
|
66
|
+
builds and sit under an `@react-native` package, so the hook sent them back through Babel
|
|
67
|
+
mid-transform. Babel then read a half-loaded plugin's exports and Node printed "Accessing
|
|
68
|
+
non-existent property 'then' of module exports inside circular dependency" on a cold cache, for
|
|
69
|
+
example on a fresh `create-expo-app` project. Code Babel loads during a transform now runs as
|
|
70
|
+
published, as it does under Jest.
|
|
71
|
+
|
|
72
|
+
- 84591de: Depend on `flow-remove-types` ^2.333.0 (was ^2.332.0).
|
|
73
|
+
|
|
74
|
+
- bb9cf45: Fix `./App` resolving to `app.json` on macOS and Windows
|
|
75
|
+
|
|
76
|
+
The React Native CLI template ships `App.tsx` and `app.json` side by side, and its own test
|
|
77
|
+
imports `../App`. Metro's extension order tries `.json` before `.tsx`, and macOS and Windows disks
|
|
78
|
+
are case-insensitive, so asking whether `App.json` exists answered yes for `app.json`. The template's
|
|
79
|
+
test then rendered `{ name, displayName }` and failed with "Element type is invalid … got: object",
|
|
80
|
+
while it passes under Jest. Metro resolves from a case-sensitive file map, and Linux CI is
|
|
81
|
+
case-sensitive, which is why neither caught it. Extensionless relative imports now match file
|
|
82
|
+
names exactly, under both engines.
|
|
83
|
+
|
|
84
|
+
- e2fa36e: Resolve tsconfig path aliases in Expo projects, as Expo's Metro does
|
|
85
|
+
|
|
86
|
+
Expo CLI resolves the `paths` in `tsconfig.json` by default, and the SDK 57 template imports its
|
|
87
|
+
own components through `@/…`, so the first component test in a new Expo project failed with
|
|
88
|
+
"Cannot find package '@/components/…'". In an Expo project with a `tsconfig.json`, the plugin now
|
|
89
|
+
turns on Vite 8's `resolve.tsconfigPaths`. An explicit `resolve.tsconfigPaths` and
|
|
90
|
+
`experiments.tsconfigPaths: false` in `app.json` both take precedence. On Vite 6 and 7, which
|
|
91
|
+
cannot resolve tsconfig paths, it warns once with the remedy. Bare React Native projects are
|
|
92
|
+
unchanged, matching their Metro.
|
|
93
|
+
|
|
94
|
+
- d23ecfa: Stop warning about `jest.mock()` in files the project does not own
|
|
95
|
+
|
|
96
|
+
The warning that a file calls `jest.mock()` without `jestMockTransform()` also fired on
|
|
97
|
+
dependencies and on vitest-native's own files: the jest-compat setup, which implements `jest.mock`,
|
|
98
|
+
and the plugin source, which only names it. A project using `vitest-native/jest-compat/setup`
|
|
99
|
+
without the transform was told to fix a file inside `node_modules/vitest-native`. The warning now
|
|
100
|
+
applies only to the project's own files.
|
|
101
|
+
|
|
102
|
+
- d93d80d: Fix Expo packages whose TypeScript source has no type syntax failing to load
|
|
103
|
+
|
|
104
|
+
Expo packages publish their TypeScript source (`expo-modules-core`'s `main` is `src/index.ts`),
|
|
105
|
+
and the native engine compiles it before Node runs it. A file that Node could already parse was
|
|
106
|
+
handed to Node unchanged, which is right for JavaScript but not for TypeScript: Node refuses any
|
|
107
|
+
`.ts` file under `node_modules`, whatever it contains. `expo-modules-core/src/polyfill/index.ts`
|
|
108
|
+
is a bare `// noop`, so a test rendering the Expo SDK 57 template's `Collapsible` (through
|
|
109
|
+
`expo-symbols`) failed with "Stripping types is currently unsupported for files under
|
|
110
|
+
node_modules". TypeScript files are now always compiled.
|
|
111
|
+
|
|
58
112
|
- 7f70965: Fix multi-project runs failing when a native project uses the hot runtime
|
|
59
113
|
|
|
60
114
|
Vitest runs projects that share a `sequence.groupOrder` (0 unless set) as one group, and stops
|
package/dist/index.mjs
CHANGED
|
@@ -48,6 +48,25 @@ function extensionsFor(platform, sourceExts = METRO_SOURCE_EXTS) {
|
|
|
48
48
|
for (const e of sourceExts) exts.push(`.${suffix}.${e}`, `.native.${e}`, `.${e}`);
|
|
49
49
|
return exts;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether `file` exists under exactly this name.
|
|
53
|
+
*
|
|
54
|
+
* macOS and Windows disks are case-insensitive by default, so `fs.existsSync("App.json")`
|
|
55
|
+
* is true when only `app.json` exists. Resolving `./App` in extension order (Metro's: js,
|
|
56
|
+
* jsx, json, ts, tsx) then picks the React Native template's `app.json` over its `App.tsx`,
|
|
57
|
+
* and the template's own test renders `{ name, displayName }`. Metro resolves from a
|
|
58
|
+
* case-sensitive file map, as does Linux, which is why neither Metro nor CI saw it. The
|
|
59
|
+
* directory listing has the real names. Checked for the file's own name: the case the
|
|
60
|
+
* template hits, and one `readdir` per hit, which the resolution caches absorb.
|
|
61
|
+
*/
|
|
62
|
+
function existsExact(file) {
|
|
63
|
+
if (!fs.existsSync(file)) return false;
|
|
64
|
+
try {
|
|
65
|
+
return fs.readdirSync(path.dirname(file)).includes(path.basename(file));
|
|
66
|
+
} catch {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
51
70
|
//#endregion
|
|
52
71
|
//#region src/resolve.ts
|
|
53
72
|
/**
|
|
@@ -312,6 +331,45 @@ function resolvePackageVersion(packageName, projectRoot) {
|
|
|
312
331
|
}
|
|
313
332
|
}
|
|
314
333
|
/**
|
|
334
|
+
* Whether to resolve tsconfig `paths` the way Expo's Metro does. Expo CLI enables
|
|
335
|
+
* tsconfig path aliases by default (`experiments.tsconfigPaths`, docs.expo.dev/guides/
|
|
336
|
+
* typescript), and the SDK 57 template imports its own components through `@/…`, so
|
|
337
|
+
* without this a new Expo project's first component test fails to resolve. Bare React
|
|
338
|
+
* Native's Metro does not, so neither does this. Vite 8 resolves tsconfig paths itself
|
|
339
|
+
* when `resolve.tsconfigPaths` is on; Vite 6 and 7 have no such option.
|
|
340
|
+
*
|
|
341
|
+
* Returns "enable" (Vite 8), "unsupported" (an older Vite with `paths` to resolve, worth
|
|
342
|
+
* a warning), or null (not an Expo project, no tsconfig, opted out, or the user set
|
|
343
|
+
* `resolve.tsconfigPaths` themselves).
|
|
344
|
+
*/
|
|
345
|
+
function expoTsconfigPaths(projectRoot, userTsconfigPaths, viteMajor) {
|
|
346
|
+
if (userTsconfigPaths !== void 0) return null;
|
|
347
|
+
const read = (file) => {
|
|
348
|
+
try {
|
|
349
|
+
return fs.readFileSync(path.join(projectRoot, file), "utf8");
|
|
350
|
+
} catch {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
let manifest = {};
|
|
355
|
+
try {
|
|
356
|
+
manifest = JSON.parse(read("package.json") ?? "{}");
|
|
357
|
+
} catch {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
if (!("expo" in {
|
|
361
|
+
...manifest.dependencies,
|
|
362
|
+
...manifest.devDependencies
|
|
363
|
+
})) return null;
|
|
364
|
+
const tsconfig = read("tsconfig.json");
|
|
365
|
+
if (tsconfig === null) return null;
|
|
366
|
+
try {
|
|
367
|
+
if (JSON.parse(read("app.json") ?? "{}").expo?.experiments?.tsconfigPaths === false) return null;
|
|
368
|
+
} catch {}
|
|
369
|
+
if (viteMajor >= 8) return "enable";
|
|
370
|
+
return /"paths"\s*:/.test(tsconfig) ? "unsupported" : null;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
315
373
|
* One line, once per process, stating which engine this run actually uses.
|
|
316
374
|
* Tests pass either way; a team that believes it's exercising real React Native
|
|
317
375
|
* while running the mock (or vice versa) must be able to see it in every log.
|
|
@@ -850,8 +908,10 @@ function reactNative(options) {
|
|
|
850
908
|
const nativeRoots = /* @__PURE__ */ new Set();
|
|
851
909
|
const contributedSetup = /* @__PURE__ */ new Map();
|
|
852
910
|
let warnedMissingJestMockTransform = false;
|
|
911
|
+
let warnedTsconfigPaths = false;
|
|
853
912
|
const warnIfJestMockUnhoisted = (code, id) => {
|
|
854
913
|
if (jestMockTransformPresent || warnedMissingJestMockTransform) return;
|
|
914
|
+
if (/[\\/]node_modules[\\/]/.test(id) || containsPath(ownPackageDir, id)) return;
|
|
855
915
|
if (!HAS_JEST_MOCK_CALL.test(code)) return;
|
|
856
916
|
warnedMissingJestMockTransform = true;
|
|
857
917
|
console.warn(`[vitest-native] ${id} calls jest.mock(), but jestMockTransform() is not in your plugins. Vitest only hoists mocks written on the vi/vitest identifier, so this call runs after the imports it should intercept and the mock will not apply.\nAdd it AFTER reactNative():\n\n import { jestMockTransform } from 'vitest-native/jest-compat'\n plugins: [reactNative(), jestMockTransform()]`);
|
|
@@ -879,6 +939,30 @@ function reactNative(options) {
|
|
|
879
939
|
};
|
|
880
940
|
let alignRoot = "";
|
|
881
941
|
const alignedCache = /* @__PURE__ */ new Map();
|
|
942
|
+
const resolveExtensionless = (source, importer) => {
|
|
943
|
+
if (importer && path.isAbsolute(importer) && source.startsWith(".") && !path.extname(source)) {
|
|
944
|
+
const cacheKey = `${importer}\0${source}`;
|
|
945
|
+
const cached = resolveCache.get(cacheKey);
|
|
946
|
+
if (cached !== void 0) return cached;
|
|
947
|
+
const importerDir = path.dirname(importer);
|
|
948
|
+
const absolute = path.resolve(importerDir, source);
|
|
949
|
+
for (const ext of extensions) {
|
|
950
|
+
const candidate = absolute + ext;
|
|
951
|
+
if (existsExact(candidate)) {
|
|
952
|
+
resolveCache.set(cacheKey, candidate);
|
|
953
|
+
return candidate;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
for (const ext of extensions) {
|
|
957
|
+
const candidate = path.join(absolute, `index${ext}`);
|
|
958
|
+
if (existsExact(candidate)) {
|
|
959
|
+
resolveCache.set(cacheKey, candidate);
|
|
960
|
+
return candidate;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
resolveCache.set(cacheKey, void 0);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
882
966
|
const alignedResolution = (source, importer) => {
|
|
883
967
|
if (engine !== "native") return void 0;
|
|
884
968
|
const from = importer && path.isAbsolute(importer) && !importer.startsWith("\0") ? importer : path.join(alignRoot || process.cwd(), "package.json");
|
|
@@ -916,6 +1000,7 @@ function reactNative(options) {
|
|
|
916
1000
|
const resolveCache = /* @__PURE__ */ new Map();
|
|
917
1001
|
const virtualCodeCache = /* @__PURE__ */ new Map();
|
|
918
1002
|
const thisDir = path.dirname(fileURLToPath(import.meta.url));
|
|
1003
|
+
const ownPackageDir = path.resolve(thisDir, "..");
|
|
919
1004
|
let setupFilePath = path.resolve(thisDir, "setup.mjs");
|
|
920
1005
|
if (!fs.existsSync(setupFilePath)) {
|
|
921
1006
|
const srcPath = path.resolve(thisDir, "setup.ts");
|
|
@@ -1197,7 +1282,7 @@ function reactNative(options) {
|
|
|
1197
1282
|
if (source === "react-native" && rnFacadeExports !== null) return "\0virtual:rn-facade";
|
|
1198
1283
|
const presetHit = resolvePresetId(source);
|
|
1199
1284
|
if (presetHit) return presetHit;
|
|
1200
|
-
return alignedResolution(source, importer);
|
|
1285
|
+
return resolveExtensionless(source, importer) ?? alignedResolution(source, importer);
|
|
1201
1286
|
}
|
|
1202
1287
|
if (source === "react-native") return "\0virtual:react-native";
|
|
1203
1288
|
if (source.startsWith("react-native/")) {
|
|
@@ -1206,28 +1291,8 @@ function reactNative(options) {
|
|
|
1206
1291
|
}
|
|
1207
1292
|
const presetId = resolvePresetId(source);
|
|
1208
1293
|
if (presetId) return presetId;
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
const cached = resolveCache.get(cacheKey);
|
|
1212
|
-
if (cached !== void 0) return cached;
|
|
1213
|
-
const importerDir = path.dirname(importer);
|
|
1214
|
-
const absolute = path.resolve(importerDir, source);
|
|
1215
|
-
for (const ext of extensions) {
|
|
1216
|
-
const candidate = absolute + ext;
|
|
1217
|
-
if (fs.existsSync(candidate)) {
|
|
1218
|
-
resolveCache.set(cacheKey, candidate);
|
|
1219
|
-
return candidate;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
for (const ext of extensions) {
|
|
1223
|
-
const candidate = path.join(absolute, `index${ext}`);
|
|
1224
|
-
if (fs.existsSync(candidate)) {
|
|
1225
|
-
resolveCache.set(cacheKey, candidate);
|
|
1226
|
-
return candidate;
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
resolveCache.set(cacheKey, void 0);
|
|
1230
|
-
}
|
|
1294
|
+
const extensionless = resolveExtensionless(source, importer);
|
|
1295
|
+
if (extensionless !== void 0) return extensionless;
|
|
1231
1296
|
},
|
|
1232
1297
|
load(id) {
|
|
1233
1298
|
if (id === "\0virtual:rn-facade" && rnFacadeExports !== null) {
|
|
@@ -1339,6 +1404,20 @@ function reactNative(options) {
|
|
|
1339
1404
|
const test = result?.test;
|
|
1340
1405
|
if (Array.isArray(test?.setupFiles) && typeof test.setupFiles[0] === "string") contributedSetup.set(vitestRootOf(userConfig), test.setupFiles[0]);
|
|
1341
1406
|
if (test) test.execArgv = [...test.execArgv ?? [], ...EXPORT_RECOVERY_ARGV];
|
|
1407
|
+
if (test) {
|
|
1408
|
+
const viteRoot = userConfig.root ? path.resolve(userConfig.root) : process.cwd();
|
|
1409
|
+
const viteMajor = Number(resolvePackageVersion("vite", viteRoot)?.split(".")[0]);
|
|
1410
|
+
const tsconfigPaths = expoTsconfigPaths(viteRoot, userConfig.resolve?.tsconfigPaths, viteMajor);
|
|
1411
|
+
const config = result;
|
|
1412
|
+
if (tsconfigPaths === "enable") config.resolve = {
|
|
1413
|
+
...config.resolve,
|
|
1414
|
+
tsconfigPaths: true
|
|
1415
|
+
};
|
|
1416
|
+
else if (tsconfigPaths === "unsupported" && !warnedTsconfigPaths) {
|
|
1417
|
+
warnedTsconfigPaths = true;
|
|
1418
|
+
console.warn(`[vitest-native] This Expo project's tsconfig declares \`paths\`, which Expo's Metro resolves by default, but Vite ${viteMajor} cannot (Vite 8 adds \`resolve.tsconfigPaths\`). Upgrade to Vite 8, or add the vite-tsconfig-paths plugin, so imports such as \`@/…\` resolve in tests.`);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1342
1421
|
return result;
|
|
1343
1422
|
}
|
|
1344
1423
|
},
|
package/dist/native/hooks.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import Module from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import fs from "node:fs";
|
|
6
|
-
import { transformRN, isFlow, needsTransform } from "./transform.mjs";
|
|
6
|
+
import { transformRN, isFlow, needsTransform, isTransforming } from "./transform.mjs";
|
|
7
7
|
import { boundarySourceFor } from "./boundary.mjs";
|
|
8
8
|
import { resolvePlatformFile, resolveDeepPackageFile } from "./resolve.mjs";
|
|
9
9
|
import { NODE_MODULES_PATH, isUtilitySubpath, packageNameOf, subpathLeafOf } from "./match.mjs";
|
|
@@ -370,6 +370,9 @@ export function installRequireHooks(
|
|
|
370
370
|
|
|
371
371
|
const origJs = Module._extensions[".js"];
|
|
372
372
|
Module._extensions[".js"] = function (mod, filename) {
|
|
373
|
+
// Babel loading its own toolchain mid-transform: never compile it (see
|
|
374
|
+
// isTransforming in transform.mjs).
|
|
375
|
+
if (isTransforming()) return origJs(mod, filename);
|
|
373
376
|
const norm = filename.replace(/\\/g, "/");
|
|
374
377
|
const rnPath = ownership.reactNativePathFor(filename);
|
|
375
378
|
const boundary = boundarySourceFor(rnPath ?? norm, platform, reactNativeVersion);
|
|
@@ -31,3 +31,9 @@ export declare function resolveDeepPackageFile(
|
|
|
31
31
|
platform: "ios" | "android",
|
|
32
32
|
sourceExts?: readonly string[],
|
|
33
33
|
): string | null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether `file` exists under exactly this name, which a case-insensitive disk (macOS,
|
|
37
|
+
* Windows) does not answer by itself.
|
|
38
|
+
*/
|
|
39
|
+
export declare function existsExact(file: string): boolean;
|
package/dist/native/resolve.mjs
CHANGED
|
@@ -40,6 +40,26 @@ export function extensionsFor(platform, sourceExts = METRO_SOURCE_EXTS) {
|
|
|
40
40
|
return exts;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Whether `file` exists under exactly this name.
|
|
45
|
+
*
|
|
46
|
+
* macOS and Windows disks are case-insensitive by default, so `fs.existsSync("App.json")`
|
|
47
|
+
* is true when only `app.json` exists. Resolving `./App` in extension order (Metro's: js,
|
|
48
|
+
* jsx, json, ts, tsx) then picks the React Native template's `app.json` over its `App.tsx`,
|
|
49
|
+
* and the template's own test renders `{ name, displayName }`. Metro resolves from a
|
|
50
|
+
* case-sensitive file map, as does Linux, which is why neither Metro nor CI saw it. The
|
|
51
|
+
* directory listing has the real names. Checked for the file's own name: the case the
|
|
52
|
+
* template hits, and one `readdir` per hit, which the resolution caches absorb.
|
|
53
|
+
*/
|
|
54
|
+
export function existsExact(file) {
|
|
55
|
+
if (!fs.existsSync(file)) return false;
|
|
56
|
+
try {
|
|
57
|
+
return fs.readdirSync(path.dirname(file)).includes(path.basename(file));
|
|
58
|
+
} catch {
|
|
59
|
+
return true; // An unreadable directory keeps the filesystem's verdict.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
// Per-worker cache: platform + ordered sourceExts + absolute base → path | null.
|
|
44
64
|
// Platform resolution is deterministic for a given on-disk layout, and Node's own
|
|
45
65
|
// module cache already dedupes most re-resolution; this dedupes the rest (distinct
|
|
@@ -66,11 +86,11 @@ export function resolvePlatformFile(absBase, platform = "ios", sourceExts = METR
|
|
|
66
86
|
function scanPlatformFile(absBase, platform, sourceExts) {
|
|
67
87
|
const extensions = extensionsFor(platform, sourceExts);
|
|
68
88
|
for (const ext of extensions) {
|
|
69
|
-
if (
|
|
89
|
+
if (existsExact(absBase + ext)) return absBase + ext;
|
|
70
90
|
}
|
|
71
91
|
for (const ext of extensions) {
|
|
72
92
|
const idx = path.join(absBase, "index" + ext);
|
|
73
|
-
if (
|
|
93
|
+
if (existsExact(idx)) return idx;
|
|
74
94
|
}
|
|
75
95
|
return null;
|
|
76
96
|
}
|
|
@@ -278,8 +278,16 @@ export function isFlow(src) {
|
|
|
278
278
|
* hands those to Node as CommonJS today, and changing that is an interop question
|
|
279
279
|
* about named exports and live bindings that this check does not answer.
|
|
280
280
|
*/
|
|
281
|
+
const TYPESCRIPT_FILE = /\.[cm]?tsx?$/;
|
|
282
|
+
|
|
281
283
|
export function needsTransform(file, src) {
|
|
282
284
|
if (file.endsWith(".mjs") || moduleGoal(file)) return true; // Not this check's business.
|
|
285
|
+
// Node refuses TypeScript under node_modules by extension, whatever the content
|
|
286
|
+
// ("Stripping types is currently unsupported for files under node_modules"). Expo
|
|
287
|
+
// packages publish their TypeScript source (expo-modules-core's `main` is
|
|
288
|
+
// src/index.ts), and a file with no type syntax — its src/polyfill/index.ts is a
|
|
289
|
+
// bare `// noop` — parses as a script, so the check below would hand it to Node.
|
|
290
|
+
if (TYPESCRIPT_FILE.test(file)) return true;
|
|
283
291
|
try {
|
|
284
292
|
// Parsed for the verdict only; the compiled script is never run.
|
|
285
293
|
const parsed = new vm.Script(src, { filename: file });
|
|
@@ -323,6 +331,22 @@ function moduleGoal(file) {
|
|
|
323
331
|
}
|
|
324
332
|
|
|
325
333
|
/** Transform an RN source file to runnable CJS. Cached in-memory + on disk. */
|
|
334
|
+
// Babel loads its own presets and plugins with `require` while a transform runs, and
|
|
335
|
+
// those requires pass through the engine's CommonJS hook like any other. Compiling them
|
|
336
|
+
// there is compiling the compiler mid-compile: @react-native/babel-preset's
|
|
337
|
+
// babel-plugin-syntax-hermes-parser and hermes-parser keep an `@flow` header in their
|
|
338
|
+
// published builds and sit under an @react-native package, so the hook sent them back
|
|
339
|
+
// through Babel, which then read the half-loaded plugin's exports and Node warned
|
|
340
|
+
// "Accessing non-existent property 'then' of module exports inside circular
|
|
341
|
+
// dependency" on a project's first run. They load as published, as they do under
|
|
342
|
+
// Jest, whose transformer is never transformed.
|
|
343
|
+
let transformDepth = 0;
|
|
344
|
+
|
|
345
|
+
/** Whether a transform is running on this thread (a require now is Babel's own). */
|
|
346
|
+
export function isTransforming() {
|
|
347
|
+
return transformDepth > 0;
|
|
348
|
+
}
|
|
349
|
+
|
|
326
350
|
export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
327
351
|
const ctx = ctxFor(projectRoot);
|
|
328
352
|
// The in-memory key uses mtime+size (one statSync) so the hot path skips
|
|
@@ -352,9 +376,10 @@ export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
|
352
376
|
return cached;
|
|
353
377
|
} catch {}
|
|
354
378
|
|
|
355
|
-
if (!ctx.babel) ctx.babel = ctx.req("@babel/core");
|
|
356
379
|
let out;
|
|
380
|
+
transformDepth++;
|
|
357
381
|
try {
|
|
382
|
+
if (!ctx.babel) ctx.babel = ctx.req("@babel/core");
|
|
358
383
|
out = ctx.babel.transformSync(src, {
|
|
359
384
|
filename: file,
|
|
360
385
|
plugins: ctx.flowEnums ? [ctx.flowEnums] : [],
|
|
@@ -368,6 +393,8 @@ export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
|
368
393
|
// loader, the CJS require hook, requireActual's .ts handlers — surfaces
|
|
369
394
|
// the file, platform, and owning package instead of a bare Babel stack.
|
|
370
395
|
throw decorateTransformError(err, file, platform);
|
|
396
|
+
} finally {
|
|
397
|
+
transformDepth--;
|
|
371
398
|
}
|
|
372
399
|
// Atomic write: multiple worker threads may transform the same RN file
|
|
373
400
|
// concurrently on a cold cache. Write to a unique temp file then rename
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.14.0-rc.
|
|
3
|
+
"version": "0.14.0-rc.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"@testing-library/react-native": "14.0.1",
|
|
150
150
|
"@types/node": "25.9.8",
|
|
151
151
|
"@types/react": "19.3.0",
|
|
152
|
-
"@vitest/coverage-v8": "5.0.
|
|
152
|
+
"@vitest/coverage-v8": "5.0.2",
|
|
153
153
|
"expo-constants": "57.0.19",
|
|
154
154
|
"expo-status-bar": "57.0.1",
|
|
155
155
|
"ext-platform-lib": "file:./tests-native/fixtures/ext-platform-lib",
|
|
@@ -176,8 +176,8 @@
|
|
|
176
176
|
"typescript": "7.0.2",
|
|
177
177
|
"typescript-6": "npm:typescript@6.0.3",
|
|
178
178
|
"untranspiled-jsx-lib": "file:./tests-native/fixtures/untranspiled-jsx-lib",
|
|
179
|
-
"vite": "^8.3.
|
|
180
|
-
"vitest": "5.0.
|
|
179
|
+
"vite": "^8.3.1",
|
|
180
|
+
"vitest": "5.0.2"
|
|
181
181
|
},
|
|
182
182
|
"scripts": {
|
|
183
183
|
"build": "bunx --bun tsdown && node scripts/copy-static-types.mjs",
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
"validate:metro-profile": "node --expose-gc validation/module-isolation/run-metro-profile.mjs"
|
|
213
213
|
},
|
|
214
214
|
"dependencies": {
|
|
215
|
-
"flow-remove-types": "^2.
|
|
215
|
+
"flow-remove-types": "^2.333.0",
|
|
216
216
|
"magic-string": "^1.4.2"
|
|
217
217
|
},
|
|
218
218
|
"bin": {
|