vitest-native 0.14.0-rc.2 → 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 +13 -0
- package/dist/native/hooks.mjs +4 -1
- package/dist/native/transform.mjs +20 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -58,6 +58,19 @@
|
|
|
58
58
|
|
|
59
59
|
### Patch Changes
|
|
60
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
|
+
|
|
61
74
|
- bb9cf45: Fix `./App` resolving to `app.json` on macOS and Windows
|
|
62
75
|
|
|
63
76
|
The React Native CLI template ships `App.tsx` and `app.json` side by side, and its own test
|
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);
|
|
@@ -331,6 +331,22 @@ function moduleGoal(file) {
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
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
|
+
|
|
334
350
|
export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
335
351
|
const ctx = ctxFor(projectRoot);
|
|
336
352
|
// The in-memory key uses mtime+size (one statSync) so the hot path skips
|
|
@@ -360,9 +376,10 @@ export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
|
360
376
|
return cached;
|
|
361
377
|
} catch {}
|
|
362
378
|
|
|
363
|
-
if (!ctx.babel) ctx.babel = ctx.req("@babel/core");
|
|
364
379
|
let out;
|
|
380
|
+
transformDepth++;
|
|
365
381
|
try {
|
|
382
|
+
if (!ctx.babel) ctx.babel = ctx.req("@babel/core");
|
|
366
383
|
out = ctx.babel.transformSync(src, {
|
|
367
384
|
filename: file,
|
|
368
385
|
plugins: ctx.flowEnums ? [ctx.flowEnums] : [],
|
|
@@ -376,6 +393,8 @@ export function transformRN(file, src, projectRoot, platform = "ios") {
|
|
|
376
393
|
// loader, the CJS require hook, requireActual's .ts handlers — surfaces
|
|
377
394
|
// the file, platform, and owning package instead of a bare Babel stack.
|
|
378
395
|
throw decorateTransformError(err, file, platform);
|
|
396
|
+
} finally {
|
|
397
|
+
transformDepth--;
|
|
379
398
|
}
|
|
380
399
|
// Atomic write: multiple worker threads may transform the same RN file
|
|
381
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": {
|