vitest-native 0.4.1 → 0.5.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/CHANGELOG.md +52 -0
- package/README.md +270 -180
- package/dist/helpers.cjs +13 -0
- package/dist/helpers.mjs +13 -0
- package/dist/{index-DEB7OFaJ.d.cts → index-DCSgnSj4.d.cts} +14 -8
- package/dist/{index-CJIhukN_.d.mts → index-EZmVLfjU.d.mts} +14 -8
- package/dist/index.cjs +104 -38
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +101 -35
- package/dist/jest-compat.cjs +1 -1
- package/dist/native/boundary.mjs +82 -32
- package/dist/native/globals.mjs +1 -0
- package/dist/native/hooks.mjs +16 -7
- package/dist/native/loader.mjs +18 -5
- package/dist/native/reset.mjs +79 -43
- package/dist/native/resolve.mjs +25 -7
- package/dist/native/setup.mjs +89 -4
- package/dist/native/transform.mjs +15 -9
- package/dist/native/worker.mjs +15 -3
- package/dist/{pool-oPTZiSXU.mjs → pool-B7LBfcMQ.mjs} +10 -1
- package/dist/{pool-B4mWN3N5.cjs → pool-p54QV1dQ.cjs} +11 -2
- package/dist/{presets-DOGXQzYT.mjs → presets-C9SvIaG-.mjs} +25 -21
- package/dist/{presets-2I68Ipyl.cjs → presets-E0yIUMJP.cjs} +27 -23
- package/dist/presets.cjs +1 -1
- package/dist/presets.d.cts +1 -1
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/setup.cjs +35 -8
- package/dist/setup.mjs +33 -6
- package/docs/migrating-from-jest.md +6 -4
- package/docs/migrating-from-vitest-react-native.md +6 -3
- package/docs/release-readiness.md +52 -0
- package/package.json +28 -19
|
@@ -416,20 +416,22 @@ function buildPressableHostProps(props, ref) {
|
|
|
416
416
|
...accessibilityState,
|
|
417
417
|
...disabled ? { disabled: true } : {}
|
|
418
418
|
} : void 0;
|
|
419
|
+
const pressProps = disabled ? {} : {
|
|
420
|
+
onStartShouldSetResponder: () => true,
|
|
421
|
+
onResponderGrant: (e) => onPressIn?.(e),
|
|
422
|
+
onResponderRelease: (e) => {
|
|
423
|
+
onPress?.(e);
|
|
424
|
+
onPressOut?.(e);
|
|
425
|
+
},
|
|
426
|
+
onPress,
|
|
427
|
+
onPressIn,
|
|
428
|
+
onPressOut,
|
|
429
|
+
onLongPress
|
|
430
|
+
};
|
|
419
431
|
return {
|
|
420
432
|
accessible: true,
|
|
421
|
-
...disabled ? {} : {
|
|
422
|
-
|
|
423
|
-
onResponderGrant: (e) => onPressIn?.(e),
|
|
424
|
-
onResponderRelease: (e) => {
|
|
425
|
-
onPress?.(e);
|
|
426
|
-
onPressOut?.(e);
|
|
427
|
-
},
|
|
428
|
-
onPress,
|
|
429
|
-
onPressIn,
|
|
430
|
-
onPressOut,
|
|
431
|
-
onLongPress
|
|
432
|
-
},
|
|
433
|
+
...disabled ? { pointerEvents: "none" } : {},
|
|
434
|
+
...pressProps,
|
|
433
435
|
...rest,
|
|
434
436
|
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
435
437
|
ref
|
|
@@ -691,9 +693,11 @@ function safeAreaContext() {
|
|
|
691
693
|
EdgeInsets: vi.fn(),
|
|
692
694
|
Rect: vi.fn(),
|
|
693
695
|
Metrics: vi.fn(),
|
|
696
|
+
/** Internal: update insets. Called by setInsets() helper. */
|
|
694
697
|
_setInsets: (insets) => {
|
|
695
698
|
Object.assign(state.insets, insets);
|
|
696
699
|
},
|
|
700
|
+
/** Internal: reset insets to defaults. Called by resetAllMocks(). */
|
|
697
701
|
_reset: () => {
|
|
698
702
|
Object.assign(state.insets, defaultInsets);
|
|
699
703
|
Object.assign(state.frame, defaultFrame);
|
|
@@ -1216,6 +1220,7 @@ function asyncStorage() {
|
|
|
1216
1220
|
});
|
|
1217
1221
|
}),
|
|
1218
1222
|
flushGetRequests: vi.fn(() => {}),
|
|
1223
|
+
/** Internal: reset store between tests. Called by resetAllMocks(). */
|
|
1219
1224
|
_resetStore: () => store.clear()
|
|
1220
1225
|
};
|
|
1221
1226
|
return {
|
|
@@ -1493,18 +1498,17 @@ const NUMBERS = {
|
|
|
1493
1498
|
getApiLevel: 33
|
|
1494
1499
|
};
|
|
1495
1500
|
function deviceInfo() {
|
|
1496
|
-
const exports = [
|
|
1497
|
-
...Object.keys(STRINGS),
|
|
1498
|
-
...Object.keys(BOOLEANS),
|
|
1499
|
-
...Object.keys(NUMBERS),
|
|
1500
|
-
...Object.keys(STRINGS).map((k) => k + "Sync"),
|
|
1501
|
-
...Object.keys(BOOLEANS).map((k) => k + "Sync"),
|
|
1502
|
-
...Object.keys(NUMBERS).map((k) => k + "Sync")
|
|
1503
|
-
];
|
|
1504
1501
|
return {
|
|
1505
1502
|
name: "deviceInfo",
|
|
1506
1503
|
modules: { "react-native-device-info": {
|
|
1507
|
-
exports
|
|
1504
|
+
exports: [
|
|
1505
|
+
...Object.keys(STRINGS),
|
|
1506
|
+
...Object.keys(BOOLEANS),
|
|
1507
|
+
...Object.keys(NUMBERS),
|
|
1508
|
+
...Object.keys(STRINGS).map((k) => k + "Sync"),
|
|
1509
|
+
...Object.keys(BOOLEANS).map((k) => k + "Sync"),
|
|
1510
|
+
...Object.keys(NUMBERS).map((k) => k + "Sync")
|
|
1511
|
+
],
|
|
1508
1512
|
factory: () => {
|
|
1509
1513
|
const api = {};
|
|
1510
1514
|
for (const [k, v] of Object.entries({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
|
-
node_path = require_chunk.__toESM(node_path);
|
|
3
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
4
4
|
let node_module = require("node:module");
|
|
5
5
|
let vitest = require("vitest");
|
|
6
6
|
let react = require("react");
|
|
7
|
-
react = require_chunk.__toESM(react);
|
|
7
|
+
react = require_chunk.__toESM(react, 1);
|
|
8
8
|
//#region src/presets/reanimated.ts
|
|
9
9
|
/**
|
|
10
10
|
* Resolve the *active* React Native module — the mock under `engine: 'mock'`
|
|
@@ -418,20 +418,22 @@ function buildPressableHostProps(props, ref) {
|
|
|
418
418
|
...accessibilityState,
|
|
419
419
|
...disabled ? { disabled: true } : {}
|
|
420
420
|
} : void 0;
|
|
421
|
+
const pressProps = disabled ? {} : {
|
|
422
|
+
onStartShouldSetResponder: () => true,
|
|
423
|
+
onResponderGrant: (e) => onPressIn?.(e),
|
|
424
|
+
onResponderRelease: (e) => {
|
|
425
|
+
onPress?.(e);
|
|
426
|
+
onPressOut?.(e);
|
|
427
|
+
},
|
|
428
|
+
onPress,
|
|
429
|
+
onPressIn,
|
|
430
|
+
onPressOut,
|
|
431
|
+
onLongPress
|
|
432
|
+
};
|
|
421
433
|
return {
|
|
422
434
|
accessible: true,
|
|
423
|
-
...disabled ? {} : {
|
|
424
|
-
|
|
425
|
-
onResponderGrant: (e) => onPressIn?.(e),
|
|
426
|
-
onResponderRelease: (e) => {
|
|
427
|
-
onPress?.(e);
|
|
428
|
-
onPressOut?.(e);
|
|
429
|
-
},
|
|
430
|
-
onPress,
|
|
431
|
-
onPressIn,
|
|
432
|
-
onPressOut,
|
|
433
|
-
onLongPress
|
|
434
|
-
},
|
|
435
|
+
...disabled ? { pointerEvents: "none" } : {},
|
|
436
|
+
...pressProps,
|
|
435
437
|
...rest,
|
|
436
438
|
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
437
439
|
ref
|
|
@@ -693,9 +695,11 @@ function safeAreaContext() {
|
|
|
693
695
|
EdgeInsets: vitest.vi.fn(),
|
|
694
696
|
Rect: vitest.vi.fn(),
|
|
695
697
|
Metrics: vitest.vi.fn(),
|
|
698
|
+
/** Internal: update insets. Called by setInsets() helper. */
|
|
696
699
|
_setInsets: (insets) => {
|
|
697
700
|
Object.assign(state.insets, insets);
|
|
698
701
|
},
|
|
702
|
+
/** Internal: reset insets to defaults. Called by resetAllMocks(). */
|
|
699
703
|
_reset: () => {
|
|
700
704
|
Object.assign(state.insets, defaultInsets);
|
|
701
705
|
Object.assign(state.frame, defaultFrame);
|
|
@@ -1218,6 +1222,7 @@ function asyncStorage() {
|
|
|
1218
1222
|
});
|
|
1219
1223
|
}),
|
|
1220
1224
|
flushGetRequests: vitest.vi.fn(() => {}),
|
|
1225
|
+
/** Internal: reset store between tests. Called by resetAllMocks(). */
|
|
1221
1226
|
_resetStore: () => store.clear()
|
|
1222
1227
|
};
|
|
1223
1228
|
return {
|
|
@@ -1495,18 +1500,17 @@ const NUMBERS = {
|
|
|
1495
1500
|
getApiLevel: 33
|
|
1496
1501
|
};
|
|
1497
1502
|
function deviceInfo() {
|
|
1498
|
-
const exports = [
|
|
1499
|
-
...Object.keys(STRINGS),
|
|
1500
|
-
...Object.keys(BOOLEANS),
|
|
1501
|
-
...Object.keys(NUMBERS),
|
|
1502
|
-
...Object.keys(STRINGS).map((k) => k + "Sync"),
|
|
1503
|
-
...Object.keys(BOOLEANS).map((k) => k + "Sync"),
|
|
1504
|
-
...Object.keys(NUMBERS).map((k) => k + "Sync")
|
|
1505
|
-
];
|
|
1506
1503
|
return {
|
|
1507
1504
|
name: "deviceInfo",
|
|
1508
1505
|
modules: { "react-native-device-info": {
|
|
1509
|
-
exports
|
|
1506
|
+
exports: [
|
|
1507
|
+
...Object.keys(STRINGS),
|
|
1508
|
+
...Object.keys(BOOLEANS),
|
|
1509
|
+
...Object.keys(NUMBERS),
|
|
1510
|
+
...Object.keys(STRINGS).map((k) => k + "Sync"),
|
|
1511
|
+
...Object.keys(BOOLEANS).map((k) => k + "Sync"),
|
|
1512
|
+
...Object.keys(NUMBERS).map((k) => k + "Sync")
|
|
1513
|
+
],
|
|
1510
1514
|
factory: () => {
|
|
1511
1515
|
const api = {};
|
|
1512
1516
|
for (const [k, v] of Object.entries({
|
package/dist/presets.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_presets = require("./presets-
|
|
2
|
+
const require_presets = require("./presets-E0yIUMJP.cjs");
|
|
3
3
|
exports.asyncStorage = require_presets.asyncStorage;
|
|
4
4
|
exports.deviceInfo = require_presets.deviceInfo;
|
|
5
5
|
exports.expo = require_presets.expo;
|
package/dist/presets.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, f as reanimated, i as mmkv, l as navigation, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./index-
|
|
1
|
+
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, f as reanimated, i as mmkv, l as navigation, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./index-DCSgnSj4.cjs";
|
|
2
2
|
export { asyncStorage, deviceInfo, expo, gestureHandler, mmkv, navigation, reanimated, safeAreaContext, screens, svg, webview };
|
package/dist/presets.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, f as reanimated, i as mmkv, l as navigation, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./index-
|
|
1
|
+
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, f as reanimated, i as mmkv, l as navigation, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./index-EZmVLfjU.mjs";
|
|
2
2
|
export { asyncStorage, deviceInfo, expo, gestureHandler, mmkv, navigation, reanimated, safeAreaContext, screens, svg, webview };
|
package/dist/presets.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, i as mmkv, l as navigation, m as reanimated, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./presets-
|
|
1
|
+
import { a as deviceInfo, c as asyncStorage, d as gestureHandler, i as mmkv, l as navigation, m as reanimated, n as webview, o as expo, r as svg, s as screens, u as safeAreaContext } from "./presets-C9SvIaG-.mjs";
|
|
2
2
|
export { asyncStorage, deviceInfo, expo, gestureHandler, mmkv, navigation, reanimated, safeAreaContext, screens, svg, webview };
|
package/dist/setup.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
2
|
const require_preset_map = require("./preset-map-C3jxnkiX.cjs");
|
|
3
|
-
const require_presets = require("./presets-
|
|
3
|
+
const require_presets = require("./presets-E0yIUMJP.cjs");
|
|
4
4
|
const require_serializer = require("./serializer.cjs");
|
|
5
5
|
const require_matchers = require("./matchers.cjs");
|
|
6
6
|
let node_path = require("node:path");
|
|
7
|
-
node_path = require_chunk.__toESM(node_path);
|
|
7
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
8
|
let node_module = require("node:module");
|
|
9
9
|
let vitest = require("vitest");
|
|
10
10
|
let react = require("react");
|
|
11
|
-
react = require_chunk.__toESM(react);
|
|
11
|
+
react = require_chunk.__toESM(react, 1);
|
|
12
12
|
//#region src/mocks/components/View.ts
|
|
13
13
|
function createViewMock() {
|
|
14
14
|
const View = react.default.forwardRef((props, ref) => {
|
|
@@ -255,6 +255,7 @@ function createTouchableNativeFeedbackMock() {
|
|
|
255
255
|
}
|
|
256
256
|
return react.default.createElement("TouchableNativeFeedback", {
|
|
257
257
|
accessible: true,
|
|
258
|
+
...disabled ? { pointerEvents: "none" } : {},
|
|
258
259
|
...rest,
|
|
259
260
|
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
260
261
|
ref
|
|
@@ -2524,6 +2525,8 @@ function installPresetCjsBridge(moduleName, mockObject) {
|
|
|
2524
2525
|
*/
|
|
2525
2526
|
const platform = process.env.VITEST_NATIVE_PLATFORM || "ios";
|
|
2526
2527
|
const diagnostics = process.env.VITEST_NATIVE_DIAGNOSTICS === "true";
|
|
2528
|
+
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
2529
|
+
const projectReq = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
2527
2530
|
let customMocks = {};
|
|
2528
2531
|
if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
2529
2532
|
customMocks = JSON.parse(process.env.VITEST_NATIVE_MOCKS);
|
|
@@ -2570,6 +2573,12 @@ Object.defineProperties(g, {
|
|
|
2570
2573
|
writable: true
|
|
2571
2574
|
}
|
|
2572
2575
|
});
|
|
2576
|
+
if (typeof g.expect === "undefined") Object.defineProperty(g, "expect", {
|
|
2577
|
+
configurable: true,
|
|
2578
|
+
enumerable: false,
|
|
2579
|
+
value: vitest.expect,
|
|
2580
|
+
writable: true
|
|
2581
|
+
});
|
|
2573
2582
|
g.IS_REACT_ACT_ENVIRONMENT = true;
|
|
2574
2583
|
g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
|
|
2575
2584
|
const rnMock = buildReactNativeMock(platform);
|
|
@@ -2583,14 +2592,15 @@ function loadPresetFactory(exportName) {
|
|
|
2583
2592
|
return typeof factory === "function" ? factory : null;
|
|
2584
2593
|
}
|
|
2585
2594
|
function autoDetectPresets() {
|
|
2586
|
-
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
2587
|
-
const projectReq = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
2588
2595
|
const detected = [];
|
|
2596
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
2589
2597
|
for (const [pkgName, exportName] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) try {
|
|
2590
2598
|
projectReq.resolve(pkgName);
|
|
2599
|
+
if (enabled.has(exportName)) continue;
|
|
2591
2600
|
const factory = loadPresetFactory(exportName);
|
|
2592
2601
|
if (factory) {
|
|
2593
2602
|
detected.push(factory());
|
|
2603
|
+
enabled.add(exportName);
|
|
2594
2604
|
if (diagnostics) console.log(`[vitest-native] Auto-detected ${pkgName} → enabled ${exportName} preset`);
|
|
2595
2605
|
}
|
|
2596
2606
|
} catch {}
|
|
@@ -2613,8 +2623,13 @@ for (const preset of presets) for (const [modName, presetModule] of Object.entri
|
|
|
2613
2623
|
if (diagnostics) console.log(`[vitest-native] Registered preset mock: ${modName} (${preset.name})`);
|
|
2614
2624
|
}
|
|
2615
2625
|
try {
|
|
2616
|
-
const rntl =
|
|
2617
|
-
|
|
2626
|
+
const rntl = projectReq("@testing-library/react-native");
|
|
2627
|
+
let rntlMajor = 0;
|
|
2628
|
+
try {
|
|
2629
|
+
const { version } = projectReq("@testing-library/react-native/package.json");
|
|
2630
|
+
rntlMajor = Number(String(version).split(".")[0]) || 0;
|
|
2631
|
+
} catch {}
|
|
2632
|
+
if (rntl?.configure && rntlMajor < 14) rntl.configure({ hostComponentNames: {
|
|
2618
2633
|
text: "Text",
|
|
2619
2634
|
textInput: "TextInput",
|
|
2620
2635
|
switch: "RCTSwitch",
|
|
@@ -2630,7 +2645,19 @@ try {
|
|
|
2630
2645
|
if (diagnostics) console.log(`[vitest-native] @testing-library/react-native not available: ${e?.message}`);
|
|
2631
2646
|
}
|
|
2632
2647
|
try {
|
|
2633
|
-
|
|
2648
|
+
let matchers = null;
|
|
2649
|
+
let lastError;
|
|
2650
|
+
for (const moduleId of [
|
|
2651
|
+
"@testing-library/react-native/matchers",
|
|
2652
|
+
"@testing-library/react-native/build/matchers",
|
|
2653
|
+
"@testing-library/react-native/dist/matchers"
|
|
2654
|
+
]) try {
|
|
2655
|
+
matchers = projectReq(moduleId);
|
|
2656
|
+
break;
|
|
2657
|
+
} catch (error) {
|
|
2658
|
+
lastError = error;
|
|
2659
|
+
}
|
|
2660
|
+
if (!matchers) throw lastError;
|
|
2634
2661
|
if (matchers && Object.keys(matchers).length > 0) {
|
|
2635
2662
|
const matcherFns = {};
|
|
2636
2663
|
for (const [key, val] of Object.entries(matchers)) if (typeof val === "function" && key !== "__esModule") matcherFns[key] = val;
|
package/dist/setup.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __require } from "./chunk-CjcI7cDX.mjs";
|
|
2
2
|
import { t as AUTO_DETECT_PRESETS } from "./preset-map-OJm5IWuL.mjs";
|
|
3
|
-
import { f as createPressableMock, p as buildPressableHostProps, t as presets_exports } from "./presets-
|
|
3
|
+
import { f as createPressableMock, p as buildPressableHostProps, t as presets_exports } from "./presets-C9SvIaG-.mjs";
|
|
4
4
|
import { serializer } from "./serializer.mjs";
|
|
5
5
|
import { animatedMatchers } from "./matchers.mjs";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
@@ -253,6 +253,7 @@ function createTouchableNativeFeedbackMock() {
|
|
|
253
253
|
}
|
|
254
254
|
return React.createElement("TouchableNativeFeedback", {
|
|
255
255
|
accessible: true,
|
|
256
|
+
...disabled ? { pointerEvents: "none" } : {},
|
|
256
257
|
...rest,
|
|
257
258
|
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
258
259
|
ref
|
|
@@ -2522,6 +2523,8 @@ function installPresetCjsBridge(moduleName, mockObject) {
|
|
|
2522
2523
|
*/
|
|
2523
2524
|
const platform = process.env.VITEST_NATIVE_PLATFORM || "ios";
|
|
2524
2525
|
const diagnostics = process.env.VITEST_NATIVE_DIAGNOSTICS === "true";
|
|
2526
|
+
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
2527
|
+
const projectReq = createRequire(path.join(projectRoot, "package.json"));
|
|
2525
2528
|
let customMocks = {};
|
|
2526
2529
|
if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
2527
2530
|
customMocks = JSON.parse(process.env.VITEST_NATIVE_MOCKS);
|
|
@@ -2568,6 +2571,12 @@ Object.defineProperties(g, {
|
|
|
2568
2571
|
writable: true
|
|
2569
2572
|
}
|
|
2570
2573
|
});
|
|
2574
|
+
if (typeof g.expect === "undefined") Object.defineProperty(g, "expect", {
|
|
2575
|
+
configurable: true,
|
|
2576
|
+
enumerable: false,
|
|
2577
|
+
value: expect,
|
|
2578
|
+
writable: true
|
|
2579
|
+
});
|
|
2571
2580
|
g.IS_REACT_ACT_ENVIRONMENT = true;
|
|
2572
2581
|
g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
|
|
2573
2582
|
const rnMock = buildReactNativeMock(platform);
|
|
@@ -2581,14 +2590,15 @@ function loadPresetFactory(exportName) {
|
|
|
2581
2590
|
return typeof factory === "function" ? factory : null;
|
|
2582
2591
|
}
|
|
2583
2592
|
function autoDetectPresets() {
|
|
2584
|
-
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
2585
|
-
const projectReq = createRequire(path.join(projectRoot, "package.json"));
|
|
2586
2593
|
const detected = [];
|
|
2594
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
2587
2595
|
for (const [pkgName, exportName] of Object.entries(AUTO_DETECT_PRESETS)) try {
|
|
2588
2596
|
projectReq.resolve(pkgName);
|
|
2597
|
+
if (enabled.has(exportName)) continue;
|
|
2589
2598
|
const factory = loadPresetFactory(exportName);
|
|
2590
2599
|
if (factory) {
|
|
2591
2600
|
detected.push(factory());
|
|
2601
|
+
enabled.add(exportName);
|
|
2592
2602
|
if (diagnostics) console.log(`[vitest-native] Auto-detected ${pkgName} → enabled ${exportName} preset`);
|
|
2593
2603
|
}
|
|
2594
2604
|
} catch {}
|
|
@@ -2611,8 +2621,13 @@ for (const preset of presets) for (const [modName, presetModule] of Object.entri
|
|
|
2611
2621
|
if (diagnostics) console.log(`[vitest-native] Registered preset mock: ${modName} (${preset.name})`);
|
|
2612
2622
|
}
|
|
2613
2623
|
try {
|
|
2614
|
-
const rntl =
|
|
2615
|
-
|
|
2624
|
+
const rntl = projectReq("@testing-library/react-native");
|
|
2625
|
+
let rntlMajor = 0;
|
|
2626
|
+
try {
|
|
2627
|
+
const { version } = projectReq("@testing-library/react-native/package.json");
|
|
2628
|
+
rntlMajor = Number(String(version).split(".")[0]) || 0;
|
|
2629
|
+
} catch {}
|
|
2630
|
+
if (rntl?.configure && rntlMajor < 14) rntl.configure({ hostComponentNames: {
|
|
2616
2631
|
text: "Text",
|
|
2617
2632
|
textInput: "TextInput",
|
|
2618
2633
|
switch: "RCTSwitch",
|
|
@@ -2628,7 +2643,19 @@ try {
|
|
|
2628
2643
|
if (diagnostics) console.log(`[vitest-native] @testing-library/react-native not available: ${e?.message}`);
|
|
2629
2644
|
}
|
|
2630
2645
|
try {
|
|
2631
|
-
|
|
2646
|
+
let matchers = null;
|
|
2647
|
+
let lastError;
|
|
2648
|
+
for (const moduleId of [
|
|
2649
|
+
"@testing-library/react-native/matchers",
|
|
2650
|
+
"@testing-library/react-native/build/matchers",
|
|
2651
|
+
"@testing-library/react-native/dist/matchers"
|
|
2652
|
+
]) try {
|
|
2653
|
+
matchers = projectReq(moduleId);
|
|
2654
|
+
break;
|
|
2655
|
+
} catch (error) {
|
|
2656
|
+
lastError = error;
|
|
2657
|
+
}
|
|
2658
|
+
if (!matchers) throw lastError;
|
|
2632
2659
|
if (matchers && Object.keys(matchers).length > 0) {
|
|
2633
2660
|
const matcherFns = {};
|
|
2634
2661
|
for (const [key, val] of Object.entries(matchers)) if (typeof val === "function" && key !== "__esModule") matcherFns[key] = val;
|
|
@@ -71,9 +71,11 @@ on the literal `jest.mock` member form, not `jest` aliased to another local name
|
|
|
71
71
|
|
|
72
72
|
…and in most cases you can **delete** third-party native-lib mocks entirely — see 2c.
|
|
73
73
|
|
|
74
|
-
### 2b. Upgrade RNTL to
|
|
74
|
+
### 2b. Upgrade RNTL to 12–14 (recommended)
|
|
75
75
|
The `@jest/globals` alias unblocks RNTL < 12, but **upgrading to `@testing-library/react-native@^12`
|
|
76
|
-
is the cleaner fix** (12 dropped the `@jest/globals` dependency). vitest-native
|
|
76
|
+
is the cleaner fix** (12 dropped the `@jest/globals` dependency). vitest-native supports RNTL
|
|
77
|
+
12–14. RNTL 14 requires Node 22.13 or 24+ and makes rendering APIs async, so await `render` and
|
|
78
|
+
other APIs as described in its migration guide.
|
|
77
79
|
|
|
78
80
|
### 2c. Delete third-party native-lib mocks — they're automatic now
|
|
79
81
|
You do **not** need `jest.mock('react-native-reanimated', …)`, safe-area's `jest/mock`,
|
|
@@ -108,7 +110,7 @@ no-op under the shim (use `test.testTimeout` in config or per-test `{ timeout }`
|
|
|
108
110
|
|
|
109
111
|
## 3. Suggested migration recipe
|
|
110
112
|
|
|
111
|
-
1. Add the jest-compat config (section 1). Upgrade RNTL to
|
|
113
|
+
1. Add the jest-compat config (section 1). Upgrade RNTL to a supported 12–14 release (2b).
|
|
112
114
|
2. Delete manual third-party native-lib mocks and `@react-native/jest-preset` (2c, 2e).
|
|
113
115
|
3. Convert any **top-level** `jest.mock(...)` to `vi.mock(...)`; leave runtime `jest.*` as-is (2a).
|
|
114
116
|
4. Run `vitest run -u` once to re-record snapshots (2d), then `vitest run` to confirm green.
|
|
@@ -116,7 +118,7 @@ no-op under the shim (use `test.testTimeout` in config or per-test `{ timeout }`
|
|
|
116
118
|
|
|
117
119
|
## 4. What "done" looks like
|
|
118
120
|
|
|
119
|
-
A migrated suite runs under Vitest with: the jest-compat aliases + setup, RNTL
|
|
121
|
+
A migrated suite runs under Vitest with: the jest-compat aliases + setup, RNTL 12–14, no manual
|
|
120
122
|
third-party native mocks, top-level mocks converted, and snapshots re-recorded. You get Vitest's
|
|
121
123
|
speed/watch/UI while keeping `engine: 'native'` real-RN fidelity (or `engine: 'mock'` for the fast
|
|
122
124
|
path). The compat layer is intentionally small — it removes the mechanical Jest coupling so the only
|
|
@@ -27,8 +27,9 @@ npm i -D vitest-native @react-native/babel-preset @babel/core
|
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Keep your existing `vitest`, `vite`, `react`, `react-native`, and
|
|
30
|
-
`@testing-library/react-native`. Requirements: **Vitest
|
|
31
|
-
React Native 0.81–0.
|
|
30
|
+
`@testing-library/react-native`. Requirements: **Vitest 4.x, Vite ^6.4.2, ^7.3.2, or ^8.0.5, the React
|
|
31
|
+
version required by your RN release, React Native 0.81–0.86 (validated), and
|
|
32
|
+
RNTL 12–14.** RNTL 14 uses async rendering APIs and requires Node 22.13 or 24+.
|
|
32
33
|
|
|
33
34
|
## 2. Update `vitest.config`
|
|
34
35
|
|
|
@@ -89,7 +90,9 @@ Your existing tests render against real React Native exactly as before.
|
|
|
89
90
|
- **Presets** auto-shadow common native libraries (Reanimated, Gesture Handler,
|
|
90
91
|
Safe Area, Navigation, …) the way `jest` mocks them — no per-lib wiring.
|
|
91
92
|
- An opt-in **hot runtime** (`reactNative({ hotRuntime: true })`) keeps RN warm
|
|
92
|
-
across files for large suites
|
|
93
|
+
across files for large suites while resetting app/test modules and common
|
|
94
|
+
process-wide pollution between files. It uses Vitest's custom worker APIs and
|
|
95
|
+
remains experimental.
|
|
93
96
|
|
|
94
97
|
## Gotchas (the margins)
|
|
95
98
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Release readiness policy
|
|
2
|
+
|
|
3
|
+
This document defines what `vitest-native` means by release-supported. It is deliberately stricter
|
|
4
|
+
than "the repository tests pass": published artifacts are installed into representative consumer
|
|
5
|
+
projects, experimental surfaces are labeled, and upstream compatibility is bounded.
|
|
6
|
+
|
|
7
|
+
## Stability labels
|
|
8
|
+
|
|
9
|
+
| Surface | Status | Release promise |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| Mock engine | Release-supported | Documented behavior and exports are gated on every pull request and release. |
|
|
12
|
+
| Native engine | Release-supported beta | Real RN behavior, iOS/Android resolution, presets, helpers, assets, matchers, and isolation are blocking gates. Pre-1.0 APIs can still change with release notes. |
|
|
13
|
+
| Hot runtime | Experimental | Correctness is gated, but it depends on Vitest's experimental custom-pool API and can require adaptation between Vitest releases. |
|
|
14
|
+
| Current RN edge | Canary | Tested weekly and in a pinned packed consumer once adopted; an edge failure opens a compatibility issue. |
|
|
15
|
+
|
|
16
|
+
## Blocking compatibility matrix
|
|
17
|
+
|
|
18
|
+
- Node 20.19 on Linux.
|
|
19
|
+
- Node 22.13 on Linux, macOS, and Windows.
|
|
20
|
+
- Patched Vite lines ^6.4.2, ^7.3.2, and ^8.0.5 through packed consumers.
|
|
21
|
+
- Vitest 4.x, including the lockfile release and newest supported 4.x release.
|
|
22
|
+
- React Native 0.81–0.85 in the full native matrix.
|
|
23
|
+
- React Native 0.86 in a pinned packed Android consumer.
|
|
24
|
+
- React Native Testing Library 12, 13, and 14.
|
|
25
|
+
- Expo 56 and a hoisted npm-workspace monorepo.
|
|
26
|
+
|
|
27
|
+
Required Vite, Vitest, and React peer mismatches fail during configuration. Unsupported future major
|
|
28
|
+
versions are rejected rather than allowed to fail later inside private runner internals.
|
|
29
|
+
|
|
30
|
+
## Blocking release gates
|
|
31
|
+
|
|
32
|
+
1. Dependency pinning, lint, formatting, and TypeScript checks.
|
|
33
|
+
2. Mock suite and React Native conformance tests.
|
|
34
|
+
3. Native iOS and Android suites.
|
|
35
|
+
4. Hot-runtime full suite, cross-file isolation suite, and generated 100-file soak.
|
|
36
|
+
5. End-to-end memory-triggered worker recycling.
|
|
37
|
+
6. Mock-versus-real-RN behavioral cross-check.
|
|
38
|
+
7. Example app.
|
|
39
|
+
8. `npm pack` followed by isolated installs of bare RN, Expo, monorepo, and current-RN consumers.
|
|
40
|
+
9. Package export and declaration analysis with `@arethetypeswrong/cli`.
|
|
41
|
+
10. Staged npm publishing with provenance; the version remains unavailable until maintainer approval.
|
|
42
|
+
|
|
43
|
+
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20+. It also
|
|
44
|
+
allows `cjs-resolves-to-esm` only for the three `jest-compat` runtime shims: those entries depend on
|
|
45
|
+
Vitest's ESM runtime and are setup-file or Vite-alias targets. All normal public APIs are gated as
|
|
46
|
+
dual ESM/CommonJS exports.
|
|
47
|
+
|
|
48
|
+
## Release decision
|
|
49
|
+
|
|
50
|
+
A release is blocked by any failure in the declared support range. Canary failures do not silently
|
|
51
|
+
expand the support range: they produce a tracked compatibility issue and must be resolved before the
|
|
52
|
+
new upstream major or RN minor is advertised as supported.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run real React Native tests under Vitest. One install, zero config.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -100,15 +100,15 @@
|
|
|
100
100
|
},
|
|
101
101
|
"./jest-compat/setup": {
|
|
102
102
|
"types": "./dist/jest-compat/setup.d.mts",
|
|
103
|
-
"
|
|
103
|
+
"import": "./dist/jest-compat/setup.mjs"
|
|
104
104
|
},
|
|
105
105
|
"./jest-compat/jest-globals": {
|
|
106
106
|
"types": "./dist/jest-compat/jest-globals.d.mts",
|
|
107
|
-
"
|
|
107
|
+
"import": "./dist/jest-compat/jest-globals.mjs"
|
|
108
108
|
},
|
|
109
109
|
"./jest-compat/extend-expect-noop": {
|
|
110
110
|
"types": "./dist/jest-compat/noop.d.mts",
|
|
111
|
-
"
|
|
111
|
+
"import": "./dist/jest-compat/noop.mjs"
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
114
|
"files": [
|
|
@@ -120,15 +120,20 @@
|
|
|
120
120
|
"engines": {
|
|
121
121
|
"node": ">=20"
|
|
122
122
|
},
|
|
123
|
-
"sideEffects":
|
|
123
|
+
"sideEffects": [
|
|
124
|
+
"./dist/setup.cjs",
|
|
125
|
+
"./dist/setup.mjs",
|
|
126
|
+
"./dist/jest-compat/setup.mjs",
|
|
127
|
+
"./dist/native/*.mjs"
|
|
128
|
+
],
|
|
124
129
|
"publishConfig": {
|
|
125
130
|
"access": "public"
|
|
126
131
|
},
|
|
127
132
|
"peerDependencies": {
|
|
128
133
|
"react": ">=18",
|
|
129
|
-
"vite": "
|
|
130
|
-
"vitest": ">=4",
|
|
131
|
-
"@testing-library/react-native": ">=12",
|
|
134
|
+
"vite": "^6.4.2 || ^7.3.2 || ^8.0.5",
|
|
135
|
+
"vitest": ">=4 <5",
|
|
136
|
+
"@testing-library/react-native": ">=12 <15",
|
|
132
137
|
"@react-native/babel-preset": "*",
|
|
133
138
|
"@babel/core": "*"
|
|
134
139
|
},
|
|
@@ -151,33 +156,37 @@
|
|
|
151
156
|
"@testing-library/react-native": "^12.9.0",
|
|
152
157
|
"@types/node": "25.3.5",
|
|
153
158
|
"@types/react": "19.2.14",
|
|
154
|
-
"@vitest/coverage-v8": "4.
|
|
159
|
+
"@vitest/coverage-v8": "4.1.8",
|
|
155
160
|
"expo-constants": "56.0.16",
|
|
156
161
|
"expo-status-bar": "56.0.4",
|
|
157
|
-
"react": "^19.
|
|
158
|
-
"react-native": "^0.
|
|
162
|
+
"react": "^19.2.3",
|
|
163
|
+
"react-native": "^0.85.3",
|
|
159
164
|
"react-native-gesture-handler": "3.0.0",
|
|
160
165
|
"react-native-reanimated": "4.3.1",
|
|
161
166
|
"react-native-safe-area-context": "5.8.0",
|
|
162
167
|
"react-native-worklets": "0.9.1",
|
|
163
|
-
"react-test-renderer": "^19.
|
|
164
|
-
"tsdown": "0.21.
|
|
168
|
+
"react-test-renderer": "^19.2.3",
|
|
169
|
+
"tsdown": "0.21.10",
|
|
165
170
|
"typescript": "5.9.3",
|
|
166
|
-
"vite": "^
|
|
167
|
-
"vitest": "^4.
|
|
171
|
+
"vite": "^8.0.5",
|
|
172
|
+
"vitest": "^4.1.8"
|
|
168
173
|
},
|
|
169
174
|
"scripts": {
|
|
170
175
|
"build": "tsdown",
|
|
171
176
|
"test": "vitest run",
|
|
172
177
|
"test:native": "vitest run --config tests-native/vitest.config.mts",
|
|
178
|
+
"test:native:android": "vitest run --config tests-native/vitest.android.config.mts",
|
|
173
179
|
"test:native:hot": "vitest run --config tests-native/vitest.hot.config.mts",
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
"
|
|
180
|
+
"test:native:hot:isolation": "vitest run --config tests-native/vitest.hot-isolation.config.mts",
|
|
181
|
+
"test:native:hot:soak": "node scripts/test-hot-soak.mjs",
|
|
182
|
+
"test:consumers": "node scripts/test-consumers.mjs",
|
|
183
|
+
"lint": "oxlint --deny-warnings src/ tests/ tests-native/ crosscheck/ consumer-tests/ scripts/",
|
|
184
|
+
"format": "oxfmt --write src/ tests/ consumer-tests/ scripts/",
|
|
185
|
+
"format:check": "oxfmt --check src/ tests/ consumer-tests/ scripts/",
|
|
177
186
|
"check-compat": "bun scripts/check-compat.ts",
|
|
178
187
|
"typecheck": "tsc --noEmit",
|
|
179
188
|
"clean": "rm -rf dist",
|
|
180
|
-
"prepublishOnly": "bun run build && bun run test && bun run lint && bun run typecheck",
|
|
189
|
+
"prepublishOnly": "bun run build && bun run test && bun run test:native && bun run test:native:android && bun run test:native:hot && bun run test:native:hot:isolation && bun run test:native:hot:soak && bun run crosscheck && bun run test:consumers && bun run lint && bun run typecheck",
|
|
181
190
|
"crosscheck": "node scripts/crosscheck.mjs"
|
|
182
191
|
},
|
|
183
192
|
"dependencies": {
|