vitest-native 0.15.0-rc.3 → 0.15.0-rc.4
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 +1 -1
- package/dist/cli.mjs +5 -5
- package/dist/{host-C02lnLzW.mjs → host-DGXnuRkW.mjs} +88 -101
- package/dist/index.mjs +2 -2
- package/dist/jest-compat.cjs +9 -1
- package/dist/jest-compat.mjs +9 -1
- package/dist/{presets-D_-kRSYm.mjs → presets-C9Q7fY_z.mjs} +38 -1
- package/dist/presets.mjs +1 -1
- package/dist/setup.mjs +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -105,7 +105,7 @@ through the jest-compat layer. See [migrating from Jest](https://vitest-native.d
|
|
|
105
105
|
| | Supported |
|
|
106
106
|
|---|---|
|
|
107
107
|
| Node.js | 22.22.3+ on Node 22, 24.12+ on Node 24, or 26+ |
|
|
108
|
-
| Vitest | 5.x |
|
|
108
|
+
| Vitest | 5.x (5.1.0 or later recommended) |
|
|
109
109
|
| Vite | ^8.0.5 |
|
|
110
110
|
| React | 19 or later |
|
|
111
111
|
| React Native | 0.86–0.88 |
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { A as PEER_REQUIREMENTS, C as SUPPORTED_NODE, E as unsupportedNodeMessage, F as unsupportedExpoSdkMessage, I as unsupportedReactNativeMessage, M as belowRecommendedMessage, N as installedExpoVersion, O as validatePeerDependency, P as isBelowSupportedReactNative, T as satisfiesNodeRange, _ as
|
|
2
|
+
import { A as PEER_REQUIREMENTS, C as SUPPORTED_NODE, E as unsupportedNodeMessage, F as unsupportedExpoSdkMessage, I as unsupportedReactNativeMessage, M as belowRecommendedMessage, N as installedExpoVersion, O as validatePeerDependency, P as isBelowSupportedReactNative, T as satisfiesNodeRange, _ as isKnownPlugin, c as detectEcosystemPackages, d as detectEngine, g as classifyBabelPlugins, h as projectBabelTrigger, i as ownVitestPackage, l as babelParser, m as missingBabelCoreNotice, o as usesVitePlus, r as installedViteVersion, u as isPlainJavaScript, v as normalizeBabelName, y as installedManifest } from "./host-DGXnuRkW.mjs";
|
|
3
3
|
import { a as PRESET_MODULES, f as presetShadowing, i as LIBRARY_SETUP_FILES, m as testsItself, r as DEFAULT_ASSET_EXTS, s as autoDetectedPresetApplies, t as AUTO_DETECT_PRESETS } from "./preset-map-DdAexIwz.mjs";
|
|
4
4
|
import { n as ignorePattern, t as findNodeModuleMocks } from "./root-mocks-DP95ncxD.mjs";
|
|
5
5
|
import { n as formatHotMemoryPlan, t as createHotMemoryPlan } from "./memory-Couw0Esx.mjs";
|
|
@@ -11,8 +11,8 @@ import os from "node:os";
|
|
|
11
11
|
import { VitestNativeError } from "./errors.mjs";
|
|
12
12
|
import { docsUrl } from "./docs-url.mjs";
|
|
13
13
|
import { createNativeOwnershipPolicy, formatNativeOwnershipManifest } from "./native/ownership.mjs";
|
|
14
|
-
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
15
14
|
import { relativeToRoot, rootSpellings } from "./native/root-spelling.mjs";
|
|
15
|
+
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
16
16
|
import { HOT_STATE_MANIFEST_ENTRIES } from "./native/state-manifest.mjs";
|
|
17
17
|
import { isDeepStrictEqual } from "node:util";
|
|
18
18
|
import { spawn, spawnSync } from "node:child_process";
|
|
@@ -5164,9 +5164,9 @@ function main(argv, log = console.log) {
|
|
|
5164
5164
|
json: parsed.json,
|
|
5165
5165
|
timeoutMs: parsed.timeoutMs,
|
|
5166
5166
|
showOutput: parsed.showOutput,
|
|
5167
|
-
runs: parsed.runs
|
|
5168
|
-
shuffle: parsed.shuffle
|
|
5169
|
-
seed: parsed.seed
|
|
5167
|
+
runs: parsed.runs,
|
|
5168
|
+
shuffle: parsed.shuffle,
|
|
5169
|
+
seed: parsed.seed
|
|
5170
5170
|
});
|
|
5171
5171
|
return runCompare({
|
|
5172
5172
|
...parsed,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-DdAexIwz.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import fs from "node:fs";
|
|
@@ -6,9 +6,9 @@ import { VitestNativeError, VitestNativeTypeError } from "./errors.mjs";
|
|
|
6
6
|
import { mainFieldFile } from "./native/shared-resolver.mjs";
|
|
7
7
|
import crypto, { createHash } from "node:crypto";
|
|
8
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
10
9
|
import { projectBabelCaller } from "./native/babel-caller.mjs";
|
|
11
10
|
import { relativeToRoot, rootSpellingOf } from "./native/root-spelling.mjs";
|
|
11
|
+
import { resolveTransformPreset } from "./native/babel-preset.mjs";
|
|
12
12
|
import { containsPath, dependencyDirOf } from "./native/match.mjs";
|
|
13
13
|
// src/peer-requirements.ts
|
|
14
14
|
const PEER_REQUIREMENTS = [
|
|
@@ -525,75 +525,6 @@ async function readProjectSource(id) {
|
|
|
525
525
|
function isProjectSourceOnDisk(id) {
|
|
526
526
|
return fs.statSync(id, { throwIfNoEntry: false })?.isFile() ?? false;
|
|
527
527
|
}
|
|
528
|
-
/**
|
|
529
|
-
* The native engine's dependencies that do NOT resolve from the project root.
|
|
530
|
-
*
|
|
531
|
-
* react-native itself is part of the check: the Babel toolchain alone chose
|
|
532
|
-
* native mode in a project with the preset installed but no react-native — an
|
|
533
|
-
* incomplete install, a babel-only workspace — which then failed later at RN
|
|
534
|
-
* resolution with nothing pointing at the cause. Resolution, not declaration:
|
|
535
|
-
* every check walks node_modules upward from the root — so a hoisted workspace
|
|
536
|
-
* install or Expo's transitive react-native counts, and a project does not need
|
|
537
|
-
* react-native in its own manifest.
|
|
538
|
-
*/
|
|
539
|
-
function missingNativeDeps(projectRoot) {
|
|
540
|
-
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
541
|
-
const missing = [];
|
|
542
|
-
if (!reactNativeInstalledNear(projectRoot)) missing.push("react-native");
|
|
543
|
-
if (resolveTransformPreset(projectRoot) === null) missing.push("@react-native/babel-preset");
|
|
544
|
-
try {
|
|
545
|
-
req.resolve("@babel/core");
|
|
546
|
-
} catch {
|
|
547
|
-
missing.push("@babel/core");
|
|
548
|
-
}
|
|
549
|
-
return missing;
|
|
550
|
-
}
|
|
551
|
-
/** Does node_modules/react-native exist in projectRoot or any ancestor? */
|
|
552
|
-
function reactNativeInstalledNear(projectRoot) {
|
|
553
|
-
let dir = path.resolve(projectRoot);
|
|
554
|
-
for (;;) {
|
|
555
|
-
if (fs.existsSync(path.join(dir, "node_modules", "react-native", "package.json"))) return true;
|
|
556
|
-
const parent = path.dirname(dir);
|
|
557
|
-
if (parent === dir) return false;
|
|
558
|
-
dir = parent;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
/** Resolve the concrete engine for a run. Pure; never throws. */
|
|
562
|
-
function detectEngine(requested, projectRoot, opts) {
|
|
563
|
-
const missing = missingNativeDeps(projectRoot);
|
|
564
|
-
const nativeAvailable = missing.length === 0;
|
|
565
|
-
if (requested === "native") return {
|
|
566
|
-
engine: "native",
|
|
567
|
-
nativeAvailable,
|
|
568
|
-
missing,
|
|
569
|
-
notice: null
|
|
570
|
-
};
|
|
571
|
-
if (requested === "mock") return {
|
|
572
|
-
engine: "mock",
|
|
573
|
-
nativeAvailable,
|
|
574
|
-
missing,
|
|
575
|
-
notice: null
|
|
576
|
-
};
|
|
577
|
-
const prefersNative = opts?.autoPrefersNative ?? true;
|
|
578
|
-
if (prefersNative && nativeAvailable) return {
|
|
579
|
-
engine: "native",
|
|
580
|
-
nativeAvailable,
|
|
581
|
-
missing,
|
|
582
|
-
notice: null
|
|
583
|
-
};
|
|
584
|
-
if (prefersNative) return {
|
|
585
|
-
engine: "mock",
|
|
586
|
-
nativeAvailable: false,
|
|
587
|
-
missing,
|
|
588
|
-
notice: `[vitest-native] ${missing.join(", ")} not found — using the mock engine. Install what's missing to run real React Native, or set engine:'mock' to silence this.`
|
|
589
|
-
};
|
|
590
|
-
return {
|
|
591
|
-
engine: "mock",
|
|
592
|
-
nativeAvailable,
|
|
593
|
-
missing,
|
|
594
|
-
notice: null
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
528
|
// src/installed-manifest.ts
|
|
598
529
|
/**
|
|
599
530
|
* A package's manifest as the package manager wrote it (see cli/manifest.ts for why
|
|
@@ -613,10 +544,6 @@ function installedManifest(root, pkg) {
|
|
|
613
544
|
}
|
|
614
545
|
// src/babel-plugins.ts
|
|
615
546
|
/**
|
|
616
|
-
* Babel plugin classification shared by the engine (projectBabel) and the CLI (doctor,
|
|
617
|
-
* migrate): what a project's Babel plugins do under vitest-native.
|
|
618
|
-
*/
|
|
619
|
-
/**
|
|
620
547
|
* @babel/core's `standardizeName` (lib/config/files/plugins.js), rule for rule except that a name
|
|
621
548
|
* starting with `.` is taken as a relative path: `foo` →
|
|
622
549
|
* `babel-plugin-foo`, `@babel/foo` → `@babel/plugin-foo` (`@babel/plugin-foo` unchanged),
|
|
@@ -631,20 +558,16 @@ function normalizeBabelName(name, kind = "plugin") {
|
|
|
631
558
|
return name.replace(prefix, `babel-${kind}-`).replace(babelOrg, `$1${kind}-`).replace(otherOrg, `$1babel-${kind}-`).replace(/^(@(?!babel$)[^/]+)$/, `$1/babel-${kind}`).replace(/^module:/, "");
|
|
632
559
|
}
|
|
633
560
|
/**
|
|
634
|
-
* Whether
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
561
|
+
* Whether real Reanimated or Worklets code can run in a test, so the worklets Babel plugin
|
|
562
|
+
* matters: whenever either is installed. A preset standing in for the library does not
|
|
563
|
+
* change that: Reanimated 4.7+ runs as its own mock, whose hooks are the real ones, and with
|
|
564
|
+
* an older Reanimated (or the mock engine) a mock that loads the library itself
|
|
565
|
+
* (`jest.requireActual('react-native-reanimated')`) hands the real hooks to the components
|
|
566
|
+
* it renders. Those components are compiled where they live, not where the mock is, so no
|
|
567
|
+
* file can be told apart; the plugin is kept for every file it applies to, as under Jest.
|
|
638
568
|
*/
|
|
639
|
-
function
|
|
640
|
-
return
|
|
641
|
-
}
|
|
642
|
-
/** Why a worklet plugin is not needed — only when the preset replacing its library is active. */
|
|
643
|
-
function workletReason(pkg, active, root) {
|
|
644
|
-
const preset = presetShadowing(pkg);
|
|
645
|
-
if (preset && active.includes(preset)) return `transforms worklets for ${pkg}; the active ${preset} preset (auto-detected from ${Object.entries(AUTO_DETECT_PRESETS).filter(([, name]) => name === preset).map(([detect]) => detect).join(", ")}) replaces ${pkg} with a mock, so no worklet runs.`;
|
|
646
|
-
if (!installedManifest(root, pkg)) return `transforms worklets for ${pkg}, which is not installed.`;
|
|
647
|
-
return null;
|
|
569
|
+
function realWorkletsCanRun(root) {
|
|
570
|
+
return installedManifest(root, "react-native-reanimated") !== null || installedManifest(root, "react-native-worklets") !== null;
|
|
648
571
|
}
|
|
649
572
|
/** Whether `name` is one of the plugins this module knows by name. */
|
|
650
573
|
const isKnownPlugin = (name) => KNOWN_PLUGINS.some((known) => known.names.includes(name));
|
|
@@ -679,21 +602,16 @@ const unknownReason = (e) => `${e.written} ran on every file under babel-jest an
|
|
|
679
602
|
function classifyBabelPlugins(report, root, active) {
|
|
680
603
|
return report.plugins.map((entry) => {
|
|
681
604
|
const worklets = /^(react-native-worklets|react-native-reanimated)\/plugin$/.exec(entry.name);
|
|
682
|
-
if (worklets && reanimatedRunsItsOwnMock(root, active)) return {
|
|
683
|
-
...entry,
|
|
684
|
-
verdict: "required",
|
|
685
|
-
reason: `${entry.written} gives Reanimated's hooks their dependencies. Under the native engine, Reanimated runs as its own mock, whose useAnimatedStyle throws without it ("used without a dependency array or Babel plugin").`
|
|
686
|
-
};
|
|
687
605
|
if (worklets) {
|
|
688
|
-
|
|
689
|
-
return reason ? {
|
|
606
|
+
if (!realWorkletsCanRun(root)) return {
|
|
690
607
|
...entry,
|
|
691
608
|
verdict: "unneeded",
|
|
692
|
-
reason
|
|
693
|
-
}
|
|
609
|
+
reason: `${entry.written} transforms worklets for ${worklets[1]}, which is not installed.`
|
|
610
|
+
};
|
|
611
|
+
return {
|
|
694
612
|
...entry,
|
|
695
|
-
verdict: "
|
|
696
|
-
reason:
|
|
613
|
+
verdict: "required",
|
|
614
|
+
reason: `${entry.written} gives Reanimated's hooks their dependencies. Real Reanimated runs in tests (as its own mock from 4.7, or through a mock that loads jest.requireActual('react-native-reanimated')), and its useAnimatedStyle throws without it ("used without a dependency array or Babel plugin").`
|
|
697
615
|
};
|
|
698
616
|
}
|
|
699
617
|
const known = KNOWN_PLUGINS.find((k) => k.names.includes(entry.name));
|
|
@@ -948,7 +866,7 @@ function classifyProjectBabelEntry(entry, root, active) {
|
|
|
948
866
|
if (opts.jsxImportSource !== void 0) return needed(`${name}'s \`jsxImportSource\``, JSX);
|
|
949
867
|
const changes = optionKeys(options).find((key) => !allowed.has(key));
|
|
950
868
|
if (changes) return needed(`${name}'s \`${changes}\` option`, null);
|
|
951
|
-
if (name === "babel-preset-expo" && opts.worklets !== false && opts.reanimated !== false &&
|
|
869
|
+
if (name === "babel-preset-expo" && opts.worklets !== false && opts.reanimated !== false && realWorkletsCanRun(root)) return needed("babel-preset-expo's worklets plugin", WORKLET);
|
|
952
870
|
return COVERED;
|
|
953
871
|
}
|
|
954
872
|
if (STRIPPED.has(name)) return STRIP;
|
|
@@ -1362,6 +1280,75 @@ function envFilesHash(root, configured) {
|
|
|
1362
1280
|
for (const file of [...new Set(files)].sort()) if (fs.existsSync(file)) hash.update(file).update(fs.readFileSync(file));
|
|
1363
1281
|
return hash.digest("hex");
|
|
1364
1282
|
}
|
|
1283
|
+
/**
|
|
1284
|
+
* The native engine's dependencies that do NOT resolve from the project root.
|
|
1285
|
+
*
|
|
1286
|
+
* react-native itself is part of the check: the Babel toolchain alone chose
|
|
1287
|
+
* native mode in a project with the preset installed but no react-native — an
|
|
1288
|
+
* incomplete install, a babel-only workspace — which then failed later at RN
|
|
1289
|
+
* resolution with nothing pointing at the cause. Resolution, not declaration:
|
|
1290
|
+
* every check walks node_modules upward from the root — so a hoisted workspace
|
|
1291
|
+
* install or Expo's transitive react-native counts, and a project does not need
|
|
1292
|
+
* react-native in its own manifest.
|
|
1293
|
+
*/
|
|
1294
|
+
function missingNativeDeps(projectRoot) {
|
|
1295
|
+
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
1296
|
+
const missing = [];
|
|
1297
|
+
if (!reactNativeInstalledNear(projectRoot)) missing.push("react-native");
|
|
1298
|
+
if (resolveTransformPreset(projectRoot) === null) missing.push("@react-native/babel-preset");
|
|
1299
|
+
try {
|
|
1300
|
+
req.resolve("@babel/core");
|
|
1301
|
+
} catch {
|
|
1302
|
+
missing.push("@babel/core");
|
|
1303
|
+
}
|
|
1304
|
+
return missing;
|
|
1305
|
+
}
|
|
1306
|
+
/** Does node_modules/react-native exist in projectRoot or any ancestor? */
|
|
1307
|
+
function reactNativeInstalledNear(projectRoot) {
|
|
1308
|
+
let dir = path.resolve(projectRoot);
|
|
1309
|
+
for (;;) {
|
|
1310
|
+
if (fs.existsSync(path.join(dir, "node_modules", "react-native", "package.json"))) return true;
|
|
1311
|
+
const parent = path.dirname(dir);
|
|
1312
|
+
if (parent === dir) return false;
|
|
1313
|
+
dir = parent;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
/** Resolve the concrete engine for a run. Pure; never throws. */
|
|
1317
|
+
function detectEngine(requested, projectRoot, opts) {
|
|
1318
|
+
const missing = missingNativeDeps(projectRoot);
|
|
1319
|
+
const nativeAvailable = missing.length === 0;
|
|
1320
|
+
if (requested === "native") return {
|
|
1321
|
+
engine: "native",
|
|
1322
|
+
nativeAvailable,
|
|
1323
|
+
missing,
|
|
1324
|
+
notice: null
|
|
1325
|
+
};
|
|
1326
|
+
if (requested === "mock") return {
|
|
1327
|
+
engine: "mock",
|
|
1328
|
+
nativeAvailable,
|
|
1329
|
+
missing,
|
|
1330
|
+
notice: null
|
|
1331
|
+
};
|
|
1332
|
+
const prefersNative = opts?.autoPrefersNative ?? true;
|
|
1333
|
+
if (prefersNative && nativeAvailable) return {
|
|
1334
|
+
engine: "native",
|
|
1335
|
+
nativeAvailable,
|
|
1336
|
+
missing,
|
|
1337
|
+
notice: null
|
|
1338
|
+
};
|
|
1339
|
+
if (prefersNative) return {
|
|
1340
|
+
engine: "mock",
|
|
1341
|
+
nativeAvailable: false,
|
|
1342
|
+
missing,
|
|
1343
|
+
notice: `[vitest-native] ${missing.join(", ")} not found — using the mock engine. Install what's missing to run real React Native, or set engine:'mock' to silence this.`
|
|
1344
|
+
};
|
|
1345
|
+
return {
|
|
1346
|
+
engine: "mock",
|
|
1347
|
+
nativeAvailable,
|
|
1348
|
+
missing,
|
|
1349
|
+
notice: null
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1365
1352
|
// src/native/plain-javascript.ts
|
|
1366
1353
|
/**
|
|
1367
1354
|
* Whether a file is standard JavaScript, read with the project's own Babel parser and no
|
|
@@ -2041,4 +2028,4 @@ function assertHotWorkerLoadsRunningVitest(running, workerEntry) {
|
|
|
2041
2028
|
version: running.version
|
|
2042
2029
|
}, loadedRoot, "the hot runtime's worker", " Or set `hotRuntime: false`: per-file isolation loads Vitest through Vitest's own resolver, which reaches the running copy.");
|
|
2043
2030
|
}
|
|
2044
|
-
export { PEER_REQUIREMENTS as A, SUPPORTED_NODE as C, validateOptions as D, unsupportedNodeMessage as E, unsupportedExpoSdkMessage as F, unsupportedReactNativeMessage as I, belowRecommendedMessage as M, installedExpoVersion as N, validatePeerDependency as O, isBelowSupportedReactNative as P, shouldDefaultFsModuleCache as S, satisfiesNodeRange as T,
|
|
2031
|
+
export { PEER_REQUIREMENTS as A, SUPPORTED_NODE as C, validateOptions as D, unsupportedNodeMessage as E, unsupportedExpoSdkMessage as F, unsupportedReactNativeMessage as I, belowRecommendedMessage as M, installedExpoVersion as N, validatePeerDependency as O, isBelowSupportedReactNative as P, shouldDefaultFsModuleCache as S, satisfiesNodeRange as T, isKnownPlugin as _, runningVite as a, readProjectSource as b, detectEcosystemPackages as c, detectEngine as d, createProjectBabel as f, classifyBabelPlugins as g, projectBabelTrigger as h, ownVitestPackage as i, SUPPORTED_EXPO_SDKS as j, warnUnknownOptions as k, babelParser as l, missingBabelCoreNotice as m, assertHotWorkerLoadsRunningVitest as n, usesVitePlus as o, isProjectSourceFile as p, installedViteVersion as r, aliasReachedPaths as s, assertHostResolvesRunningVitest as t, isPlainJavaScript as u, normalizeBabelName as v, assertSupportedNode as w, fsModuleCacheKey as x, installedManifest as y };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as PEER_REQUIREMENTS, D as validateOptions, F as unsupportedExpoSdkMessage, I as unsupportedReactNativeMessage, M as belowRecommendedMessage, N as installedExpoVersion, O as validatePeerDependency, P as isBelowSupportedReactNative, S as shouldDefaultFsModuleCache, a as runningVite, b as readProjectSource, c as detectEcosystemPackages, d as
|
|
2
|
-
import { N as BUILT_IN_PRESET, t as presets_exports } from "./presets-
|
|
1
|
+
import { A as PEER_REQUIREMENTS, D as validateOptions, F as unsupportedExpoSdkMessage, I as unsupportedReactNativeMessage, M as belowRecommendedMessage, N as installedExpoVersion, O as validatePeerDependency, P as isBelowSupportedReactNative, S as shouldDefaultFsModuleCache, a as runningVite, b as readProjectSource, c as detectEcosystemPackages, d as detectEngine, f as createProjectBabel, j as SUPPORTED_EXPO_SDKS, k as warnUnknownOptions, m as missingBabelCoreNotice, n as assertHotWorkerLoadsRunningVitest, p as isProjectSourceFile, s as aliasReachedPaths, t as assertHostResolvesRunningVitest, w as assertSupportedNode, x as fsModuleCacheKey, y as installedManifest } from "./host-DGXnuRkW.mjs";
|
|
2
|
+
import { N as BUILT_IN_PRESET, t as presets_exports } from "./presets-C9Q7fY_z.mjs";
|
|
3
3
|
import { a as PRESET_MODULES, d as presetForInstalled, i as LIBRARY_SETUP_FILES, r as DEFAULT_ASSET_EXTS, s as autoDetectedPresetApplies, t as AUTO_DETECT_PRESETS, u as libraryRegistryEntries } from "./preset-map-DdAexIwz.mjs";
|
|
4
4
|
import { t as workerVitestMismatch } from "./worker-vitest-CILPFeRX.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
package/dist/jest-compat.cjs
CHANGED
|
@@ -381,7 +381,15 @@ function jestMockTransform(options = {}) {
|
|
|
381
381
|
const module = rootMockModules.get(id);
|
|
382
382
|
if (!module) return null;
|
|
383
383
|
const owner = projectsByRoot.get(module.root) ?? project;
|
|
384
|
-
|
|
384
|
+
const code = rootMocksSource(module, (spec) => owner.coveredBy(spec));
|
|
385
|
+
return {
|
|
386
|
+
code,
|
|
387
|
+
map: new magic_string.MagicString(code).generateMap({
|
|
388
|
+
hires: true,
|
|
389
|
+
includeContent: true,
|
|
390
|
+
source: id
|
|
391
|
+
})
|
|
392
|
+
};
|
|
385
393
|
},
|
|
386
394
|
transform(code, id) {
|
|
387
395
|
if (id.includes("/node_modules/")) return null;
|
package/dist/jest-compat.mjs
CHANGED
|
@@ -207,7 +207,15 @@ function jestMockTransform(options = {}) {
|
|
|
207
207
|
const module = rootMockModules.get(id);
|
|
208
208
|
if (!module) return null;
|
|
209
209
|
const owner = projectsByRoot.get(module.root) ?? project;
|
|
210
|
-
|
|
210
|
+
const code = rootMocksSource(module, (spec) => owner.coveredBy(spec));
|
|
211
|
+
return {
|
|
212
|
+
code,
|
|
213
|
+
map: new MagicString(code).generateMap({
|
|
214
|
+
hires: true,
|
|
215
|
+
includeContent: true,
|
|
216
|
+
source: id
|
|
217
|
+
})
|
|
218
|
+
};
|
|
211
219
|
},
|
|
212
220
|
transform(code, id) {
|
|
213
221
|
if (id.includes("/node_modules/")) return null;
|
|
@@ -408,7 +408,7 @@ function perComponent(create) {
|
|
|
408
408
|
* Reanimated's mock, with the names it answers with a no-op replaced (see
|
|
409
409
|
* REANIMATED_MOCK). Exported for its tests.
|
|
410
410
|
*/
|
|
411
|
-
function mockCorrections(mock, dir, fromRegistry = false, helpers = ownHelpers(dir, fromRegistry)) {
|
|
411
|
+
function mockCorrections(mock, dir, fromRegistry = false, helpers = ownHelpers(dir, fromRegistry), real = ownIndex(dir, fromRegistry)) {
|
|
412
412
|
const probes = {
|
|
413
413
|
interpolate: (f) => f(5, [0, 10], [0, 100]),
|
|
414
414
|
clamp: (f) => f(5, 0, 3),
|
|
@@ -471,6 +471,29 @@ function mockCorrections(mock, dir, fromRegistry = false, helpers = ownHelpers(d
|
|
|
471
471
|
};
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
|
+
if (real) {
|
|
475
|
+
const base = real.BaseAnimationBuilder;
|
|
476
|
+
for (const [name, own] of Object.entries(real)) if (typeof own === "function" && (own === base || typeof base === "function" && own.prototype instanceof base || name === "Keyframe") && name in mock && mock[name] !== own) fixed[name] = own;
|
|
477
|
+
}
|
|
478
|
+
if (typeof mock.useAnimatedRef === "function" && typeof gives("useAnimatedRef", (hook) => hook()) === "object") fixed.useAnimatedRef = () => perComponent(() => {
|
|
479
|
+
const ref = (node) => {
|
|
480
|
+
if (node !== void 0) ref.current = node;
|
|
481
|
+
return ref.current;
|
|
482
|
+
};
|
|
483
|
+
ref.current = null;
|
|
484
|
+
ref.observe = () => () => {};
|
|
485
|
+
ref.getTag = () => null;
|
|
486
|
+
return ref;
|
|
487
|
+
});
|
|
488
|
+
const runtime = gives("createWorkletRuntime", (hook) => hook({ name: "probe" }));
|
|
489
|
+
if (typeof mock.createWorkletRuntime === "function" && typeof runtime?.runtimeId !== "number") {
|
|
490
|
+
let next = 1;
|
|
491
|
+
fixed.createWorkletRuntime = (config) => ({
|
|
492
|
+
name: (typeof config === "string" ? config : config?.name) ?? "",
|
|
493
|
+
runtimeId: next++
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
if (typeof mock.runOnRuntime === "function" && typeof gives("runOnRuntime", (hook) => hook({}, () => {})) !== "function") fixed.runOnRuntime = (_runtime, worklet) => (...args) => worklet(...args);
|
|
474
497
|
if (typeof mock.setUpTests === "function") {
|
|
475
498
|
const own = mock.setUpTests;
|
|
476
499
|
fixed.setUpTests = (...args) => {
|
|
@@ -565,6 +588,20 @@ function useRefOrNull() {
|
|
|
565
588
|
function registryHolds(file) {
|
|
566
589
|
return globalThis[Symbol.for("vitest-native.node-dispatch")]?.channel("registry").libraryHolds?.(file) === true;
|
|
567
590
|
}
|
|
591
|
+
/**
|
|
592
|
+
* Reanimated's own index, which its mock imports (`from './index'`): the module the mock
|
|
593
|
+
* loaded, from the library registry that holds it beside the mock, or from Node's cache
|
|
594
|
+
* where the index loaded through Node (per-file module loading). Never a second copy:
|
|
595
|
+
* null where neither holds it (unit tests), and the corrections that need it stay off.
|
|
596
|
+
*/
|
|
597
|
+
function ownIndex(dir, fromRegistry) {
|
|
598
|
+
if (!fromRegistry) return null;
|
|
599
|
+
const index = path.join(dir, "src/index.ts");
|
|
600
|
+
const required = createRequire(path.join(dir, "package.json"));
|
|
601
|
+
const real = loadOrNull(() => ({ path: fs.realpathSync(index) }))?.path ?? index;
|
|
602
|
+
if (!registryHolds(index) && !required.cache[real] && !required.cache[index]) return null;
|
|
603
|
+
return loadOrNull(() => required(index));
|
|
604
|
+
}
|
|
568
605
|
/** What `load` returns, or null when it throws: not this version's layout, or not loadable here. */
|
|
569
606
|
function loadOrNull(load) {
|
|
570
607
|
try {
|
package/dist/presets.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { T as asyncStorage, s as bottomSheet, S as deviceInfo, C as expo, g as flashList, O as gestureHandler, a as keyboardController, x as mmkv, E as navigation, b as netInfo, j as reanimated, D as safeAreaContext, w as screens, n as skia, y as svg, r as unistyles, _ as vectorIcons, v as webview, i as worklets } from "./presets-
|
|
1
|
+
export { T as asyncStorage, s as bottomSheet, S as deviceInfo, C as expo, g as flashList, O as gestureHandler, a as keyboardController, x as mmkv, E as navigation, b as netInfo, j as reanimated, D as safeAreaContext, w as screens, n as skia, y as svg, r as unistyles, _ as vectorIcons, v as webview, i as worklets } from "./presets-C9Q7fY_z.mjs";
|
package/dist/setup.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as __require } from "./rolldown-runtime-D70C1uOS.mjs";
|
|
2
|
-
import { A as buildPressableHostProps, M as hostComponent, c as createTouchableWithoutFeedbackMock, d as createVirtualizedListMock, f as createSectionListMock, h as createTextInputMock, k as createPressableMock, l as createTouchableHighlightMock, m as createScrollViewMock, o as createViewMock, p as createFlatListMock, t as presets_exports, u as createTouchableOpacityMock } from "./presets-
|
|
2
|
+
import { A as buildPressableHostProps, M as hostComponent, c as createTouchableWithoutFeedbackMock, d as createVirtualizedListMock, f as createSectionListMock, h as createTextInputMock, k as createPressableMock, l as createTouchableHighlightMock, m as createScrollViewMock, o as createViewMock, p as createFlatListMock, t as presets_exports, u as createTouchableOpacityMock } from "./presets-C9Q7fY_z.mjs";
|
|
3
3
|
import { d as presetForInstalled, t as AUTO_DETECT_PRESETS } from "./preset-map-DdAexIwz.mjs";
|
|
4
4
|
import { animatedMatchers } from "./matchers.mjs";
|
|
5
5
|
import Module$1, { createRequire } from "node:module";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.15.0-rc.
|
|
3
|
+
"version": "0.15.0-rc.4",
|
|
4
4
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expo",
|
|
@@ -230,6 +230,7 @@
|
|
|
230
230
|
"react-native-reanimated": "4.7.1",
|
|
231
231
|
"react-native-safe-area-context": "5.11.0",
|
|
232
232
|
"react-native-skia": "3.8.1",
|
|
233
|
+
"react-native-svg": "15.16.0",
|
|
233
234
|
"react-native-unistyles": "3.7.0",
|
|
234
235
|
"react-native-worklets": "0.13.1",
|
|
235
236
|
"react-test-renderer": "^19.3.1",
|