vitest-native 0.15.0-rc.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/cli.mjs +116 -12
- package/dist/{host-DGXnuRkW.mjs → host-TAGjG56H.mjs} +10 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +63 -4
- package/dist/native/loader.mjs +13 -3
- package/dist/{presets-C9Q7fY_z.mjs → presets-DLH7uRGA.mjs} +434 -377
- package/dist/presets.mjs +1 -1
- package/dist/setup.mjs +2 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
<h1>
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/danfry1/vitest-native/main/website/public/lockup-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/danfry1/vitest-native/main/website/public/lockup.svg" alt="vitest-native" width="335" height="64">
|
|
5
|
+
</picture>
|
|
6
|
+
</h1>
|
|
2
7
|
|
|
3
8
|
[](https://www.npmjs.com/package/vitest-native)
|
|
4
9
|
[](https://npmcharts.com/compare/vitest-native?interval=30)
|
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 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-
|
|
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-TAGjG56H.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";
|
|
@@ -277,6 +277,16 @@ function serializableOptions(entry) {
|
|
|
277
277
|
};
|
|
278
278
|
return entry.options === void 0 || plain(entry.options);
|
|
279
279
|
}
|
|
280
|
+
// src/regexp.ts
|
|
281
|
+
/**
|
|
282
|
+
* `text` as a RegExp source that matches exactly that text. Every value interpolated into
|
|
283
|
+
* a RegExp goes through an escape helper (lint rule vitest-native/escaped-regexp): a
|
|
284
|
+
* path, package name or identifier can hold `.`, `+`, `(` or `$`, which otherwise match
|
|
285
|
+
* more, or less, than themselves.
|
|
286
|
+
*/
|
|
287
|
+
function escapeRegExp(text) {
|
|
288
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
289
|
+
}
|
|
280
290
|
// src/cli/doctor.ts
|
|
281
291
|
/**
|
|
282
292
|
* `vitest-native doctor` — diagnose the project's environment: peer versions,
|
|
@@ -362,12 +372,97 @@ function extendsSharedConfig(source) {
|
|
|
362
372
|
const bindings = [...clause.matchAll(/([A-Za-z_$][\w$]*)/g)].map((m) => m[1]);
|
|
363
373
|
for (const binding of bindings) {
|
|
364
374
|
if (binding === "defineConfig" || binding === "default") continue;
|
|
365
|
-
if (new RegExp(`export\\s+default\\s+${binding}\\s*;?\\s*$`, "m").test(code)) return true;
|
|
366
|
-
if (new RegExp(`\\bmergeConfig\\s*\\(\\s*${binding}\\
|
|
375
|
+
if (new RegExp(`export\\s+default\\s+${escapeRegExp(binding)}\\s*;?\\s*$`, "m").test(code)) return true;
|
|
376
|
+
if (new RegExp(`\\bmergeConfig\\s*\\(\\s*${escapeRegExp(binding)}(?![\\w$])`).test(code)) return true;
|
|
367
377
|
}
|
|
368
378
|
}
|
|
369
379
|
return false;
|
|
370
380
|
}
|
|
381
|
+
/** Source extensions a shared config module can have, in the order a relative import tries them. */
|
|
382
|
+
const CONFIG_MODULE_EXTENSIONS = [
|
|
383
|
+
".ts",
|
|
384
|
+
".mts",
|
|
385
|
+
".cts",
|
|
386
|
+
".js",
|
|
387
|
+
".mjs",
|
|
388
|
+
".cjs"
|
|
389
|
+
];
|
|
390
|
+
/** How many relative imports deep the config is followed (config → shared → its base). */
|
|
391
|
+
const SHARED_CONFIG_DEPTH = 3;
|
|
392
|
+
const RELATIVE_SPECIFIER = /(?:\bfrom\s*|\bimport\s*\(\s*|\brequire\s*\(\s*|\bimport\s+)["'](\.{1,2}\/[^"']+)["']/g;
|
|
393
|
+
/** The relative modules `code` imports (static, dynamic, side-effect, require). */
|
|
394
|
+
function relativeSpecifiers(code) {
|
|
395
|
+
return [...new Set([...code.matchAll(RELATIVE_SPECIFIER)].map((m) => m[1]))];
|
|
396
|
+
}
|
|
397
|
+
/** A relative import as a file, as Vite resolves it: as written, by extension, as a directory index. */
|
|
398
|
+
function resolveConfigModule(fromFile, specifier) {
|
|
399
|
+
const base = path.resolve(path.dirname(fromFile), specifier);
|
|
400
|
+
const stem = /\.[cm]?js$/.test(base) ? base.replace(/\.([cm]?)js$/, "") : null;
|
|
401
|
+
return [
|
|
402
|
+
base,
|
|
403
|
+
...CONFIG_MODULE_EXTENSIONS.map((ext) => base + ext),
|
|
404
|
+
...stem ? [
|
|
405
|
+
".ts",
|
|
406
|
+
".mts",
|
|
407
|
+
".cts"
|
|
408
|
+
].map((ext) => stem + ext) : [],
|
|
409
|
+
...CONFIG_MODULE_EXTENSIONS.map((ext) => path.join(base, `index${ext}`))
|
|
410
|
+
].find((file) => fs.statSync(file, { throwIfNoEntry: false })?.isFile()) ?? null;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Whether a config that does not import vitest-native itself builds on a module that does:
|
|
414
|
+
* a monorepo package's config merging a shared `../../vitest.shared.ts`, say. The config's
|
|
415
|
+
* relative imports are followed up to SHARED_CONFIG_DEPTH deep, each module once. A
|
|
416
|
+
* relative import that cannot be resolved or read, or the depth running out, leaves it
|
|
417
|
+
* unconfirmed rather than "does not import".
|
|
418
|
+
*/
|
|
419
|
+
function sharedConfigUse(configFile) {
|
|
420
|
+
const shown = (file) => path.relative(path.dirname(configFile), file).split(path.sep).join("/");
|
|
421
|
+
const seen = /* @__PURE__ */ new Set([path.resolve(configFile)]);
|
|
422
|
+
let unconfirmed = null;
|
|
423
|
+
const note = (reason) => unconfirmed ??= reason;
|
|
424
|
+
let level = [path.resolve(configFile)];
|
|
425
|
+
for (let depth = 1; level.length > 0; depth++) {
|
|
426
|
+
const next = [];
|
|
427
|
+
for (const file of level) {
|
|
428
|
+
let source;
|
|
429
|
+
try {
|
|
430
|
+
source = fs.readFileSync(file, "utf8");
|
|
431
|
+
} catch (error) {
|
|
432
|
+
note(`${shown(file)} could not be read (${error.code ?? "error"})`);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const code = withoutComments$1(source);
|
|
436
|
+
if (file !== path.resolve(configFile)) {
|
|
437
|
+
const usage = analyzeConfigUsage(source);
|
|
438
|
+
if (usage.imports && usage.invokes) return {
|
|
439
|
+
via: shown(file),
|
|
440
|
+
unconfirmed: null
|
|
441
|
+
};
|
|
442
|
+
if (usage.imports) note(`${shown(file)} imports vitest-native but does not call reactNative() there`);
|
|
443
|
+
}
|
|
444
|
+
for (const specifier of relativeSpecifiers(code)) {
|
|
445
|
+
const target = resolveConfigModule(file, specifier);
|
|
446
|
+
if (!target) {
|
|
447
|
+
note(`'${specifier}' (imported by ${shown(file)}) could not be resolved`);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (!CONFIG_MODULE_EXTENSIONS.includes(path.extname(target)) || seen.has(target)) continue;
|
|
451
|
+
if (depth > SHARED_CONFIG_DEPTH) {
|
|
452
|
+
note(`it builds on modules more than ${SHARED_CONFIG_DEPTH} imports deep`);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
seen.add(target);
|
|
456
|
+
next.push(target);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
level = next;
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
via: null,
|
|
463
|
+
unconfirmed
|
|
464
|
+
};
|
|
465
|
+
}
|
|
371
466
|
/**
|
|
372
467
|
* Whether a config genuinely uses the plugin.
|
|
373
468
|
*
|
|
@@ -399,12 +494,12 @@ function analyzeConfigUsage(source) {
|
|
|
399
494
|
};
|
|
400
495
|
return {
|
|
401
496
|
imports: true,
|
|
402
|
-
invokes: new RegExp(
|
|
497
|
+
invokes: new RegExp(`(?<![\\w$])${escapeRegExp(binding)}\\s*\\(`).test(code)
|
|
403
498
|
};
|
|
404
499
|
}
|
|
405
500
|
if (namespaced) return {
|
|
406
501
|
imports: true,
|
|
407
|
-
invokes: new RegExp(
|
|
502
|
+
invokes: new RegExp(`(?<![\\w$])${escapeRegExp(namespaced[1])}\\.\\w+\\s*\\(`).test(code)
|
|
408
503
|
};
|
|
409
504
|
if (/from\s*["']vitest-native["']|require\(\s*["']vitest-native["']\s*\)/.test(code)) return {
|
|
410
505
|
imports: true,
|
|
@@ -588,6 +683,10 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
588
683
|
else {
|
|
589
684
|
const content = fs.readFileSync(path.join(configRoot, configFile), "utf8");
|
|
590
685
|
const usage = analyzeConfigUsage(content);
|
|
686
|
+
let shared = {
|
|
687
|
+
via: null,
|
|
688
|
+
unconfirmed: null
|
|
689
|
+
};
|
|
591
690
|
const code = withoutComments$1(content);
|
|
592
691
|
if (/@rolldown\/plugin-babel|vite-plugin-babel/.test(code)) {
|
|
593
692
|
const listed = new Set([...code.matchAll(/["'`]([^"'`\s]+)["'`]/g)].map((m) => normalizeBabelName(m[1])));
|
|
@@ -602,7 +701,9 @@ function runDoctor(root, nodeVersion = process.versions.node) {
|
|
|
602
701
|
if (model === "resolution") lines.push(" · 'resolution' turns on experimental.nodeMocks: a vi.mock also reaches the modules Node loads, and a mock Node cannot have synchronously fails as MOCK_NOT_SEEN_BY_NODE.");
|
|
603
702
|
}
|
|
604
703
|
} else if (usage.imports) warn(`${configFile} imports vitest-native but never calls reactNative() — the plugin is not in \`plugins: [...]\`, so React Native imports will not resolve.`);
|
|
704
|
+
else if ((shared = sharedConfigUse(path.join(configRoot, configFile))).via) pass(`${configFile} uses vitest-native through ${shared.via}.`);
|
|
605
705
|
else if (extendsSharedConfig(content)) lines.push(` · ${configFile} builds on a shared config, so this cannot tell from here whether the plugin is wired up. Check the config it extends.`);
|
|
706
|
+
else if (shared.unconfirmed) lines.push(` · couldn't confirm that ${configFile} uses vitest-native: it does not import it itself, and ${shared.unconfirmed}. Check that reactNative() is in its plugins.`);
|
|
606
707
|
else warn(`${configFile} exists but does not import vitest-native` + (content.includes("vitest-native") ? " (it is only mentioned in a comment)" : "") + " — add `reactNative()` to `plugins: [...]`, or run `vitest-native init`.");
|
|
607
708
|
}
|
|
608
709
|
lines.push("", ok ? "✓ No blocking problems found." : "✗ Blocking problems found (see ✗ above).");
|
|
@@ -2003,7 +2104,12 @@ function analyzeJestConfig(root) {
|
|
|
2003
2104
|
const setupFiles = ["jestCompatSetup"];
|
|
2004
2105
|
const aliasEntries = [];
|
|
2005
2106
|
const aliasKeys = /* @__PURE__ */ new Set();
|
|
2006
|
-
const
|
|
2107
|
+
const aliasArray = [];
|
|
2108
|
+
let regexAlias = false;
|
|
2109
|
+
const addRegexAlias = (entry) => {
|
|
2110
|
+
aliasArray.push(entry);
|
|
2111
|
+
regexAlias = true;
|
|
2112
|
+
};
|
|
2007
2113
|
const transformPkgs = [];
|
|
2008
2114
|
const extraImports = [];
|
|
2009
2115
|
const extraPlugins = [];
|
|
@@ -2025,6 +2131,7 @@ function analyzeJestConfig(root) {
|
|
|
2025
2131
|
if (aliasKeys.has(key)) return false;
|
|
2026
2132
|
aliasKeys.add(key);
|
|
2027
2133
|
aliasEntries.push(`${JSON.stringify(key)}: ${value}`);
|
|
2134
|
+
aliasArray.push(`{ find: ${JSON.stringify(key)}, replacement: ${value} }`);
|
|
2028
2135
|
return true;
|
|
2029
2136
|
};
|
|
2030
2137
|
const projectSource = (file) => {
|
|
@@ -2106,7 +2213,7 @@ function analyzeJestConfig(root) {
|
|
|
2106
2213
|
}
|
|
2107
2214
|
} else if (plainPrefix) {
|
|
2108
2215
|
const find = `${regexLiteral(plainPrefix.key).slice(0, -2)}\\/(${plainPrefix.rest})$/`;
|
|
2109
|
-
|
|
2216
|
+
addRegexAlias(`{ find: ${find}, replacement: ${absolutePath(plainPrefix.dir)} + "/$1" }`);
|
|
2110
2217
|
automatic.push(`moduleNameMapper '${pattern}' → resolve.alias { find: ${find} } (absolute path).`);
|
|
2111
2218
|
} else if (/^\^?@\/|\^~\/|\^src\//.test(pattern)) {
|
|
2112
2219
|
const aliasKey = pattern.replace(/[\^$]/g, "").replace(/\((\.\*|\.\+)\)\$?$/, "").replace(/\/$/, "");
|
|
@@ -2120,7 +2227,7 @@ function analyzeJestConfig(root) {
|
|
|
2120
2227
|
if (packageOfPath(target) === splitSpecifier(literal).pkg && packageServes(root, literal)) dropped.push(`moduleNameMapper '${pattern}' → '${target}' — '${literal}' is served by its package's exports, which Vite and Node resolve (Jest's CommonJS resolver could not); dropped.`);
|
|
2121
2228
|
else {
|
|
2122
2229
|
const replacement = target.startsWith("<rootDir>") ? absolutePath(target.replace(/^<rootDir>\/?/, "./")) : target.startsWith(".") ? absolutePath(target) : JSON.stringify(target);
|
|
2123
|
-
|
|
2230
|
+
addRegexAlias(`{ find: ${regexLiteral(literal)}, replacement: ${replacement} }`);
|
|
2124
2231
|
automatic.push(`moduleNameMapper '${pattern}' → resolve.alias { find: ${regexLiteral(literal)} } (anchored: a string find would also catch '${literal}/…').`);
|
|
2125
2232
|
}
|
|
2126
2233
|
} else attention.push(`moduleNameMapper '${pattern}' → '${String(target)}' — map manually to resolve.alias (regex mappers need rewriting).`);
|
|
@@ -2368,10 +2475,7 @@ function analyzeJestConfig(root) {
|
|
|
2368
2475
|
if (transformPkgs.length) pluginOptions.unshift(`transform: [${transformPkgs.map((p) => JSON.stringify(p)).join(", ")}]`);
|
|
2369
2476
|
const transformLine = pluginOptions.length ? `reactNative({ ${pluginOptions.join(", ")} })` : `reactNative()`;
|
|
2370
2477
|
if (excludeGlobs.length) testEntries.push(`exclude: [...configDefaults.exclude, ${excludeGlobs.map((g) => JSON.stringify(g)).join(", ")}]`);
|
|
2371
|
-
const aliasSource =
|
|
2372
|
-
const at = e.indexOf(": ");
|
|
2373
|
-
return ` { find: ${e.slice(0, at)}, replacement: ${e.slice(at + 2)} },\n`;
|
|
2374
|
-
}).join("") + regexAliases.map((e) => ` ${e},\n`).join("") + ` ]` : `{ ${["...jestCompatAliases()", ...aliasEntries].join(", ")} }`;
|
|
2478
|
+
const aliasSource = regexAlias ? `[\n ...Object.entries(jestCompatAliases()).map(([find, replacement]) => ({ find, replacement })),\n` + aliasArray.map((e) => ` ${e},\n`).join("") + ` ]` : `{ ${["...jestCompatAliases()", ...aliasEntries].join(", ")} }`;
|
|
2375
2479
|
const vitePlus = usesVitePlus(root);
|
|
2376
2480
|
return {
|
|
2377
2481
|
source,
|
|
@@ -1153,7 +1153,16 @@ function createProjectBabel(root, mode, options, announce = () => {}) {
|
|
|
1153
1153
|
for (const reason of fresh) announced.add(reason);
|
|
1154
1154
|
announce(fresh);
|
|
1155
1155
|
};
|
|
1156
|
-
const
|
|
1156
|
+
const rootSpellingById = /* @__PURE__ */ new Map();
|
|
1157
|
+
const projectRootOf = (id) => {
|
|
1158
|
+
if (!isProjectSourceFile(id)) return null;
|
|
1159
|
+
let spelling = rootSpellingById.get(id);
|
|
1160
|
+
if (spelling === void 0) {
|
|
1161
|
+
spelling = rootSpellingOf(root, path.normalize(id));
|
|
1162
|
+
rootSpellingById.set(id, spelling);
|
|
1163
|
+
}
|
|
1164
|
+
return spelling;
|
|
1165
|
+
};
|
|
1157
1166
|
const versionOf = (item) => {
|
|
1158
1167
|
const file = item.file?.resolved;
|
|
1159
1168
|
if (!file) return "inline";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as VitestNativeOptions, S as ReactNativeMock, t as index_d_exports, x as Preset } from "./index-BpZ0E2eJ.mjs";
|
|
2
|
-
import { Plugin } from "vite";
|
|
3
2
|
import "./context.mjs";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
4
|
/**
|
|
5
5
|
* Preset names switched off by the object form of the `presets` option.
|
|
6
6
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
2
|
-
import {
|
|
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";
|
|
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-TAGjG56H.mjs";
|
|
2
|
+
import { A as KEYBOARD_CONTROLLER_MOCK, F as BUILT_IN_PRESET, O as SAFE_AREA_MOCK, t as presets_exports } from "./presets-DLH7uRGA.mjs";
|
|
3
|
+
import { a as PRESET_MODULES, c as libraryMockDir, 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";
|
|
6
6
|
import { extensionsFor, firstExact, platformSubpathFile } from "./native/resolve.mjs";
|
|
@@ -12,6 +12,7 @@ import flowRemoveTypes from "flow-remove-types";
|
|
|
12
12
|
import { VitestNativeError, VitestNativeTypeError } from "./errors.mjs";
|
|
13
13
|
import { docsUrl } from "./docs-url.mjs";
|
|
14
14
|
import { presetFromModule } from "./preset-modules.mjs";
|
|
15
|
+
import { CONTEXT_ENV, ensureProjectContext, projectContext, writeProjectContext } from "./context.mjs";
|
|
15
16
|
import { serializableAliases } from "./jest-compat/aliases.mjs";
|
|
16
17
|
import { tsconfigPathAliases } from "./native/tsconfig-paths.mjs";
|
|
17
18
|
import { aliasList, checkResolverInputs, conditionsIn, createSharedResolver, identityKey, nodeDefaultConditions, nodeOptionsList, ownershipShadowFile, resolverInputsHash, serializeResolutionAliases } from "./native/shared-resolver.mjs";
|
|
@@ -21,7 +22,6 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
21
22
|
import { transformWithOxc } from "vite";
|
|
22
23
|
import { containsPath, dependencyDirOf, isPackageEntryFile, memoizePackageDirOf, packageDirOf } from "./native/match.mjs";
|
|
23
24
|
import { OWNERSHIP_META_KEY, OWNERSHIP_ROUTES, viteMarkerFor } from "./native/ownership-ledger.mjs";
|
|
24
|
-
import { CONTEXT_ENV, ensureProjectContext, projectContext, writeProjectContext } from "./context.mjs";
|
|
25
25
|
import { cacheRootFor } from "./native/transform.mjs";
|
|
26
26
|
import { HangWatch, debugging, hangTimeoutFor } from "./hang-watch.mjs";
|
|
27
27
|
import inspector from "node:inspector";
|
|
@@ -42,6 +42,53 @@ function getPlatformExtensions(platform) {
|
|
|
42
42
|
function getConfiguredPlatformExtensions(platform, sourceExts) {
|
|
43
43
|
return extensionsFor(platform, sourceExts);
|
|
44
44
|
}
|
|
45
|
+
// src/fresh-runtime-presets.ts
|
|
46
|
+
/**
|
|
47
|
+
* The presets whose module, as served, uses React through vitest-native's own dist (a
|
|
48
|
+
* module-scope `import React`). The hot runtime keeps that dist resident, so under
|
|
49
|
+
* `hotRuntime.freshRuntime`, where React is evaluated again for each file, these modules
|
|
50
|
+
* keep the first file's React, and later files fail with "Invalid hook call" or read a
|
|
51
|
+
* default (#719). While one is active, freshRuntime declines and React stays resident.
|
|
52
|
+
*
|
|
53
|
+
* reanimated corrects even the library's own mock with React-using helpers, and
|
|
54
|
+
* bottomSheet serves the names the library's mock lacks from its built-in module, so
|
|
55
|
+
* both count whichever module they serve.
|
|
56
|
+
*
|
|
57
|
+
* Temporary: removed when the preset factories take React from the file's own require.
|
|
58
|
+
*/
|
|
59
|
+
const HOLD_REACT = /* @__PURE__ */ new Set([
|
|
60
|
+
"bottomSheet",
|
|
61
|
+
"expo",
|
|
62
|
+
"flashList",
|
|
63
|
+
"gestureHandler",
|
|
64
|
+
"keyboardController",
|
|
65
|
+
"mmkv",
|
|
66
|
+
"navigation",
|
|
67
|
+
"reanimated",
|
|
68
|
+
"safeAreaContext",
|
|
69
|
+
"screens",
|
|
70
|
+
"svg",
|
|
71
|
+
"unistyles",
|
|
72
|
+
"vectorIcons",
|
|
73
|
+
"webview"
|
|
74
|
+
]);
|
|
75
|
+
/** Presets that serve the library's own Jest mock, which does not use the preset's React, when it is installed. */
|
|
76
|
+
const NOT_WITH_OWN_MOCK = {
|
|
77
|
+
safeAreaContext: SAFE_AREA_MOCK,
|
|
78
|
+
keyboardController: KEYBOARD_CONTROLLER_MOCK
|
|
79
|
+
};
|
|
80
|
+
/** The active presets, by name, whose served module holds React per worker. */
|
|
81
|
+
function presetsHoldingReact(presetNames, projectRoot) {
|
|
82
|
+
return presetNames.filter((name) => {
|
|
83
|
+
if (!HOLD_REACT.has(name)) return false;
|
|
84
|
+
const mock = NOT_WITH_OWN_MOCK[name];
|
|
85
|
+
return mock === void 0 || libraryMockDir(mock, projectRoot) === null;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** The one line printed when freshRuntime declines. */
|
|
89
|
+
function freshRuntimeDeclinedNotice(names) {
|
|
90
|
+
return `[vitest-native] hotRuntime.freshRuntime declined: ${names.join(", ")} ${names.length === 1 ? "holds" : "hold"} React per worker (#719). React stays resident, as without freshRuntime.`;
|
|
91
|
+
}
|
|
45
92
|
// src/native/apply.ts
|
|
46
93
|
/**
|
|
47
94
|
* Vite/Vitest config fragment for the native engine.
|
|
@@ -590,6 +637,7 @@ async function startRegistryFor(options) {
|
|
|
590
637
|
}
|
|
591
638
|
/** Recommended-floor warnings already printed in this process. */
|
|
592
639
|
const warnedRecommended = /* @__PURE__ */ new Set();
|
|
640
|
+
const freshRuntimeNotices = /* @__PURE__ */ new Set();
|
|
593
641
|
/** Vitest instances whose close already settles the background registry builds. */
|
|
594
642
|
const registrySettlers = /* @__PURE__ */ new WeakSet();
|
|
595
643
|
/** Load declarative Metro data without retaining Metro/Expo in Vite's process. */
|
|
@@ -1756,6 +1804,17 @@ function reactNative(options) {
|
|
|
1756
1804
|
const selection = selectPresets(options?.presets, resolvedRoot);
|
|
1757
1805
|
const nativePresetNames = selection.listed ? selection.listed.map((p) => p.name) : autoDetectPresetNames(resolvedRoot, diagnostics).filter((n) => !disabledNative.has(n) && autoDetectedPresetApplies(n, "native", options?.presets));
|
|
1758
1806
|
if (nativePresetNames.length > 0) fields.presetNames = nativePresetNames;
|
|
1807
|
+
if (fields.hotFreshRuntime === true) {
|
|
1808
|
+
const holding = presetsHoldingReact(nativePresetNames, resolvedRoot);
|
|
1809
|
+
if (holding.length > 0) {
|
|
1810
|
+
delete fields.hotFreshRuntime;
|
|
1811
|
+
const notice = freshRuntimeDeclinedNotice(holding);
|
|
1812
|
+
if (!freshRuntimeNotices.has(notice)) {
|
|
1813
|
+
freshRuntimeNotices.add(notice);
|
|
1814
|
+
console.warn(notice);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1759
1818
|
if (options?.experimental?.nodeMocks === true || ownershipModel === "resolution") fields.nodeMocks = true;
|
|
1760
1819
|
let ownJestSupport = [];
|
|
1761
1820
|
if (!selection.listed) {
|
package/dist/native/loader.mjs
CHANGED
|
@@ -77,6 +77,16 @@ function resolveExtensionless(base) {
|
|
|
77
77
|
}
|
|
78
78
|
// Synthetic URL scheme for preset mocks served to the ESM graph (see below).
|
|
79
79
|
const PRESET_SCHEME = "vitest-native-preset:";
|
|
80
|
+
// Under the hot runtime the URL carries the generation, as a stamped file does (see
|
|
81
|
+
// versionable): Node keeps an ES module by URL for the worker's life, and the module reads
|
|
82
|
+
// the preset mocks of the file that first evaluates it. Unstamped, every later file's ES
|
|
83
|
+
// imports of a preset package got the first file's mocks, so a file's mockReturnValue or
|
|
84
|
+
// call assertion reached another file's mock. One URL per generation is one module per
|
|
85
|
+
// test file, however many of its ES modules import the package.
|
|
86
|
+
function presetURL(specifier) {
|
|
87
|
+
const gen = generationOf();
|
|
88
|
+
return gen > 0 ? `${PRESET_SCHEME}${specifier}?vnhot=${gen}` : PRESET_SCHEME + specifier;
|
|
89
|
+
}
|
|
80
90
|
// A preset reached by resolved file: only CommonJS that this loader compiled requires
|
|
81
91
|
// through that path (see presetRequestForFile), and on Node 22.13 that `require` reads
|
|
82
92
|
// a CommonJS cache an ES module job never fills ("Cannot read properties of undefined
|
|
@@ -313,7 +323,7 @@ function resolveBefore(specifier, context, presets = true) {
|
|
|
313
323
|
// Node-safe utility entries (jest-utils, mock, plugin) — those pass through
|
|
314
324
|
// to the real file.
|
|
315
325
|
if (presets && isPresetSpecifier(specifier)) {
|
|
316
|
-
return { done: { url:
|
|
326
|
+
return { done: { url: presetURL(specifier), shortCircuit: true } };
|
|
317
327
|
}
|
|
318
328
|
|
|
319
329
|
const parent =
|
|
@@ -395,7 +405,7 @@ function resolveAfter(resolved, context) {
|
|
|
395
405
|
Object.prototype.hasOwnProperty.call(presetExports, pkg),
|
|
396
406
|
);
|
|
397
407
|
if (hit && isPackageEntryFile(hit.pkg, file, parent)) {
|
|
398
|
-
return { url:
|
|
408
|
+
return { url: presetURL(hit.pkg), shortCircuit: true };
|
|
399
409
|
}
|
|
400
410
|
}
|
|
401
411
|
// JSON imports without an explicit `with { type: 'json' }` attribute throw
|
|
@@ -906,7 +916,7 @@ function loadModule(url, context, nextLoad) {
|
|
|
906
916
|
return { format: "commonjs", source, shortCircuit: true };
|
|
907
917
|
}
|
|
908
918
|
if (url.startsWith(PRESET_SCHEME)) {
|
|
909
|
-
const specifier = url.slice(PRESET_SCHEME.length);
|
|
919
|
+
const specifier = url.slice(PRESET_SCHEME.length).replace(STAMP, "");
|
|
910
920
|
// A subpath the preset shadows as a module of its own is served from that module
|
|
911
921
|
// (see the plugin's virtual:preset load hook).
|
|
912
922
|
const pkg = Object.prototype.hasOwnProperty.call(presetExports, specifier)
|
|
@@ -4,9 +4,9 @@ import { Module, createRequire } from "node:module";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import { VitestNativeError } from "./errors.mjs";
|
|
7
|
-
import { projectContext } from "./context.mjs";
|
|
8
7
|
import { vi } from "vitest";
|
|
9
8
|
import React, { useState } from "react";
|
|
9
|
+
import { projectContext } from "./context.mjs";
|
|
10
10
|
// src/presets/built-in.ts
|
|
11
11
|
/**
|
|
12
12
|
* Marks the presets vitest-native's own factories return. A test worker rebuilds a
|
|
@@ -61,6 +61,35 @@ function hostComponent(name) {
|
|
|
61
61
|
function asHost(type) {
|
|
62
62
|
return typeof type === "string" ? hostComponent(type) : type;
|
|
63
63
|
}
|
|
64
|
+
// src/mocks/components/View.ts
|
|
65
|
+
function createViewMock() {
|
|
66
|
+
const View = React.forwardRef((props, ref) => {
|
|
67
|
+
return React.createElement(hostComponent("View"), {
|
|
68
|
+
...props,
|
|
69
|
+
ref
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
View.displayName = "View";
|
|
73
|
+
return View;
|
|
74
|
+
}
|
|
75
|
+
// src/mocks/components/ScrollView.ts
|
|
76
|
+
function createScrollViewMock() {
|
|
77
|
+
const ScrollView = React.forwardRef((props, ref) => {
|
|
78
|
+
const { children, refreshControl, ...rest } = props;
|
|
79
|
+
const instanceMethods = {
|
|
80
|
+
scrollTo: vi.fn(),
|
|
81
|
+
scrollToEnd: vi.fn(),
|
|
82
|
+
flashScrollIndicators: vi.fn(),
|
|
83
|
+
getScrollResponder: vi.fn(() => ({})),
|
|
84
|
+
getInnerViewNode: vi.fn(),
|
|
85
|
+
setNativeProps: vi.fn()
|
|
86
|
+
};
|
|
87
|
+
React.useImperativeHandle(ref, () => instanceMethods);
|
|
88
|
+
return React.createElement("RCTScrollView", rest, refreshControl, React.createElement("View", null, children));
|
|
89
|
+
});
|
|
90
|
+
ScrollView.displayName = "ScrollView";
|
|
91
|
+
return ScrollView;
|
|
92
|
+
}
|
|
64
93
|
// src/presets/esm-export-names.ts
|
|
65
94
|
/** Metro's order for a module path without an extension: platform files first. */
|
|
66
95
|
function sourceExtensions(platform) {
|
|
@@ -243,6 +272,294 @@ function namesIn(file) {
|
|
|
243
272
|
return [];
|
|
244
273
|
}
|
|
245
274
|
}
|
|
275
|
+
// src/presets/keyboard-controller.ts
|
|
276
|
+
const KEYBOARD_CONTROLLER_MOCK = {
|
|
277
|
+
pkg: "react-native-keyboard-controller",
|
|
278
|
+
entry: "jest",
|
|
279
|
+
file: "jest/index.js"
|
|
280
|
+
};
|
|
281
|
+
function keyboardController() {
|
|
282
|
+
return builtInPreset({
|
|
283
|
+
name: "keyboardController",
|
|
284
|
+
modules: { "react-native-keyboard-controller": libraryMockModule(KEYBOARD_CONTROLLER_MOCK, {
|
|
285
|
+
exports: [
|
|
286
|
+
"KeyboardProvider",
|
|
287
|
+
"KeyboardControllerView",
|
|
288
|
+
"KeyboardGestureArea",
|
|
289
|
+
"OverKeyboardView",
|
|
290
|
+
"KeyboardBackgroundView",
|
|
291
|
+
"KeyboardExtender",
|
|
292
|
+
"KeyboardStickyView",
|
|
293
|
+
"KeyboardAvoidingView",
|
|
294
|
+
"KeyboardAwareScrollView",
|
|
295
|
+
"KeyboardChatScrollView",
|
|
296
|
+
"KeyboardToolbar",
|
|
297
|
+
"KeyboardController",
|
|
298
|
+
"KeyboardEvents",
|
|
299
|
+
"AndroidSoftInputModes",
|
|
300
|
+
"DefaultKeyboardToolbarTheme",
|
|
301
|
+
"useKeyboardAnimation",
|
|
302
|
+
"useReanimatedKeyboardAnimation",
|
|
303
|
+
"useResizeMode",
|
|
304
|
+
"useGenericKeyboardHandler",
|
|
305
|
+
"useKeyboardHandler",
|
|
306
|
+
"useKeyboardContext",
|
|
307
|
+
"useKeyboardState",
|
|
308
|
+
"useReanimatedFocusedInput",
|
|
309
|
+
"useFocusedInputHandler",
|
|
310
|
+
"useKeyboardController",
|
|
311
|
+
"useWindowDimensions"
|
|
312
|
+
],
|
|
313
|
+
factory: () => {
|
|
314
|
+
function hostComponent(name) {
|
|
315
|
+
const Component = React.forwardRef((props, ref) => React.createElement(asHost(name), {
|
|
316
|
+
...props,
|
|
317
|
+
ref
|
|
318
|
+
}, props.children));
|
|
319
|
+
Component.displayName = name;
|
|
320
|
+
return Component;
|
|
321
|
+
}
|
|
322
|
+
const sharedValue = (value) => ({
|
|
323
|
+
value,
|
|
324
|
+
get: () => value,
|
|
325
|
+
set: () => {}
|
|
326
|
+
});
|
|
327
|
+
const animationValues = {
|
|
328
|
+
animated: {
|
|
329
|
+
progress: sharedValue(0),
|
|
330
|
+
height: sharedValue(0)
|
|
331
|
+
},
|
|
332
|
+
reanimated: {
|
|
333
|
+
progress: sharedValue(0),
|
|
334
|
+
height: sharedValue(0)
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const lastKeyboardEvent = {
|
|
338
|
+
height: 0,
|
|
339
|
+
duration: 0,
|
|
340
|
+
timestamp: 0,
|
|
341
|
+
target: 0,
|
|
342
|
+
type: "default",
|
|
343
|
+
appearance: "default"
|
|
344
|
+
};
|
|
345
|
+
const keyboardState = {
|
|
346
|
+
...lastKeyboardEvent,
|
|
347
|
+
isVisible: false
|
|
348
|
+
};
|
|
349
|
+
const focusedInput = { input: sharedValue({
|
|
350
|
+
target: 1,
|
|
351
|
+
parentScrollViewTarget: -1,
|
|
352
|
+
layout: {
|
|
353
|
+
x: 0,
|
|
354
|
+
y: 0,
|
|
355
|
+
width: 200,
|
|
356
|
+
height: 40,
|
|
357
|
+
absoluteX: 0,
|
|
358
|
+
absoluteY: 100
|
|
359
|
+
}
|
|
360
|
+
}) };
|
|
361
|
+
const KeyboardToolbar = Object.assign(createViewMock(), {
|
|
362
|
+
Background: hostComponent("KeyboardToolbar.Background"),
|
|
363
|
+
Content: hostComponent("KeyboardToolbar.Content"),
|
|
364
|
+
Prev: hostComponent("KeyboardToolbar.Prev"),
|
|
365
|
+
Next: hostComponent("KeyboardToolbar.Next"),
|
|
366
|
+
Done: hostComponent("KeyboardToolbar.Done"),
|
|
367
|
+
Group: hostComponent("KeyboardToolbar.Group")
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
KeyboardProvider: hostComponent("KeyboardProvider"),
|
|
371
|
+
KeyboardControllerView: hostComponent("KeyboardControllerView"),
|
|
372
|
+
KeyboardGestureArea: hostComponent("KeyboardGestureArea"),
|
|
373
|
+
OverKeyboardView: hostComponent("OverKeyboardView"),
|
|
374
|
+
KeyboardBackgroundView: hostComponent("KeyboardBackgroundView"),
|
|
375
|
+
KeyboardExtender: hostComponent("KeyboardExtender"),
|
|
376
|
+
KeyboardStickyView: createViewMock(),
|
|
377
|
+
KeyboardAvoidingView: createViewMock(),
|
|
378
|
+
KeyboardAwareScrollView: createScrollViewMock(),
|
|
379
|
+
KeyboardChatScrollView: createScrollViewMock(),
|
|
380
|
+
KeyboardToolbar,
|
|
381
|
+
KeyboardController: {
|
|
382
|
+
setInputMode: vi.fn(),
|
|
383
|
+
setDefaultMode: vi.fn(),
|
|
384
|
+
preload: vi.fn(),
|
|
385
|
+
dismiss: vi.fn(() => Promise.resolve()),
|
|
386
|
+
setFocusTo: vi.fn(),
|
|
387
|
+
isVisible: vi.fn(() => false),
|
|
388
|
+
state: vi.fn(() => lastKeyboardEvent),
|
|
389
|
+
viewPositionInWindow: vi.fn(() => Promise.resolve({
|
|
390
|
+
x: 0,
|
|
391
|
+
y: 0,
|
|
392
|
+
width: 0,
|
|
393
|
+
height: 0
|
|
394
|
+
}))
|
|
395
|
+
},
|
|
396
|
+
KeyboardEvents: { addListener: vi.fn(() => ({ remove: vi.fn() })) },
|
|
397
|
+
AndroidSoftInputModes: {
|
|
398
|
+
SOFT_INPUT_ADJUST_NOTHING: 48,
|
|
399
|
+
SOFT_INPUT_ADJUST_PAN: 32,
|
|
400
|
+
SOFT_INPUT_ADJUST_RESIZE: 16,
|
|
401
|
+
SOFT_INPUT_ADJUST_UNSPECIFIED: 0,
|
|
402
|
+
SOFT_INPUT_IS_FORWARD_NAVIGATION: 256,
|
|
403
|
+
SOFT_INPUT_MASK_ADJUST: 240,
|
|
404
|
+
SOFT_INPUT_MASK_STATE: 15,
|
|
405
|
+
SOFT_INPUT_MODE_CHANGED: 512,
|
|
406
|
+
SOFT_INPUT_STATE_ALWAYS_HIDDEN: 3,
|
|
407
|
+
SOFT_INPUT_STATE_ALWAYS_VISIBLE: 5,
|
|
408
|
+
SOFT_INPUT_STATE_HIDDEN: 2,
|
|
409
|
+
SOFT_INPUT_STATE_UNCHANGED: 1,
|
|
410
|
+
SOFT_INPUT_STATE_UNSPECIFIED: 0,
|
|
411
|
+
SOFT_INPUT_STATE_VISIBLE: 4
|
|
412
|
+
},
|
|
413
|
+
DefaultKeyboardToolbarTheme: {
|
|
414
|
+
light: {
|
|
415
|
+
primary: "#2c2c2c",
|
|
416
|
+
disabled: "#B0BEC5",
|
|
417
|
+
background: "#f3f3f4",
|
|
418
|
+
ripple: "#bcbcbcbc"
|
|
419
|
+
},
|
|
420
|
+
dark: {
|
|
421
|
+
primary: "#fafafa",
|
|
422
|
+
disabled: "#707070",
|
|
423
|
+
background: "#2C2C2E",
|
|
424
|
+
ripple: "#F8F8F888"
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
useKeyboardAnimation: () => animationValues.animated,
|
|
428
|
+
useReanimatedKeyboardAnimation: () => animationValues.reanimated,
|
|
429
|
+
useResizeMode: () => {},
|
|
430
|
+
useGenericKeyboardHandler: () => {},
|
|
431
|
+
useKeyboardHandler: () => {},
|
|
432
|
+
useKeyboardContext: () => animationValues,
|
|
433
|
+
useKeyboardState: (selector) => selector ? selector(keyboardState) : keyboardState,
|
|
434
|
+
useReanimatedFocusedInput: () => focusedInput,
|
|
435
|
+
useFocusedInputHandler: () => {},
|
|
436
|
+
useKeyboardController: () => ({
|
|
437
|
+
enabled: true,
|
|
438
|
+
setEnabled: vi.fn()
|
|
439
|
+
}),
|
|
440
|
+
useWindowDimensions: () => ({
|
|
441
|
+
width: 390,
|
|
442
|
+
height: 844,
|
|
443
|
+
scale: 3,
|
|
444
|
+
fontScale: 1
|
|
445
|
+
})
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
}) }
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
// src/presets/safe-area.ts
|
|
452
|
+
const SAFE_AREA_MOCK = {
|
|
453
|
+
pkg: "react-native-safe-area-context",
|
|
454
|
+
entry: "jest/mock",
|
|
455
|
+
file: "lib/module/jest/mock.js",
|
|
456
|
+
exportKey: "default"
|
|
457
|
+
};
|
|
458
|
+
function safeAreaContext() {
|
|
459
|
+
return builtInPreset({
|
|
460
|
+
name: "safeAreaContext",
|
|
461
|
+
modules: { "react-native-safe-area-context": libraryMockModule(SAFE_AREA_MOCK, {
|
|
462
|
+
exports: [
|
|
463
|
+
"SafeAreaProvider",
|
|
464
|
+
"SafeAreaView",
|
|
465
|
+
"SafeAreaInsetsContext",
|
|
466
|
+
"SafeAreaFrameContext",
|
|
467
|
+
"SafeAreaCornerAdaptedInsetsContext",
|
|
468
|
+
"useSafeAreaInsets",
|
|
469
|
+
"useSafeAreaFrame",
|
|
470
|
+
"withSafeAreaInsets",
|
|
471
|
+
"initialWindowMetrics",
|
|
472
|
+
"initialWindowSafeAreaInsets"
|
|
473
|
+
],
|
|
474
|
+
factory: () => {
|
|
475
|
+
const defaultInsets = {
|
|
476
|
+
top: 47,
|
|
477
|
+
right: 0,
|
|
478
|
+
bottom: 34,
|
|
479
|
+
left: 0
|
|
480
|
+
};
|
|
481
|
+
const defaultFrame = {
|
|
482
|
+
x: 0,
|
|
483
|
+
y: 0,
|
|
484
|
+
width: 390,
|
|
485
|
+
height: 844
|
|
486
|
+
};
|
|
487
|
+
const state = {
|
|
488
|
+
insets: { ...defaultInsets },
|
|
489
|
+
frame: { ...defaultFrame }
|
|
490
|
+
};
|
|
491
|
+
const initialMetrics = {
|
|
492
|
+
frame: state.frame,
|
|
493
|
+
insets: state.insets
|
|
494
|
+
};
|
|
495
|
+
const SafeAreaProvider = React.forwardRef((props, ref) => {
|
|
496
|
+
const host = React.createElement(hostComponent("SafeAreaProvider"), {
|
|
497
|
+
...props,
|
|
498
|
+
ref
|
|
499
|
+
}, props.children);
|
|
500
|
+
const metrics = props.initialMetrics;
|
|
501
|
+
if (!metrics) return host;
|
|
502
|
+
return React.createElement(SafeAreaFrameContext.Provider, { value: metrics.frame ?? state.frame }, React.createElement(SafeAreaInsetsContext.Provider, { value: metrics.insets ?? state.insets }, host));
|
|
503
|
+
});
|
|
504
|
+
SafeAreaProvider.displayName = "SafeAreaProvider";
|
|
505
|
+
const SafeAreaView = React.forwardRef((props, ref) => React.createElement(hostComponent("SafeAreaView"), {
|
|
506
|
+
...props,
|
|
507
|
+
ref
|
|
508
|
+
}, props.children));
|
|
509
|
+
SafeAreaView.displayName = "SafeAreaView";
|
|
510
|
+
const SafeAreaInsetsContext = React.createContext(state.insets);
|
|
511
|
+
const SafeAreaFrameContext = React.createContext(state.frame);
|
|
512
|
+
const SafeAreaCornerAdaptedInsetsContext = React.createContext(null);
|
|
513
|
+
function useSafeAreaInsets(options) {
|
|
514
|
+
const insets = React.useContext(SafeAreaInsetsContext) ?? state.insets;
|
|
515
|
+
const corner = React.useContext(SafeAreaCornerAdaptedInsetsContext);
|
|
516
|
+
const axis = options?.cornerAdaptation;
|
|
517
|
+
return (axis != null ? corner?.[axis] : void 0) ?? insets;
|
|
518
|
+
}
|
|
519
|
+
function useSafeAreaFrame() {
|
|
520
|
+
return React.useContext(SafeAreaFrameContext) ?? state.frame;
|
|
521
|
+
}
|
|
522
|
+
function withSafeAreaInsets(WrappedComponent) {
|
|
523
|
+
const WithSafeAreaInsets = React.forwardRef((props, ref) => React.createElement(asHost(WrappedComponent), {
|
|
524
|
+
...props,
|
|
525
|
+
ref,
|
|
526
|
+
insets: useSafeAreaInsets()
|
|
527
|
+
}));
|
|
528
|
+
WithSafeAreaInsets.displayName = `withSafeAreaInsets(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
|
|
529
|
+
return WithSafeAreaInsets;
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
default: {
|
|
533
|
+
SafeAreaProvider,
|
|
534
|
+
SafeAreaView
|
|
535
|
+
},
|
|
536
|
+
SafeAreaProvider,
|
|
537
|
+
SafeAreaView,
|
|
538
|
+
SafeAreaInsetsContext,
|
|
539
|
+
SafeAreaFrameContext,
|
|
540
|
+
SafeAreaCornerAdaptedInsetsContext,
|
|
541
|
+
useSafeAreaInsets,
|
|
542
|
+
useSafeAreaFrame,
|
|
543
|
+
withSafeAreaInsets,
|
|
544
|
+
initialWindowMetrics: initialMetrics,
|
|
545
|
+
initialWindowSafeAreaInsets: state.insets,
|
|
546
|
+
EdgeInsets: vi.fn(),
|
|
547
|
+
Rect: vi.fn(),
|
|
548
|
+
Metrics: vi.fn(),
|
|
549
|
+
/** Internal: update insets. Called by setInsets() helper. */
|
|
550
|
+
_setInsets: (insets) => {
|
|
551
|
+
Object.assign(state.insets, insets);
|
|
552
|
+
},
|
|
553
|
+
/** Internal: reset insets to defaults. Called by resetAllMocks(). */
|
|
554
|
+
_reset: () => {
|
|
555
|
+
Object.assign(state.insets, defaultInsets);
|
|
556
|
+
Object.assign(state.frame, defaultFrame);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
}) }
|
|
561
|
+
});
|
|
562
|
+
}
|
|
246
563
|
// src/presets/reanimated.ts
|
|
247
564
|
/**
|
|
248
565
|
* Whether reanimated's own mock can run: it loads the real package, whose JS
|
|
@@ -358,24 +675,29 @@ function probeHook(call) {
|
|
|
358
675
|
* A shared value with Reanimated 4's API: `.value` and `get()`, `set(value | updater)`,
|
|
359
676
|
* `modify(modifier?, forceUpdate = true)` (the value becomes the modifier's result),
|
|
360
677
|
* `addListener(id, listener)` / `removeListener(id)`, each listener called with the new
|
|
361
|
-
* value on every write, and the `_isReanimatedSharedValue` mark.
|
|
678
|
+
* value on every write, and the `_isReanimatedSharedValue` mark. A read (`.value` or
|
|
679
|
+
* `get()`) is recorded while a derived value's updater runs (derivedValue).
|
|
362
680
|
*/
|
|
363
681
|
function sharedValue(init) {
|
|
364
682
|
let current = init;
|
|
365
683
|
const listeners = /* @__PURE__ */ new Map();
|
|
366
684
|
const notify = () => {
|
|
367
|
-
for (const listener of listeners.values()) listener(current);
|
|
685
|
+
for (const listener of Array.from(listeners.values())) listener(current);
|
|
368
686
|
};
|
|
369
|
-
|
|
687
|
+
const shared = {
|
|
370
688
|
_isReanimatedSharedValue: true,
|
|
371
689
|
get value() {
|
|
690
|
+
derivedReads?.add(shared);
|
|
372
691
|
return current;
|
|
373
692
|
},
|
|
374
693
|
set value(next) {
|
|
375
694
|
current = next;
|
|
376
695
|
notify();
|
|
377
696
|
},
|
|
378
|
-
get: () =>
|
|
697
|
+
get: () => {
|
|
698
|
+
derivedReads?.add(shared);
|
|
699
|
+
return current;
|
|
700
|
+
},
|
|
379
701
|
set(next) {
|
|
380
702
|
current = typeof next === "function" ? next(current) : next;
|
|
381
703
|
notify();
|
|
@@ -391,6 +713,65 @@ function sharedValue(init) {
|
|
|
391
713
|
listeners.delete(id);
|
|
392
714
|
}
|
|
393
715
|
};
|
|
716
|
+
return shared;
|
|
717
|
+
}
|
|
718
|
+
/** The shared values read while a derived value's updater runs, or null outside one. */
|
|
719
|
+
let derivedReads = null;
|
|
720
|
+
/**
|
|
721
|
+
* Reanimated's useDerivedValue: a shared value holding what `updater` returns, recomputed
|
|
722
|
+
* whenever a shared value the updater read changes, without a render. Reanimated starts a
|
|
723
|
+
* mapper over the updater's inputs and runs it on every change of one (at once under
|
|
724
|
+
* Jest, src/mappers.ts maybeRequestUpdates); here the inputs are the shared values the
|
|
725
|
+
* last run read, so it needs no Babel plugin. It also recomputes on every render, as the
|
|
726
|
+
* mock's does, so a value the updater takes from props is current, and once more on
|
|
727
|
+
* mount, as Reanimated's mapper runs when it starts. Listeners hear a changed result, and
|
|
728
|
+
* the subscriptions end when the component unmounts.
|
|
729
|
+
*/
|
|
730
|
+
function derivedValue(updater) {
|
|
731
|
+
const rendering = useRefOrNull();
|
|
732
|
+
const state = rendering?.current ?? derivedState(updater);
|
|
733
|
+
if (rendering && rendering.current === null) rendering.current = state;
|
|
734
|
+
state.updater = updater;
|
|
735
|
+
state.run();
|
|
736
|
+
if (rendering) React.useEffect(() => {
|
|
737
|
+
state.run();
|
|
738
|
+
return () => state.stop();
|
|
739
|
+
}, [state]);
|
|
740
|
+
return state.derived;
|
|
741
|
+
}
|
|
742
|
+
function derivedState(updater) {
|
|
743
|
+
const held = {
|
|
744
|
+
derived: sharedValue(void 0),
|
|
745
|
+
updater,
|
|
746
|
+
inputs: /* @__PURE__ */ new Set(),
|
|
747
|
+
ran: false,
|
|
748
|
+
last: void 0,
|
|
749
|
+
run() {
|
|
750
|
+
const outer = derivedReads;
|
|
751
|
+
const read = /* @__PURE__ */ new Set();
|
|
752
|
+
derivedReads = read;
|
|
753
|
+
let next;
|
|
754
|
+
try {
|
|
755
|
+
next = held.updater();
|
|
756
|
+
} finally {
|
|
757
|
+
derivedReads = outer;
|
|
758
|
+
}
|
|
759
|
+
read.delete(held.derived);
|
|
760
|
+
for (const input of held.inputs) if (!read.has(input)) input.removeListener(held);
|
|
761
|
+
for (const input of read) if (!held.inputs.has(input)) input.addListener(held, held.run);
|
|
762
|
+
held.inputs = read;
|
|
763
|
+
if (!held.ran || !Object.is(held.last, next)) {
|
|
764
|
+
held.ran = true;
|
|
765
|
+
held.last = next;
|
|
766
|
+
held.derived.value = next;
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
stop() {
|
|
770
|
+
for (const input of held.inputs) input.removeListener(held);
|
|
771
|
+
held.inputs.clear();
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
return held;
|
|
394
775
|
}
|
|
395
776
|
/**
|
|
396
777
|
* `create()` once per component, as Reanimated's hooks keep their shared values: a
|
|
@@ -439,12 +820,7 @@ function mockCorrections(mock, dir, fromRegistry = false, helpers = ownHelpers(d
|
|
|
439
820
|
};
|
|
440
821
|
if (wrong("useSharedValue", (hook) => hook(0))) fixed.useSharedValue = (init) => perComponent(() => sharedValue(init));
|
|
441
822
|
if (wrong("makeMutable", (hook) => hook(0))) fixed.makeMutable = (init) => sharedValue(init);
|
|
442
|
-
if (wrong("useDerivedValue", (hook) => hook(() => 0))) fixed.useDerivedValue =
|
|
443
|
-
const next = updater();
|
|
444
|
-
const derived = perComponent(() => sharedValue(next));
|
|
445
|
-
if (!Object.is(derived.value, next)) derived.value = next;
|
|
446
|
-
return derived;
|
|
447
|
-
};
|
|
823
|
+
if (wrong("useDerivedValue", (hook) => hook(() => 0))) fixed.useDerivedValue = derivedValue;
|
|
448
824
|
for (const name of [
|
|
449
825
|
"useScrollOffset",
|
|
450
826
|
"useScrollViewOffset",
|
|
@@ -820,9 +1196,7 @@ function reanimated() {
|
|
|
820
1196
|
function useAnimatedProps(updater) {
|
|
821
1197
|
return updater();
|
|
822
1198
|
}
|
|
823
|
-
|
|
824
|
-
return createSharedValue(updater());
|
|
825
|
-
}
|
|
1199
|
+
const useDerivedValue = derivedValue;
|
|
826
1200
|
const { useAnimatedScrollHandler, useComposedEventHandler, useScrollOffset } = scrollHandlers(createSharedValue);
|
|
827
1201
|
const installedDir = reanimatedDir(workerRoot$1());
|
|
828
1202
|
const helpers = installedDir ? ownHelpers(installedDir) : {};
|
|
@@ -1287,166 +1661,54 @@ function gestureHandler() {
|
|
|
1287
1661
|
direction: vi.fn(returnThis),
|
|
1288
1662
|
onStart: vi.fn(returnThis),
|
|
1289
1663
|
onEnd: vi.fn(returnThis),
|
|
1290
|
-
enabled: vi.fn(returnThis)
|
|
1291
|
-
})),
|
|
1292
|
-
Simultaneous: vi.fn((..._gestures) => ({})),
|
|
1293
|
-
Exclusive: vi.fn((..._gestures) => ({})),
|
|
1294
|
-
Race: vi.fn((..._gestures) => ({}))
|
|
1295
|
-
};
|
|
1296
|
-
const GestureDetector = React.forwardRef((props, ref) => React.createElement(hostComponent("GestureDetector"), {
|
|
1297
|
-
...props,
|
|
1298
|
-
ref
|
|
1299
|
-
}, props.children));
|
|
1300
|
-
GestureDetector.displayName = "GestureDetector";
|
|
1301
|
-
return {
|
|
1302
|
-
default: {
|
|
1303
|
-
GestureHandlerRootView,
|
|
1304
|
-
State,
|
|
1305
|
-
Directions
|
|
1306
|
-
},
|
|
1307
|
-
State,
|
|
1308
|
-
Directions,
|
|
1309
|
-
Gesture,
|
|
1310
|
-
GestureDetector,
|
|
1311
|
-
GestureHandlerRootView,
|
|
1312
|
-
Swipeable,
|
|
1313
|
-
DrawerLayout,
|
|
1314
|
-
gestureHandlerRootHOC,
|
|
1315
|
-
PanGestureHandler: createGestureHandler("PanGestureHandler"),
|
|
1316
|
-
TapGestureHandler: createGestureHandler("TapGestureHandler"),
|
|
1317
|
-
LongPressGestureHandler: createGestureHandler("LongPressGestureHandler"),
|
|
1318
|
-
PinchGestureHandler: createGestureHandler("PinchGestureHandler"),
|
|
1319
|
-
RotationGestureHandler: createGestureHandler("RotationGestureHandler"),
|
|
1320
|
-
FlingGestureHandler: createGestureHandler("FlingGestureHandler"),
|
|
1321
|
-
ForceTouchGestureHandler: createGestureHandler("ForceTouchGestureHandler"),
|
|
1322
|
-
NativeViewGestureHandler: createGestureHandler("NativeViewGestureHandler"),
|
|
1323
|
-
ScrollView: createGestureHandler("GH-ScrollView"),
|
|
1324
|
-
FlatList: createGestureHandler("GH-FlatList"),
|
|
1325
|
-
TouchableOpacity: createGestureHandler("GH-TouchableOpacity"),
|
|
1326
|
-
TouchableHighlight: createGestureHandler("GH-TouchableHighlight"),
|
|
1327
|
-
TouchableWithoutFeedback: createGestureHandler("GH-TouchableWithoutFeedback"),
|
|
1328
|
-
TouchableNativeFeedback: createGestureHandler("GH-TouchableNativeFeedback"),
|
|
1329
|
-
Pressable: createPressableMock(),
|
|
1330
|
-
RectButton: createGestureHandler("RectButton"),
|
|
1331
|
-
BaseButton: createGestureHandler("BaseButton"),
|
|
1332
|
-
BorderlessButton: createGestureHandler("BorderlessButton"),
|
|
1333
|
-
RawButton: createGestureHandler("RawButton"),
|
|
1334
|
-
PureNativeButton: createGestureHandler("PureNativeButton")
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
} }
|
|
1338
|
-
});
|
|
1339
|
-
}
|
|
1340
|
-
// src/presets/safe-area.ts
|
|
1341
|
-
const SAFE_AREA_MOCK = {
|
|
1342
|
-
pkg: "react-native-safe-area-context",
|
|
1343
|
-
entry: "jest/mock",
|
|
1344
|
-
file: "lib/module/jest/mock.js",
|
|
1345
|
-
exportKey: "default"
|
|
1346
|
-
};
|
|
1347
|
-
function safeAreaContext() {
|
|
1348
|
-
return builtInPreset({
|
|
1349
|
-
name: "safeAreaContext",
|
|
1350
|
-
modules: { "react-native-safe-area-context": libraryMockModule(SAFE_AREA_MOCK, {
|
|
1351
|
-
exports: [
|
|
1352
|
-
"SafeAreaProvider",
|
|
1353
|
-
"SafeAreaView",
|
|
1354
|
-
"SafeAreaInsetsContext",
|
|
1355
|
-
"SafeAreaFrameContext",
|
|
1356
|
-
"SafeAreaCornerAdaptedInsetsContext",
|
|
1357
|
-
"useSafeAreaInsets",
|
|
1358
|
-
"useSafeAreaFrame",
|
|
1359
|
-
"withSafeAreaInsets",
|
|
1360
|
-
"initialWindowMetrics",
|
|
1361
|
-
"initialWindowSafeAreaInsets"
|
|
1362
|
-
],
|
|
1363
|
-
factory: () => {
|
|
1364
|
-
const defaultInsets = {
|
|
1365
|
-
top: 47,
|
|
1366
|
-
right: 0,
|
|
1367
|
-
bottom: 34,
|
|
1368
|
-
left: 0
|
|
1369
|
-
};
|
|
1370
|
-
const defaultFrame = {
|
|
1371
|
-
x: 0,
|
|
1372
|
-
y: 0,
|
|
1373
|
-
width: 390,
|
|
1374
|
-
height: 844
|
|
1375
|
-
};
|
|
1376
|
-
const state = {
|
|
1377
|
-
insets: { ...defaultInsets },
|
|
1378
|
-
frame: { ...defaultFrame }
|
|
1379
|
-
};
|
|
1380
|
-
const initialMetrics = {
|
|
1381
|
-
frame: state.frame,
|
|
1382
|
-
insets: state.insets
|
|
1383
|
-
};
|
|
1384
|
-
const SafeAreaProvider = React.forwardRef((props, ref) => {
|
|
1385
|
-
const host = React.createElement(hostComponent("SafeAreaProvider"), {
|
|
1386
|
-
...props,
|
|
1387
|
-
ref
|
|
1388
|
-
}, props.children);
|
|
1389
|
-
const metrics = props.initialMetrics;
|
|
1390
|
-
if (!metrics) return host;
|
|
1391
|
-
return React.createElement(SafeAreaFrameContext.Provider, { value: metrics.frame ?? state.frame }, React.createElement(SafeAreaInsetsContext.Provider, { value: metrics.insets ?? state.insets }, host));
|
|
1392
|
-
});
|
|
1393
|
-
SafeAreaProvider.displayName = "SafeAreaProvider";
|
|
1394
|
-
const SafeAreaView = React.forwardRef((props, ref) => React.createElement(hostComponent("SafeAreaView"), {
|
|
1395
|
-
...props,
|
|
1396
|
-
ref
|
|
1397
|
-
}, props.children));
|
|
1398
|
-
SafeAreaView.displayName = "SafeAreaView";
|
|
1399
|
-
const SafeAreaInsetsContext = React.createContext(state.insets);
|
|
1400
|
-
const SafeAreaFrameContext = React.createContext(state.frame);
|
|
1401
|
-
const SafeAreaCornerAdaptedInsetsContext = React.createContext(null);
|
|
1402
|
-
function useSafeAreaInsets(options) {
|
|
1403
|
-
const insets = React.useContext(SafeAreaInsetsContext) ?? state.insets;
|
|
1404
|
-
const corner = React.useContext(SafeAreaCornerAdaptedInsetsContext);
|
|
1405
|
-
const axis = options?.cornerAdaptation;
|
|
1406
|
-
return (axis != null ? corner?.[axis] : void 0) ?? insets;
|
|
1407
|
-
}
|
|
1408
|
-
function useSafeAreaFrame() {
|
|
1409
|
-
return React.useContext(SafeAreaFrameContext) ?? state.frame;
|
|
1410
|
-
}
|
|
1411
|
-
function withSafeAreaInsets(WrappedComponent) {
|
|
1412
|
-
const WithSafeAreaInsets = React.forwardRef((props, ref) => React.createElement(asHost(WrappedComponent), {
|
|
1413
|
-
...props,
|
|
1414
|
-
ref,
|
|
1415
|
-
insets: useSafeAreaInsets()
|
|
1416
|
-
}));
|
|
1417
|
-
WithSafeAreaInsets.displayName = `withSafeAreaInsets(${WrappedComponent.displayName || WrappedComponent.name || "Component"})`;
|
|
1418
|
-
return WithSafeAreaInsets;
|
|
1419
|
-
}
|
|
1420
|
-
return {
|
|
1421
|
-
default: {
|
|
1422
|
-
SafeAreaProvider,
|
|
1423
|
-
SafeAreaView
|
|
1424
|
-
},
|
|
1425
|
-
SafeAreaProvider,
|
|
1426
|
-
SafeAreaView,
|
|
1427
|
-
SafeAreaInsetsContext,
|
|
1428
|
-
SafeAreaFrameContext,
|
|
1429
|
-
SafeAreaCornerAdaptedInsetsContext,
|
|
1430
|
-
useSafeAreaInsets,
|
|
1431
|
-
useSafeAreaFrame,
|
|
1432
|
-
withSafeAreaInsets,
|
|
1433
|
-
initialWindowMetrics: initialMetrics,
|
|
1434
|
-
initialWindowSafeAreaInsets: state.insets,
|
|
1435
|
-
EdgeInsets: vi.fn(),
|
|
1436
|
-
Rect: vi.fn(),
|
|
1437
|
-
Metrics: vi.fn(),
|
|
1438
|
-
/** Internal: update insets. Called by setInsets() helper. */
|
|
1439
|
-
_setInsets: (insets) => {
|
|
1440
|
-
Object.assign(state.insets, insets);
|
|
1664
|
+
enabled: vi.fn(returnThis)
|
|
1665
|
+
})),
|
|
1666
|
+
Simultaneous: vi.fn((..._gestures) => ({})),
|
|
1667
|
+
Exclusive: vi.fn((..._gestures) => ({})),
|
|
1668
|
+
Race: vi.fn((..._gestures) => ({}))
|
|
1669
|
+
};
|
|
1670
|
+
const GestureDetector = React.forwardRef((props, ref) => React.createElement(hostComponent("GestureDetector"), {
|
|
1671
|
+
...props,
|
|
1672
|
+
ref
|
|
1673
|
+
}, props.children));
|
|
1674
|
+
GestureDetector.displayName = "GestureDetector";
|
|
1675
|
+
return {
|
|
1676
|
+
default: {
|
|
1677
|
+
GestureHandlerRootView,
|
|
1678
|
+
State,
|
|
1679
|
+
Directions
|
|
1441
1680
|
},
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1681
|
+
State,
|
|
1682
|
+
Directions,
|
|
1683
|
+
Gesture,
|
|
1684
|
+
GestureDetector,
|
|
1685
|
+
GestureHandlerRootView,
|
|
1686
|
+
Swipeable,
|
|
1687
|
+
DrawerLayout,
|
|
1688
|
+
gestureHandlerRootHOC,
|
|
1689
|
+
PanGestureHandler: createGestureHandler("PanGestureHandler"),
|
|
1690
|
+
TapGestureHandler: createGestureHandler("TapGestureHandler"),
|
|
1691
|
+
LongPressGestureHandler: createGestureHandler("LongPressGestureHandler"),
|
|
1692
|
+
PinchGestureHandler: createGestureHandler("PinchGestureHandler"),
|
|
1693
|
+
RotationGestureHandler: createGestureHandler("RotationGestureHandler"),
|
|
1694
|
+
FlingGestureHandler: createGestureHandler("FlingGestureHandler"),
|
|
1695
|
+
ForceTouchGestureHandler: createGestureHandler("ForceTouchGestureHandler"),
|
|
1696
|
+
NativeViewGestureHandler: createGestureHandler("NativeViewGestureHandler"),
|
|
1697
|
+
ScrollView: createGestureHandler("GH-ScrollView"),
|
|
1698
|
+
FlatList: createGestureHandler("GH-FlatList"),
|
|
1699
|
+
TouchableOpacity: createGestureHandler("GH-TouchableOpacity"),
|
|
1700
|
+
TouchableHighlight: createGestureHandler("GH-TouchableHighlight"),
|
|
1701
|
+
TouchableWithoutFeedback: createGestureHandler("GH-TouchableWithoutFeedback"),
|
|
1702
|
+
TouchableNativeFeedback: createGestureHandler("GH-TouchableNativeFeedback"),
|
|
1703
|
+
Pressable: createPressableMock(),
|
|
1704
|
+
RectButton: createGestureHandler("RectButton"),
|
|
1705
|
+
BaseButton: createGestureHandler("BaseButton"),
|
|
1706
|
+
BorderlessButton: createGestureHandler("BorderlessButton"),
|
|
1707
|
+
RawButton: createGestureHandler("RawButton"),
|
|
1708
|
+
PureNativeButton: createGestureHandler("PureNativeButton")
|
|
1447
1709
|
};
|
|
1448
1710
|
}
|
|
1449
|
-
}
|
|
1711
|
+
} }
|
|
1450
1712
|
});
|
|
1451
1713
|
}
|
|
1452
1714
|
// src/presets/navigation.ts
|
|
@@ -2950,24 +3212,6 @@ function createTextInputMock() {
|
|
|
2950
3212
|
TextInput.displayName = "TextInput";
|
|
2951
3213
|
return TextInput;
|
|
2952
3214
|
}
|
|
2953
|
-
// src/mocks/components/ScrollView.ts
|
|
2954
|
-
function createScrollViewMock() {
|
|
2955
|
-
const ScrollView = React.forwardRef((props, ref) => {
|
|
2956
|
-
const { children, refreshControl, ...rest } = props;
|
|
2957
|
-
const instanceMethods = {
|
|
2958
|
-
scrollTo: vi.fn(),
|
|
2959
|
-
scrollToEnd: vi.fn(),
|
|
2960
|
-
flashScrollIndicators: vi.fn(),
|
|
2961
|
-
getScrollResponder: vi.fn(() => ({})),
|
|
2962
|
-
getInnerViewNode: vi.fn(),
|
|
2963
|
-
setNativeProps: vi.fn()
|
|
2964
|
-
};
|
|
2965
|
-
React.useImperativeHandle(ref, () => instanceMethods);
|
|
2966
|
-
return React.createElement("RCTScrollView", rest, refreshControl, React.createElement("View", null, children));
|
|
2967
|
-
});
|
|
2968
|
-
ScrollView.displayName = "ScrollView";
|
|
2969
|
-
return ScrollView;
|
|
2970
|
-
}
|
|
2971
3215
|
// src/mocks/components/FlatList.ts
|
|
2972
3216
|
function createFlatListMock() {
|
|
2973
3217
|
const FlatList = React.forwardRef((props, ref) => {
|
|
@@ -3286,193 +3530,6 @@ function bottomSheet() {
|
|
|
3286
3530
|
}) }
|
|
3287
3531
|
});
|
|
3288
3532
|
}
|
|
3289
|
-
// src/mocks/components/View.ts
|
|
3290
|
-
function createViewMock() {
|
|
3291
|
-
const View = React.forwardRef((props, ref) => {
|
|
3292
|
-
return React.createElement(hostComponent("View"), {
|
|
3293
|
-
...props,
|
|
3294
|
-
ref
|
|
3295
|
-
});
|
|
3296
|
-
});
|
|
3297
|
-
View.displayName = "View";
|
|
3298
|
-
return View;
|
|
3299
|
-
}
|
|
3300
|
-
// src/presets/keyboard-controller.ts
|
|
3301
|
-
const KEYBOARD_CONTROLLER_MOCK = {
|
|
3302
|
-
pkg: "react-native-keyboard-controller",
|
|
3303
|
-
entry: "jest",
|
|
3304
|
-
file: "jest/index.js"
|
|
3305
|
-
};
|
|
3306
|
-
function keyboardController() {
|
|
3307
|
-
return builtInPreset({
|
|
3308
|
-
name: "keyboardController",
|
|
3309
|
-
modules: { "react-native-keyboard-controller": libraryMockModule(KEYBOARD_CONTROLLER_MOCK, {
|
|
3310
|
-
exports: [
|
|
3311
|
-
"KeyboardProvider",
|
|
3312
|
-
"KeyboardControllerView",
|
|
3313
|
-
"KeyboardGestureArea",
|
|
3314
|
-
"OverKeyboardView",
|
|
3315
|
-
"KeyboardBackgroundView",
|
|
3316
|
-
"KeyboardExtender",
|
|
3317
|
-
"KeyboardStickyView",
|
|
3318
|
-
"KeyboardAvoidingView",
|
|
3319
|
-
"KeyboardAwareScrollView",
|
|
3320
|
-
"KeyboardChatScrollView",
|
|
3321
|
-
"KeyboardToolbar",
|
|
3322
|
-
"KeyboardController",
|
|
3323
|
-
"KeyboardEvents",
|
|
3324
|
-
"AndroidSoftInputModes",
|
|
3325
|
-
"DefaultKeyboardToolbarTheme",
|
|
3326
|
-
"useKeyboardAnimation",
|
|
3327
|
-
"useReanimatedKeyboardAnimation",
|
|
3328
|
-
"useResizeMode",
|
|
3329
|
-
"useGenericKeyboardHandler",
|
|
3330
|
-
"useKeyboardHandler",
|
|
3331
|
-
"useKeyboardContext",
|
|
3332
|
-
"useKeyboardState",
|
|
3333
|
-
"useReanimatedFocusedInput",
|
|
3334
|
-
"useFocusedInputHandler",
|
|
3335
|
-
"useKeyboardController",
|
|
3336
|
-
"useWindowDimensions"
|
|
3337
|
-
],
|
|
3338
|
-
factory: () => {
|
|
3339
|
-
function hostComponent(name) {
|
|
3340
|
-
const Component = React.forwardRef((props, ref) => React.createElement(asHost(name), {
|
|
3341
|
-
...props,
|
|
3342
|
-
ref
|
|
3343
|
-
}, props.children));
|
|
3344
|
-
Component.displayName = name;
|
|
3345
|
-
return Component;
|
|
3346
|
-
}
|
|
3347
|
-
const sharedValue = (value) => ({
|
|
3348
|
-
value,
|
|
3349
|
-
get: () => value,
|
|
3350
|
-
set: () => {}
|
|
3351
|
-
});
|
|
3352
|
-
const animationValues = {
|
|
3353
|
-
animated: {
|
|
3354
|
-
progress: sharedValue(0),
|
|
3355
|
-
height: sharedValue(0)
|
|
3356
|
-
},
|
|
3357
|
-
reanimated: {
|
|
3358
|
-
progress: sharedValue(0),
|
|
3359
|
-
height: sharedValue(0)
|
|
3360
|
-
}
|
|
3361
|
-
};
|
|
3362
|
-
const lastKeyboardEvent = {
|
|
3363
|
-
height: 0,
|
|
3364
|
-
duration: 0,
|
|
3365
|
-
timestamp: 0,
|
|
3366
|
-
target: 0,
|
|
3367
|
-
type: "default",
|
|
3368
|
-
appearance: "default"
|
|
3369
|
-
};
|
|
3370
|
-
const keyboardState = {
|
|
3371
|
-
...lastKeyboardEvent,
|
|
3372
|
-
isVisible: false
|
|
3373
|
-
};
|
|
3374
|
-
const focusedInput = { input: sharedValue({
|
|
3375
|
-
target: 1,
|
|
3376
|
-
parentScrollViewTarget: -1,
|
|
3377
|
-
layout: {
|
|
3378
|
-
x: 0,
|
|
3379
|
-
y: 0,
|
|
3380
|
-
width: 200,
|
|
3381
|
-
height: 40,
|
|
3382
|
-
absoluteX: 0,
|
|
3383
|
-
absoluteY: 100
|
|
3384
|
-
}
|
|
3385
|
-
}) };
|
|
3386
|
-
const KeyboardToolbar = Object.assign(createViewMock(), {
|
|
3387
|
-
Background: hostComponent("KeyboardToolbar.Background"),
|
|
3388
|
-
Content: hostComponent("KeyboardToolbar.Content"),
|
|
3389
|
-
Prev: hostComponent("KeyboardToolbar.Prev"),
|
|
3390
|
-
Next: hostComponent("KeyboardToolbar.Next"),
|
|
3391
|
-
Done: hostComponent("KeyboardToolbar.Done"),
|
|
3392
|
-
Group: hostComponent("KeyboardToolbar.Group")
|
|
3393
|
-
});
|
|
3394
|
-
return {
|
|
3395
|
-
KeyboardProvider: hostComponent("KeyboardProvider"),
|
|
3396
|
-
KeyboardControllerView: hostComponent("KeyboardControllerView"),
|
|
3397
|
-
KeyboardGestureArea: hostComponent("KeyboardGestureArea"),
|
|
3398
|
-
OverKeyboardView: hostComponent("OverKeyboardView"),
|
|
3399
|
-
KeyboardBackgroundView: hostComponent("KeyboardBackgroundView"),
|
|
3400
|
-
KeyboardExtender: hostComponent("KeyboardExtender"),
|
|
3401
|
-
KeyboardStickyView: createViewMock(),
|
|
3402
|
-
KeyboardAvoidingView: createViewMock(),
|
|
3403
|
-
KeyboardAwareScrollView: createScrollViewMock(),
|
|
3404
|
-
KeyboardChatScrollView: createScrollViewMock(),
|
|
3405
|
-
KeyboardToolbar,
|
|
3406
|
-
KeyboardController: {
|
|
3407
|
-
setInputMode: vi.fn(),
|
|
3408
|
-
setDefaultMode: vi.fn(),
|
|
3409
|
-
preload: vi.fn(),
|
|
3410
|
-
dismiss: vi.fn(() => Promise.resolve()),
|
|
3411
|
-
setFocusTo: vi.fn(),
|
|
3412
|
-
isVisible: vi.fn(() => false),
|
|
3413
|
-
state: vi.fn(() => lastKeyboardEvent),
|
|
3414
|
-
viewPositionInWindow: vi.fn(() => Promise.resolve({
|
|
3415
|
-
x: 0,
|
|
3416
|
-
y: 0,
|
|
3417
|
-
width: 0,
|
|
3418
|
-
height: 0
|
|
3419
|
-
}))
|
|
3420
|
-
},
|
|
3421
|
-
KeyboardEvents: { addListener: vi.fn(() => ({ remove: vi.fn() })) },
|
|
3422
|
-
AndroidSoftInputModes: {
|
|
3423
|
-
SOFT_INPUT_ADJUST_NOTHING: 48,
|
|
3424
|
-
SOFT_INPUT_ADJUST_PAN: 32,
|
|
3425
|
-
SOFT_INPUT_ADJUST_RESIZE: 16,
|
|
3426
|
-
SOFT_INPUT_ADJUST_UNSPECIFIED: 0,
|
|
3427
|
-
SOFT_INPUT_IS_FORWARD_NAVIGATION: 256,
|
|
3428
|
-
SOFT_INPUT_MASK_ADJUST: 240,
|
|
3429
|
-
SOFT_INPUT_MASK_STATE: 15,
|
|
3430
|
-
SOFT_INPUT_MODE_CHANGED: 512,
|
|
3431
|
-
SOFT_INPUT_STATE_ALWAYS_HIDDEN: 3,
|
|
3432
|
-
SOFT_INPUT_STATE_ALWAYS_VISIBLE: 5,
|
|
3433
|
-
SOFT_INPUT_STATE_HIDDEN: 2,
|
|
3434
|
-
SOFT_INPUT_STATE_UNCHANGED: 1,
|
|
3435
|
-
SOFT_INPUT_STATE_UNSPECIFIED: 0,
|
|
3436
|
-
SOFT_INPUT_STATE_VISIBLE: 4
|
|
3437
|
-
},
|
|
3438
|
-
DefaultKeyboardToolbarTheme: {
|
|
3439
|
-
light: {
|
|
3440
|
-
primary: "#2c2c2c",
|
|
3441
|
-
disabled: "#B0BEC5",
|
|
3442
|
-
background: "#f3f3f4",
|
|
3443
|
-
ripple: "#bcbcbcbc"
|
|
3444
|
-
},
|
|
3445
|
-
dark: {
|
|
3446
|
-
primary: "#fafafa",
|
|
3447
|
-
disabled: "#707070",
|
|
3448
|
-
background: "#2C2C2E",
|
|
3449
|
-
ripple: "#F8F8F888"
|
|
3450
|
-
}
|
|
3451
|
-
},
|
|
3452
|
-
useKeyboardAnimation: () => animationValues.animated,
|
|
3453
|
-
useReanimatedKeyboardAnimation: () => animationValues.reanimated,
|
|
3454
|
-
useResizeMode: () => {},
|
|
3455
|
-
useGenericKeyboardHandler: () => {},
|
|
3456
|
-
useKeyboardHandler: () => {},
|
|
3457
|
-
useKeyboardContext: () => animationValues,
|
|
3458
|
-
useKeyboardState: (selector) => selector ? selector(keyboardState) : keyboardState,
|
|
3459
|
-
useReanimatedFocusedInput: () => focusedInput,
|
|
3460
|
-
useFocusedInputHandler: () => {},
|
|
3461
|
-
useKeyboardController: () => ({
|
|
3462
|
-
enabled: true,
|
|
3463
|
-
setEnabled: vi.fn()
|
|
3464
|
-
}),
|
|
3465
|
-
useWindowDimensions: () => ({
|
|
3466
|
-
width: 390,
|
|
3467
|
-
height: 844,
|
|
3468
|
-
scale: 3,
|
|
3469
|
-
fontScale: 1
|
|
3470
|
-
})
|
|
3471
|
-
};
|
|
3472
|
-
}
|
|
3473
|
-
}) }
|
|
3474
|
-
});
|
|
3475
|
-
}
|
|
3476
3533
|
// src/presets/worklets.ts
|
|
3477
3534
|
const RuntimeKind = {
|
|
3478
3535
|
ReactNative: 1,
|
|
@@ -4388,4 +4445,4 @@ var presets_exports = /* @__PURE__ */ __exportAll({
|
|
|
4388
4445
|
webview: () => webview,
|
|
4389
4446
|
worklets: () => worklets
|
|
4390
4447
|
});
|
|
4391
|
-
export {
|
|
4448
|
+
export { KEYBOARD_CONTROLLER_MOCK as A, navigation as C, reanimated as D, buildPressableHostProps as E, BUILT_IN_PRESET as F, createScrollViewMock as M, createViewMock as N, SAFE_AREA_MOCK as O, hostComponent as P, asyncStorage as S, createPressableMock as T, netInfo as _, bottomSheet as a, expo as b, createTouchableOpacityMock as c, createFlatListMock as d, createTextInputMock as f, svg as g, webview as h, worklets as i, keyboardController as j, safeAreaContext as k, createVirtualizedListMock as l, vectorIcons as m, skia as n, createTouchableWithoutFeedbackMock as o, flashList as p, unistyles as r, createTouchableHighlightMock as s, presets_exports as t, createSectionListMock as u, mmkv as v, gestureHandler as w, screens as x, deviceInfo as y };
|
package/dist/presets.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { S as asyncStorage, a as bottomSheet, y as deviceInfo, b as expo, p as flashList, w as gestureHandler, j as keyboardController, v as mmkv, C as navigation, _ as netInfo, D as reanimated, k as safeAreaContext, x as screens, n as skia, g as svg, r as unistyles, m as vectorIcons, h as webview, i as worklets } from "./presets-DLH7uRGA.mjs";
|
package/dist/setup.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { n as __require } from "./rolldown-runtime-D70C1uOS.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { E as buildPressableHostProps, M as createScrollViewMock, N as createViewMock, P as hostComponent, T as createPressableMock, c as createTouchableOpacityMock, d as createFlatListMock, f as createTextInputMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-DLH7uRGA.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";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { importPresetModule, presetModulePaths } from "./preset-modules.mjs";
|
|
8
|
-
import { projectContext } from "./context.mjs";
|
|
9
8
|
import { afterAll, afterEach, expect, vi } from "vitest";
|
|
10
9
|
import React from "react";
|
|
10
|
+
import { projectContext } from "./context.mjs";
|
|
11
11
|
import { installRendererReportError } from "./report-error.mjs";
|
|
12
12
|
import { installRntlAutoCleanup, installRntlLoadTracking } from "./rntl-support.mjs";
|
|
13
13
|
// src/mocks/components/Text.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.15.0
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expo",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"access": "public"
|
|
118
118
|
},
|
|
119
119
|
"scripts": {
|
|
120
|
-
"build": "
|
|
120
|
+
"build": "bun --bun tsdown && node scripts/copy-static-types.mjs && node scripts/build-stamp.mjs write",
|
|
121
121
|
"test": "node scripts/ci/vitest.mjs run",
|
|
122
122
|
"test:e2e": "node scripts/ci/vitest.mjs run --config vitest.e2e.config.ts",
|
|
123
123
|
"test:native": "node scripts/run-scripts.mjs test:native:no-globals test:native:main test:native:per-file test:native:rntl-timers test:native:one-instance test:native:context test:native:shared-root test:native:preset-modules test:native:permissive test:native:reanimated-fallback test:native:partial-mock-external test:native:tsconfig-paths test:native:regex-alias test:native:dispatch-alias test:native:jest-registry-node-mocks test:native:jest-compat-restore-mocks test:native:node-mocks test:native:ownership test:native:project-js-jsx test:native:jest-globals-require test:native:compile-error test:native:project-babel test:native:rn-deep-mock test:native:root-mocks test:native:library-setup-preset-off test:native:reanimated-shapes test:native:conformance",
|
|
@@ -229,6 +229,7 @@
|
|
|
229
229
|
"react-native-keyboard-controller": "1.22.9",
|
|
230
230
|
"react-native-reanimated": "4.7.1",
|
|
231
231
|
"react-native-safe-area-context": "5.11.0",
|
|
232
|
+
"react-native-screens": "4.25.2",
|
|
232
233
|
"react-native-skia": "3.8.1",
|
|
233
234
|
"react-native-svg": "15.16.0",
|
|
234
235
|
"react-native-unistyles": "3.7.0",
|