vitest-native 0.10.0 → 0.11.1
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 +257 -0
- package/README.md +1 -0
- package/dist/cli.cjs +25 -7
- package/dist/cli.mjs +22 -4
- package/dist/{ecosystem-IuZ-Gv0R.cjs → ecosystem-DGlajfDG.cjs} +280 -14
- package/dist/{ecosystem-CO5vqExO.mjs → ecosystem-DJMGR2YY.mjs} +254 -12
- package/dist/helpers.cjs +1 -1
- package/dist/helpers.mjs +1 -1
- package/dist/{index-BJL4cQ-l.d.cts → index-CrMeE8rd.d.mts} +5 -5
- package/dist/{index-CvCU0cLl.d.mts → index-DIMbjH8R.d.cts} +6 -3
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +78 -48
- 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/native/hooks.mjs +77 -12
- package/dist/native/loader.mjs +10 -5
- package/dist/native/match.d.mts +33 -0
- package/dist/native/match.mjs +94 -22
- package/dist/native/registry.mjs +30 -2
- package/dist/{pool-CFND7plG.cjs → pool-BU-1ecIF.cjs} +6 -6
- package/dist/{pool-Bcxp4Qrg.mjs → pool-Bcxn9a3I.mjs} +3 -3
- package/dist/{preset-map-DxilQ4pI.cjs → preset-map-BoG19dLa.cjs} +1 -0
- package/dist/{preset-map-BpDG_D5m.mjs → preset-map-DuX0ocdn.mjs} +1 -0
- package/dist/{presets-BGTqVH6C.cjs → presets-CwO_c4aL.cjs} +131 -6
- package/dist/{presets-CK85x8ey.mjs → presets-IStcJEOa.mjs} +123 -4
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- 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 +1 -1
- package/dist/serializer.mjs +1 -1
- package/dist/setup.d.mts +1 -1
- package/dist/setup.mjs +5 -5
- package/docs/versioning.md +1 -1
- package/package.json +17 -15
- /package/dist/{errors-flXDIeWk.cjs → errors-B3lJK46O.cjs} +0 -0
- /package/dist/{errors-Dm5yLNTF.mjs → errors-CxoBUfVJ.mjs} +0 -0
package/dist/native/match.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which files belong to which package — the one place that decides it.
|
|
3
|
+
*
|
|
4
|
+
* The native engine splits the module graph between Vite and Node (the rule itself is
|
|
5
|
+
* written down in the header of apply.ts). Four places used to answer "does this file
|
|
6
|
+
* belong to a Node-owned package?" independently: the externalization patterns handed
|
|
7
|
+
* to Vitest, auto-detection, and the transform matchers in the require hook and the
|
|
8
|
+
* ESM loader. They agreed by construction rather than by structure, and three of the
|
|
9
|
+
* defects in this area were one of them disagreeing with the others — a directory
|
|
10
|
+
* anchor the transform side applied and the config side did not, a `node_modules`
|
|
11
|
+
* rule that also matched any folder sharing a package's name, and a separator
|
|
12
|
+
* mismatch that only appeared on Windows.
|
|
13
|
+
*
|
|
14
|
+
* Vitest's `server.deps.external` takes patterns rather than a predicate, so config
|
|
15
|
+
* time and run time cannot literally call the same function. They can be generated
|
|
16
|
+
* from the same rules, which is what `packagePatterns` is for: `buildPkgMatcher`
|
|
17
|
+
* tests exactly the patterns that were handed to Vitest.
|
|
18
|
+
*
|
|
19
|
+
* Everything here is pure. apply.ts bundles a copy into the plugin entry while the
|
|
20
|
+
* worker loads this file directly, so it must stay that way — module-level state
|
|
21
|
+
* would exist twice.
|
|
22
|
+
*/
|
|
1
23
|
import { createRequire } from "node:module";
|
|
2
24
|
import path from "node:path";
|
|
3
25
|
|
|
26
|
+
/** Any file under a node_modules directory. */
|
|
27
|
+
export const NODE_MODULES_PATH = /[\\/]node_modules[\\/]/;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* React Native's own source, including the `@react-native/*` packages. Node owns
|
|
31
|
+
* these unconditionally: the Flow strip, the boundary mocks and the precompiled
|
|
32
|
+
* registry are all Node loader hooks.
|
|
33
|
+
*/
|
|
34
|
+
export const REACT_NATIVE_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
35
|
+
|
|
4
36
|
/** Escape a string for literal use inside a RegExp. */
|
|
5
37
|
function escapeRe(value) {
|
|
6
38
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7
39
|
}
|
|
8
40
|
|
|
41
|
+
/** Forward slashes, the form Vitest presents module ids in. */
|
|
42
|
+
function toPosix(value) {
|
|
43
|
+
return value.replace(/\\/g, "/");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Does `dir` contain `target` (or equal it)?
|
|
48
|
+
*
|
|
49
|
+
* Used to recognise the package the run lives in. A package directory containing the
|
|
50
|
+
* Vitest root is the project, not a dependency of it — externalizing it hands Vitest
|
|
51
|
+
* its own source and test files back through Node, where they are compiled to
|
|
52
|
+
* CommonJS.
|
|
53
|
+
*
|
|
54
|
+
* Compared case-insensitively on Windows: `require.resolve` reports the on-disk
|
|
55
|
+
* casing while a working directory carries whatever the shell supplied, and a
|
|
56
|
+
* drive-letter difference alone would silently defeat the check.
|
|
57
|
+
*/
|
|
58
|
+
export function containsPath(dir, target) {
|
|
59
|
+
const normalize = (value) => {
|
|
60
|
+
const resolved = path.resolve(value);
|
|
61
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
62
|
+
};
|
|
63
|
+
const outer = normalize(dir);
|
|
64
|
+
const inner = normalize(target);
|
|
65
|
+
return inner === outer || inner.startsWith(outer.endsWith(path.sep) ? outer : outer + path.sep);
|
|
66
|
+
}
|
|
67
|
+
|
|
9
68
|
/**
|
|
10
69
|
* The on-disk directory a package resolves to, or null.
|
|
11
70
|
*
|
|
@@ -14,7 +73,7 @@ function escapeRe(value) {
|
|
|
14
73
|
* the manifest that names them. Symlinked and workspace packages resolve to their
|
|
15
74
|
* real location, which is the whole point — see buildPkgMatcher.
|
|
16
75
|
*/
|
|
17
|
-
function packageDirOf(name, projectRoot) {
|
|
76
|
+
export function packageDirOf(name, projectRoot) {
|
|
18
77
|
const req = createRequire(path.join(projectRoot, "package.json"));
|
|
19
78
|
try {
|
|
20
79
|
return path.dirname(req.resolve(`${name}/package.json`));
|
|
@@ -36,9 +95,9 @@ function packageDirOf(name, projectRoot) {
|
|
|
36
95
|
}
|
|
37
96
|
|
|
38
97
|
/**
|
|
39
|
-
*
|
|
98
|
+
* The patterns identifying one package's files. THE rule; everything else composes it.
|
|
40
99
|
*
|
|
41
|
-
* A bare `[/\]name[/\]` test — what this used to
|
|
100
|
+
* A bare `[/\]name[/\]` test — what this used to be — also matches any DIRECTORY
|
|
42
101
|
* that happens to share a package's name. A project folder called `expo`, or a source
|
|
43
102
|
* directory named after the library it implements, made every file beneath it look
|
|
44
103
|
* like third-party source to be compiled. That mis-compiled unrelated files, this
|
|
@@ -48,29 +107,42 @@ function packageDirOf(name, projectRoot) {
|
|
|
48
107
|
* workspace or `file:` dependency resolves to its real path, which has no
|
|
49
108
|
* `node_modules` segment at all. So a file matches if it is either
|
|
50
109
|
*
|
|
110
|
+
* - under `node_modules/<name>/` (covers additional copies of a package that a
|
|
111
|
+
* single resolution cannot see, and projects where resolution fails), or
|
|
51
112
|
* - inside the package's resolved directory (exact; covers workspace links, and
|
|
52
|
-
* stores like pnpm's and bun's)
|
|
53
|
-
*
|
|
54
|
-
*
|
|
113
|
+
* stores like pnpm's and bun's).
|
|
114
|
+
*
|
|
115
|
+
* The resolved-directory anchor is dropped when that directory CONTAINS the project
|
|
116
|
+
* root, because then it is the project. Externalizing the project hands Vitest its
|
|
117
|
+
* own source and test files back through Node, which compiles them to CommonJS: a
|
|
118
|
+
* test file's `import { it } from 'vitest'` becomes `require('vitest')` and throws.
|
|
55
119
|
*
|
|
56
|
-
* `projectRoot` is optional
|
|
57
|
-
*
|
|
120
|
+
* `projectRoot` is optional; without it only the `node_modules` rule applies, since
|
|
121
|
+
* there is nothing to resolve against.
|
|
58
122
|
*/
|
|
59
|
-
export function
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
if (projectRoot) {
|
|
64
|
-
|
|
65
|
-
const dir = packageDirOf(name, projectRoot);
|
|
66
|
-
if (dir) dirs.push(dir.replace(/\\/g, "/").replace(/\/$/, "") + "/");
|
|
67
|
-
}
|
|
123
|
+
export function packagePatterns(name, projectRoot) {
|
|
124
|
+
const patterns = [new RegExp(`[\\\\/]node_modules[\\\\/]${escapeRe(name)}[\\\\/]`)];
|
|
125
|
+
if (!projectRoot) return patterns;
|
|
126
|
+
const dir = packageDirOf(name, projectRoot);
|
|
127
|
+
if (dir && !containsPath(dir, projectRoot)) {
|
|
128
|
+
patterns.push(new RegExp(`^${escapeRe(toPosix(dir).replace(/\/$/, ""))}[\\\\/]`));
|
|
68
129
|
}
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
130
|
+
return patterns;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A predicate over the same patterns Vitest is given, so what the loader transforms
|
|
135
|
+
* and what Vitest externalizes cannot drift apart.
|
|
136
|
+
*
|
|
137
|
+
* Paths are normalised before testing: the directory anchor is written with forward
|
|
138
|
+
* slashes (the form Vitest presents module ids in) while callers here pass whatever
|
|
139
|
+
* Node handed them, which on Windows is backslashes.
|
|
140
|
+
*/
|
|
141
|
+
export function buildPkgMatcher(pkgs, projectRoot) {
|
|
142
|
+
const patterns = (pkgs || []).flatMap((name) => packagePatterns(name, projectRoot));
|
|
143
|
+
return (file) => {
|
|
144
|
+
const norm = toPosix(file);
|
|
145
|
+
return patterns.some((re) => re.test(norm));
|
|
74
146
|
};
|
|
75
147
|
}
|
|
76
148
|
|
package/dist/native/registry.mjs
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
// through to the per-file hooks in hooks.mjs / loader.mjs, and a failed build leaves
|
|
27
27
|
// the engine running exactly as it did before.
|
|
28
28
|
import Module from "node:module";
|
|
29
|
+
import { REACT_NATIVE_PATH } from "./match.mjs";
|
|
29
30
|
import { createRequire } from "node:module";
|
|
30
31
|
import path from "node:path";
|
|
31
32
|
import fs from "node:fs";
|
|
@@ -83,7 +84,6 @@ export function _resetRegistryFailureReports() {
|
|
|
83
84
|
reportedRegistryFailures.clear();
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
const RN_PATH = /[\\/]node_modules[\\/](react-native|@react-native)[\\/]/;
|
|
87
87
|
// Bump when the emitted registry's shape or the walk's semantics change, so a
|
|
88
88
|
// stale on-disk registry from an older vitest-native can never be reused.
|
|
89
89
|
const REGISTRY_FORMAT_VERSION = 2;
|
|
@@ -421,6 +421,11 @@ export function buildRegistry({
|
|
|
421
421
|
const options = { projectRoot, platform, reactNativeVersion, assetExtSet };
|
|
422
422
|
const modules = new Map();
|
|
423
423
|
const manifest = [];
|
|
424
|
+
// Targets the registry does NOT inline but DOES bake in as pre-resolved absolute
|
|
425
|
+
// paths. They belong in the manifest for the same reason React Native's own files
|
|
426
|
+
// do: if one moves or changes, the paths compiled into the registry are wrong.
|
|
427
|
+
// See the note above the manifest write below.
|
|
428
|
+
const externals = new Set();
|
|
424
429
|
try {
|
|
425
430
|
const entry = createRequire(path.join(projectRoot, "package.json")).resolve("react-native");
|
|
426
431
|
const queue = [entry];
|
|
@@ -440,10 +445,11 @@ export function buildRegistry({
|
|
|
440
445
|
// identity and are shared with the rest of the worker.
|
|
441
446
|
const internal =
|
|
442
447
|
target !== null &&
|
|
443
|
-
|
|
448
|
+
REACT_NATIVE_PATH.test(target.replace(/\\/g, "/")) &&
|
|
444
449
|
!PASSTHROUGH_EXT.has(path.extname(target).toLowerCase());
|
|
445
450
|
deps[request] = target;
|
|
446
451
|
if (internal) queue.push(target);
|
|
452
|
+
else if (target !== null) externals.add(target);
|
|
447
453
|
}
|
|
448
454
|
}
|
|
449
455
|
modules.set(file, { code, deps });
|
|
@@ -451,6 +457,28 @@ export function buildRegistry({
|
|
|
451
457
|
manifest.push([file, st.mtimeMs, st.size]);
|
|
452
458
|
}
|
|
453
459
|
|
|
460
|
+
// Externals are require()d through pre-resolved absolute paths baked into the
|
|
461
|
+
// emitted registry, so the registry is only valid while those paths still point
|
|
462
|
+
// at what they pointed at when it was built. Nothing noticed when they did not:
|
|
463
|
+
// upgrading React served a registry whose baked path was a react directory that
|
|
464
|
+
// no longer existed, and the fallback produced a second React — a null dispatcher
|
|
465
|
+
// and React Native singletons that stopped comparing equal.
|
|
466
|
+
//
|
|
467
|
+
// Naming the packages in the cache key instead would work only for the ones
|
|
468
|
+
// somebody remembered to name. Statting the resolved targets covers every
|
|
469
|
+
// external there is, and covers both node_modules layouts: under bun and pnpm a
|
|
470
|
+
// version change moves the path, so the stat fails; under a flat npm or yarn tree
|
|
471
|
+
// the path survives but the file's size and mtime change.
|
|
472
|
+
for (const target of externals) {
|
|
473
|
+
try {
|
|
474
|
+
const st = fs.statSync(target);
|
|
475
|
+
manifest.push([target, st.mtimeMs, st.size]);
|
|
476
|
+
} catch {
|
|
477
|
+
// Not a real file on disk (a native addon resolved elsewhere, a virtual
|
|
478
|
+
// target). Nothing to pin; the runtime require still decides.
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
454
482
|
const files = [...modules.keys()];
|
|
455
483
|
const { code, map } = emit(files, modules);
|
|
456
484
|
// Write via a unique temp file then rename: several workers may race here on a
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_errors = require("./errors-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_errors = require("./errors-B3lJK46O.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
|
-
node_path =
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
5
|
let node_module = require("node:module");
|
|
6
6
|
let node_os = require("node:os");
|
|
7
|
-
node_os =
|
|
7
|
+
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
8
8
|
let vitest_node = require("vitest/node");
|
|
9
9
|
//#region src/native/pool.ts
|
|
10
10
|
function deepEqual(a, b) {
|
|
@@ -62,8 +62,8 @@ var NativePoolWorker = class extends vitest_node.ThreadsPoolWorker {
|
|
|
62
62
|
return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
const HOT_MEMORY_MIN_BYTES =
|
|
66
|
-
const HOT_MEMORY_MAX_BYTES =
|
|
65
|
+
const HOT_MEMORY_MIN_BYTES = 805306368;
|
|
66
|
+
const HOT_MEMORY_MAX_BYTES = 1610612736;
|
|
67
67
|
const HOT_MEMORY_FRACTION = .25;
|
|
68
68
|
/**
|
|
69
69
|
* Default per-worker hot `memoryLimit` (bytes): `clamp(totalmem * 0.25, 768MB, 1.5GB)`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as VitestNativeError } from "./errors-
|
|
1
|
+
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import os from "node:os";
|
|
@@ -59,8 +59,8 @@ var NativePoolWorker = class extends ThreadsPoolWorker {
|
|
|
59
59
|
return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const HOT_MEMORY_MIN_BYTES =
|
|
63
|
-
const HOT_MEMORY_MAX_BYTES =
|
|
62
|
+
const HOT_MEMORY_MIN_BYTES = 805306368;
|
|
63
|
+
const HOT_MEMORY_MAX_BYTES = 1610612736;
|
|
64
64
|
const HOT_MEMORY_FRACTION = .25;
|
|
65
65
|
/**
|
|
66
66
|
* Default per-worker hot `memoryLimit` (bytes): `clamp(totalmem * 0.25, 768MB, 1.5GB)`.
|
|
@@ -18,6 +18,7 @@ const AUTO_DETECT_PRESETS = {
|
|
|
18
18
|
"expo-constants": "expo",
|
|
19
19
|
"react-native-device-info": "deviceInfo",
|
|
20
20
|
"react-native-mmkv": "mmkv",
|
|
21
|
+
"@react-native-community/netinfo": "netInfo",
|
|
21
22
|
"react-native-svg": "svg",
|
|
22
23
|
"react-native-webview": "webview",
|
|
23
24
|
"@react-native-vector-icons/common": "vectorIcons",
|
|
@@ -18,6 +18,7 @@ const AUTO_DETECT_PRESETS = {
|
|
|
18
18
|
"expo-constants": "expo",
|
|
19
19
|
"react-native-device-info": "deviceInfo",
|
|
20
20
|
"react-native-mmkv": "mmkv",
|
|
21
|
+
"@react-native-community/netinfo": "netInfo",
|
|
21
22
|
"react-native-svg": "svg",
|
|
22
23
|
"react-native-webview": "webview",
|
|
23
24
|
"@react-native-vector-icons/common": "vectorIcons",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_errors = require("./errors-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_errors = require("./errors-B3lJK46O.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
|
-
node_path =
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
5
|
let node_module = require("node:module");
|
|
6
6
|
let vitest = require("vitest");
|
|
7
7
|
let react = require("react");
|
|
8
|
-
react =
|
|
8
|
+
react = require_rolldown_runtime.__toESM(react, 1);
|
|
9
9
|
//#region src/presets/reanimated.ts
|
|
10
10
|
/**
|
|
11
11
|
* Resolve the *active* React Native module — the mock under `engine: 'mock'`
|
|
@@ -17,7 +17,8 @@ let _rnCache = null;
|
|
|
17
17
|
function getRN() {
|
|
18
18
|
if (_rnCache) return _rnCache;
|
|
19
19
|
try {
|
|
20
|
-
|
|
20
|
+
const base = node_path.default.join(process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd(), "package.json");
|
|
21
|
+
_rnCache = (0, node_module.createRequire)(base)("react-native");
|
|
21
22
|
} catch {
|
|
22
23
|
_rnCache = {};
|
|
23
24
|
}
|
|
@@ -1712,6 +1713,123 @@ function mmkv() {
|
|
|
1712
1713
|
};
|
|
1713
1714
|
}
|
|
1714
1715
|
//#endregion
|
|
1716
|
+
//#region src/presets/netinfo.ts
|
|
1717
|
+
/**
|
|
1718
|
+
* The state every fetch/listener resolves to until a test changes it.
|
|
1719
|
+
*
|
|
1720
|
+
* Derived from ONE constant so `_reset()` and the initial value cannot drift — the
|
|
1721
|
+
* failure mode where `beforeEach(_reset())` masks the default it claims to test.
|
|
1722
|
+
*
|
|
1723
|
+
* The real library starts at `{ type: 'unknown', isConnected: null, … }` and resolves
|
|
1724
|
+
* to the device's actual connection a moment later. A mock has no device, and a null
|
|
1725
|
+
* resting state would send every component under test down its offline branch, so the
|
|
1726
|
+
* resting state here is a connected wifi device — the same reasoning that gives
|
|
1727
|
+
* Dimensions a device-shaped default.
|
|
1728
|
+
*/
|
|
1729
|
+
const RESTING = {
|
|
1730
|
+
type: "wifi",
|
|
1731
|
+
isConnected: true,
|
|
1732
|
+
isInternetReachable: true,
|
|
1733
|
+
details: {
|
|
1734
|
+
isConnectionExpensive: false,
|
|
1735
|
+
ssid: null,
|
|
1736
|
+
bssid: null,
|
|
1737
|
+
strength: null,
|
|
1738
|
+
ipAddress: null,
|
|
1739
|
+
subnet: null,
|
|
1740
|
+
frequency: null,
|
|
1741
|
+
linkSpeed: null,
|
|
1742
|
+
rxLinkSpeed: null,
|
|
1743
|
+
txLinkSpeed: null
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
const state = () => structuredClone(RESTING);
|
|
1747
|
+
function netInfo() {
|
|
1748
|
+
return {
|
|
1749
|
+
name: "netInfo",
|
|
1750
|
+
modules: { "@react-native-community/netinfo": {
|
|
1751
|
+
exports: [
|
|
1752
|
+
"configure",
|
|
1753
|
+
"fetch",
|
|
1754
|
+
"refresh",
|
|
1755
|
+
"addEventListener",
|
|
1756
|
+
"useNetInfo",
|
|
1757
|
+
"useNetInfoInstance",
|
|
1758
|
+
"NetInfoStateType",
|
|
1759
|
+
"NetInfoCellularGeneration"
|
|
1760
|
+
],
|
|
1761
|
+
factory: () => {
|
|
1762
|
+
let current = state();
|
|
1763
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1764
|
+
const emit = () => {
|
|
1765
|
+
for (const listener of listeners) listener(current);
|
|
1766
|
+
};
|
|
1767
|
+
const fetch = vitest.vi.fn(async () => current);
|
|
1768
|
+
const refresh = vitest.vi.fn(async () => current);
|
|
1769
|
+
const configure = vitest.vi.fn(() => {
|
|
1770
|
+
listeners.clear();
|
|
1771
|
+
});
|
|
1772
|
+
const addEventListener = vitest.vi.fn((listener) => {
|
|
1773
|
+
listeners.add(listener);
|
|
1774
|
+
listener(current);
|
|
1775
|
+
return () => {
|
|
1776
|
+
listeners.delete(listener);
|
|
1777
|
+
};
|
|
1778
|
+
});
|
|
1779
|
+
const useNetInfo = vitest.vi.fn(() => current);
|
|
1780
|
+
const useNetInfoInstance = vitest.vi.fn(() => ({
|
|
1781
|
+
netInfo: current,
|
|
1782
|
+
refresh
|
|
1783
|
+
}));
|
|
1784
|
+
const NetInfoStateType = {
|
|
1785
|
+
unknown: "unknown",
|
|
1786
|
+
none: "none",
|
|
1787
|
+
cellular: "cellular",
|
|
1788
|
+
wifi: "wifi",
|
|
1789
|
+
bluetooth: "bluetooth",
|
|
1790
|
+
ethernet: "ethernet",
|
|
1791
|
+
wimax: "wimax",
|
|
1792
|
+
vpn: "vpn",
|
|
1793
|
+
other: "other"
|
|
1794
|
+
};
|
|
1795
|
+
const NetInfoCellularGeneration = {
|
|
1796
|
+
"2g": "2g",
|
|
1797
|
+
"3g": "3g",
|
|
1798
|
+
"4g": "4g",
|
|
1799
|
+
"5g": "5g"
|
|
1800
|
+
};
|
|
1801
|
+
const api = {
|
|
1802
|
+
configure,
|
|
1803
|
+
fetch,
|
|
1804
|
+
refresh,
|
|
1805
|
+
addEventListener,
|
|
1806
|
+
useNetInfo,
|
|
1807
|
+
useNetInfoInstance
|
|
1808
|
+
};
|
|
1809
|
+
return {
|
|
1810
|
+
...api,
|
|
1811
|
+
NetInfoStateType,
|
|
1812
|
+
NetInfoCellularGeneration,
|
|
1813
|
+
default: api,
|
|
1814
|
+
/** Drive the connection state from a test. */
|
|
1815
|
+
_setState: (next) => {
|
|
1816
|
+
current = {
|
|
1817
|
+
...current,
|
|
1818
|
+
...next
|
|
1819
|
+
};
|
|
1820
|
+
emit();
|
|
1821
|
+
},
|
|
1822
|
+
/** Internal: restore the resting state. Called by resetAllMocks(). */
|
|
1823
|
+
_reset: () => {
|
|
1824
|
+
current = state();
|
|
1825
|
+
listeners.clear();
|
|
1826
|
+
}
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
} }
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
//#endregion
|
|
1715
1833
|
//#region src/presets/svg.ts
|
|
1716
1834
|
const SVG_COMPONENTS = [
|
|
1717
1835
|
"Svg",
|
|
@@ -2601,7 +2719,7 @@ function worklets() {
|
|
|
2601
2719
|
}
|
|
2602
2720
|
//#endregion
|
|
2603
2721
|
//#region src/presets/index.ts
|
|
2604
|
-
var presets_exports = /* @__PURE__ */
|
|
2722
|
+
var presets_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
2605
2723
|
asyncStorage: () => asyncStorage,
|
|
2606
2724
|
bottomSheet: () => bottomSheet,
|
|
2607
2725
|
deviceInfo: () => deviceInfo,
|
|
@@ -2611,6 +2729,7 @@ var presets_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
|
2611
2729
|
keyboardController: () => keyboardController,
|
|
2612
2730
|
mmkv: () => mmkv,
|
|
2613
2731
|
navigation: () => navigation,
|
|
2732
|
+
netInfo: () => netInfo,
|
|
2614
2733
|
reanimated: () => reanimated,
|
|
2615
2734
|
safeAreaContext: () => safeAreaContext,
|
|
2616
2735
|
screens: () => screens,
|
|
@@ -2740,6 +2859,12 @@ Object.defineProperty(exports, "navigation", {
|
|
|
2740
2859
|
return navigation;
|
|
2741
2860
|
}
|
|
2742
2861
|
});
|
|
2862
|
+
Object.defineProperty(exports, "netInfo", {
|
|
2863
|
+
enumerable: true,
|
|
2864
|
+
get: function() {
|
|
2865
|
+
return netInfo;
|
|
2866
|
+
}
|
|
2867
|
+
});
|
|
2743
2868
|
Object.defineProperty(exports, "presets_exports", {
|
|
2744
2869
|
enumerable: true,
|
|
2745
2870
|
get: function() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as __exportAll } from "./
|
|
2
|
-
import { t as VitestNativeError } from "./errors-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { vi } from "vitest";
|
|
@@ -15,7 +15,8 @@ let _rnCache = null;
|
|
|
15
15
|
function getRN() {
|
|
16
16
|
if (_rnCache) return _rnCache;
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
const base = path.join(process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd(), "package.json");
|
|
19
|
+
_rnCache = createRequire(base)("react-native");
|
|
19
20
|
} catch {
|
|
20
21
|
_rnCache = {};
|
|
21
22
|
}
|
|
@@ -1710,6 +1711,123 @@ function mmkv() {
|
|
|
1710
1711
|
};
|
|
1711
1712
|
}
|
|
1712
1713
|
//#endregion
|
|
1714
|
+
//#region src/presets/netinfo.ts
|
|
1715
|
+
/**
|
|
1716
|
+
* The state every fetch/listener resolves to until a test changes it.
|
|
1717
|
+
*
|
|
1718
|
+
* Derived from ONE constant so `_reset()` and the initial value cannot drift — the
|
|
1719
|
+
* failure mode where `beforeEach(_reset())` masks the default it claims to test.
|
|
1720
|
+
*
|
|
1721
|
+
* The real library starts at `{ type: 'unknown', isConnected: null, … }` and resolves
|
|
1722
|
+
* to the device's actual connection a moment later. A mock has no device, and a null
|
|
1723
|
+
* resting state would send every component under test down its offline branch, so the
|
|
1724
|
+
* resting state here is a connected wifi device — the same reasoning that gives
|
|
1725
|
+
* Dimensions a device-shaped default.
|
|
1726
|
+
*/
|
|
1727
|
+
const RESTING = {
|
|
1728
|
+
type: "wifi",
|
|
1729
|
+
isConnected: true,
|
|
1730
|
+
isInternetReachable: true,
|
|
1731
|
+
details: {
|
|
1732
|
+
isConnectionExpensive: false,
|
|
1733
|
+
ssid: null,
|
|
1734
|
+
bssid: null,
|
|
1735
|
+
strength: null,
|
|
1736
|
+
ipAddress: null,
|
|
1737
|
+
subnet: null,
|
|
1738
|
+
frequency: null,
|
|
1739
|
+
linkSpeed: null,
|
|
1740
|
+
rxLinkSpeed: null,
|
|
1741
|
+
txLinkSpeed: null
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
const state = () => structuredClone(RESTING);
|
|
1745
|
+
function netInfo() {
|
|
1746
|
+
return {
|
|
1747
|
+
name: "netInfo",
|
|
1748
|
+
modules: { "@react-native-community/netinfo": {
|
|
1749
|
+
exports: [
|
|
1750
|
+
"configure",
|
|
1751
|
+
"fetch",
|
|
1752
|
+
"refresh",
|
|
1753
|
+
"addEventListener",
|
|
1754
|
+
"useNetInfo",
|
|
1755
|
+
"useNetInfoInstance",
|
|
1756
|
+
"NetInfoStateType",
|
|
1757
|
+
"NetInfoCellularGeneration"
|
|
1758
|
+
],
|
|
1759
|
+
factory: () => {
|
|
1760
|
+
let current = state();
|
|
1761
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1762
|
+
const emit = () => {
|
|
1763
|
+
for (const listener of listeners) listener(current);
|
|
1764
|
+
};
|
|
1765
|
+
const fetch = vi.fn(async () => current);
|
|
1766
|
+
const refresh = vi.fn(async () => current);
|
|
1767
|
+
const configure = vi.fn(() => {
|
|
1768
|
+
listeners.clear();
|
|
1769
|
+
});
|
|
1770
|
+
const addEventListener = vi.fn((listener) => {
|
|
1771
|
+
listeners.add(listener);
|
|
1772
|
+
listener(current);
|
|
1773
|
+
return () => {
|
|
1774
|
+
listeners.delete(listener);
|
|
1775
|
+
};
|
|
1776
|
+
});
|
|
1777
|
+
const useNetInfo = vi.fn(() => current);
|
|
1778
|
+
const useNetInfoInstance = vi.fn(() => ({
|
|
1779
|
+
netInfo: current,
|
|
1780
|
+
refresh
|
|
1781
|
+
}));
|
|
1782
|
+
const NetInfoStateType = {
|
|
1783
|
+
unknown: "unknown",
|
|
1784
|
+
none: "none",
|
|
1785
|
+
cellular: "cellular",
|
|
1786
|
+
wifi: "wifi",
|
|
1787
|
+
bluetooth: "bluetooth",
|
|
1788
|
+
ethernet: "ethernet",
|
|
1789
|
+
wimax: "wimax",
|
|
1790
|
+
vpn: "vpn",
|
|
1791
|
+
other: "other"
|
|
1792
|
+
};
|
|
1793
|
+
const NetInfoCellularGeneration = {
|
|
1794
|
+
"2g": "2g",
|
|
1795
|
+
"3g": "3g",
|
|
1796
|
+
"4g": "4g",
|
|
1797
|
+
"5g": "5g"
|
|
1798
|
+
};
|
|
1799
|
+
const api = {
|
|
1800
|
+
configure,
|
|
1801
|
+
fetch,
|
|
1802
|
+
refresh,
|
|
1803
|
+
addEventListener,
|
|
1804
|
+
useNetInfo,
|
|
1805
|
+
useNetInfoInstance
|
|
1806
|
+
};
|
|
1807
|
+
return {
|
|
1808
|
+
...api,
|
|
1809
|
+
NetInfoStateType,
|
|
1810
|
+
NetInfoCellularGeneration,
|
|
1811
|
+
default: api,
|
|
1812
|
+
/** Drive the connection state from a test. */
|
|
1813
|
+
_setState: (next) => {
|
|
1814
|
+
current = {
|
|
1815
|
+
...current,
|
|
1816
|
+
...next
|
|
1817
|
+
};
|
|
1818
|
+
emit();
|
|
1819
|
+
},
|
|
1820
|
+
/** Internal: restore the resting state. Called by resetAllMocks(). */
|
|
1821
|
+
_reset: () => {
|
|
1822
|
+
current = state();
|
|
1823
|
+
listeners.clear();
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
} }
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
//#endregion
|
|
1713
1831
|
//#region src/presets/svg.ts
|
|
1714
1832
|
const SVG_COMPONENTS = [
|
|
1715
1833
|
"Svg",
|
|
@@ -2609,6 +2727,7 @@ var presets_exports = /* @__PURE__ */ __exportAll({
|
|
|
2609
2727
|
keyboardController: () => keyboardController,
|
|
2610
2728
|
mmkv: () => mmkv,
|
|
2611
2729
|
navigation: () => navigation,
|
|
2730
|
+
netInfo: () => netInfo,
|
|
2612
2731
|
reanimated: () => reanimated,
|
|
2613
2732
|
safeAreaContext: () => safeAreaContext,
|
|
2614
2733
|
screens: () => screens,
|
|
@@ -2618,4 +2737,4 @@ var presets_exports = /* @__PURE__ */ __exportAll({
|
|
|
2618
2737
|
worklets: () => worklets
|
|
2619
2738
|
});
|
|
2620
2739
|
//#endregion
|
|
2621
|
-
export {
|
|
2740
|
+
export { asyncStorage as C, createPressableMock as D, gestureHandler as E, buildPressableHostProps as O, screens as S, safeAreaContext as T, svg as _, bottomSheet as a, deviceInfo as b, createTouchableOpacityMock as c, createFlatListMock as d, createScrollViewMock as f, webview as g, vectorIcons as h, createViewMock as i, reanimated as k, createVirtualizedListMock as l, flashList as m, worklets as n, createTouchableWithoutFeedbackMock as o, createTextInputMock as p, keyboardController as r, createTouchableHighlightMock as s, presets_exports as t, createSectionListMock as u, netInfo as v, navigation as w, expo as x, mmkv as y };
|
package/dist/presets.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
1
|
+
import { _ as gestureHandler, a as flashList, c as svg, d as deviceInfo, f as expo, g as safeAreaContext, h as navigation, i as bottomSheet, l as netInfo, m as asyncStorage, n as worklets, o as vectorIcons, p as screens, r as keyboardController, s as webview, u as mmkv, v as reanimated } from "./index-CrMeE8rd.mjs";
|
|
2
|
+
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
package/dist/presets.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
1
|
+
import { C as asyncStorage, E as gestureHandler, S as screens, T as safeAreaContext, _ as svg, a as bottomSheet, b as deviceInfo, g as webview, h as vectorIcons, k as reanimated, m as flashList, n as worklets, r as keyboardController, v as netInfo, w as navigation, x as expo, y as mmkv } from "./presets-IStcJEOa.mjs";
|
|
2
|
+
export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
|
|
@@ -10,6 +10,6 @@ var __exportAll = (all, no_symbols) => {
|
|
|
10
10
|
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
11
11
|
return target;
|
|
12
12
|
};
|
|
13
|
-
var __require = /*
|
|
13
|
+
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
14
14
|
//#endregion
|
|
15
15
|
export { __require as n, __exportAll as t };
|
|
@@ -24,7 +24,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
}
|
|
25
25
|
return to;
|
|
26
26
|
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
28
28
|
value: mod,
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
package/dist/serializer.cjs
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
9
9
|
* Usage: expect.addSnapshotSerializer(serializer)
|
|
10
10
|
*/
|
|
11
11
|
/** Props that are React internals and should be omitted from snapshot output. */
|
|
12
|
-
const INTERNAL_PROPS = new Set([
|
|
12
|
+
const INTERNAL_PROPS = /* @__PURE__ */ new Set([
|
|
13
13
|
"__reactFiber",
|
|
14
14
|
"__reactInternalInstance",
|
|
15
15
|
"__reactEvents",
|