vitest-native 0.9.0 → 0.11.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +921 -0
  2. package/README.md +33 -1
  3. package/dist/cli.cjs +185 -31
  4. package/dist/cli.mjs +182 -28
  5. package/dist/ecosystem-BJzJU3Cf.cjs +568 -0
  6. package/dist/ecosystem-C4qT_vl3.mjs +506 -0
  7. package/dist/errors-B3lJK46O.cjs +75 -0
  8. package/dist/errors-CxoBUfVJ.mjs +64 -0
  9. package/dist/errors.d.mts +46 -0
  10. package/dist/errors.mjs +78 -0
  11. package/dist/helpers.cjs +6 -23
  12. package/dist/helpers.d.cts +0 -6
  13. package/dist/helpers.d.mts +0 -6
  14. package/dist/helpers.mjs +6 -23
  15. package/dist/{index-CEgRDdhd.d.cts → index-CrMeE8rd.d.mts} +14 -9
  16. package/dist/{index-j-0tueBr.d.mts → index-DIMbjH8R.d.cts} +15 -7
  17. package/dist/index.d.mts +8 -7
  18. package/dist/index.mjs +307 -91
  19. package/dist/jest-compat/interop.mjs +15 -0
  20. package/dist/jest-compat/setup.mjs +102 -7
  21. package/dist/jest-compat.cjs +4 -4
  22. package/dist/jest-compat.d.cts +0 -1
  23. package/dist/jest-compat.d.mts +0 -1
  24. package/dist/jest-compat.mjs +2 -2
  25. package/dist/matchers.cjs +16 -7
  26. package/dist/matchers.mjs +16 -7
  27. package/dist/native/hooks.mjs +152 -13
  28. package/dist/native/loader.mjs +36 -11
  29. package/dist/native/match.d.mts +33 -0
  30. package/dist/native/match.mjs +94 -22
  31. package/dist/native/module-reset.mjs +63 -0
  32. package/dist/native/registry.mjs +110 -13
  33. package/dist/native/resolve.d.mts +22 -0
  34. package/dist/native/resolve.mjs +21 -13
  35. package/dist/native/runner.mjs +21 -0
  36. package/dist/native/setup.mjs +4 -2
  37. package/dist/native/transform.mjs +108 -3
  38. package/dist/native/worker.mjs +59 -16
  39. package/dist/{pool-DzsEo9vv.cjs → pool-BU-1ecIF.cjs} +7 -6
  40. package/dist/{pool-CJmjRgsB.mjs → pool-Bcxn9a3I.mjs} +4 -3
  41. package/dist/{preset-map-CG4FMtsl.cjs → preset-map-BoG19dLa.cjs} +1 -1
  42. package/dist/{preset-map-CNsZKfvu.mjs → preset-map-DuX0ocdn.mjs} +1 -1
  43. package/dist/{presets-C4faM3ds.cjs → presets-CwO_c4aL.cjs} +224 -55
  44. package/dist/{presets-CuDrNA_W.mjs → presets-IStcJEOa.mjs} +216 -53
  45. package/dist/presets.d.mts +2 -2
  46. package/dist/presets.mjs +2 -2
  47. package/dist/rntl-matchers.d.ts +35 -0
  48. package/dist/{chunk-CjcI7cDX.mjs → rolldown-runtime-BhDjJH2R.mjs} +1 -1
  49. package/dist/{chunk-CZWwpsFl.cjs → rolldown-runtime-C0BPl7ul.cjs} +1 -1
  50. package/dist/serializer.cjs +34 -4
  51. package/dist/serializer.mjs +34 -4
  52. package/dist/setup.d.mts +1 -1
  53. package/dist/setup.mjs +237 -74
  54. package/docs/release-readiness.md +22 -5
  55. package/docs/versioning.md +133 -0
  56. package/package.json +38 -46
  57. package/dist/ecosystem-BIWaVwYL.cjs +0 -294
  58. package/dist/ecosystem-EFtHnKS9.mjs +0 -256
  59. package/dist/index.cjs +0 -788
  60. package/dist/index.d.cts +0 -14
  61. package/dist/presets.cjs +0 -18
  62. package/dist/presets.d.cts +0 -2
  63. package/dist/setup.cjs +0 -2702
  64. package/dist/setup.d.cts +0 -1
@@ -1,10 +1,11 @@
1
- const require_chunk = require("./chunk-CZWwpsFl.cjs");
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ const require_errors = require("./errors-B3lJK46O.cjs");
2
3
  let node_path = require("node:path");
3
- node_path = require_chunk.__toESM(node_path, 1);
4
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
4
5
  let node_module = require("node:module");
5
6
  let vitest = require("vitest");
6
7
  let react = require("react");
7
- react = require_chunk.__toESM(react, 1);
8
+ react = require_rolldown_runtime.__toESM(react, 1);
8
9
  //#region src/presets/reanimated.ts
9
10
  /**
10
11
  * Resolve the *active* React Native module — the mock under `engine: 'mock'`
@@ -16,7 +17,8 @@ let _rnCache = null;
16
17
  function getRN() {
17
18
  if (_rnCache) return _rnCache;
18
19
  try {
19
- _rnCache = (0, node_module.createRequire)(node_path.default.join(process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd(), "package.json"))("react-native");
20
+ const base = node_path.default.join(process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd(), "package.json");
21
+ _rnCache = (0, node_module.createRequire)(base)("react-native");
20
22
  } catch {
21
23
  _rnCache = {};
22
24
  }
@@ -49,11 +51,6 @@ function reanimated() {
49
51
  "addWhitelistedUIProps",
50
52
  "addWhitelistedNativeProps",
51
53
  "configureProps",
52
- "View",
53
- "Text",
54
- "Image",
55
- "ScrollView",
56
- "FlatList",
57
54
  "Easing",
58
55
  "FadeIn",
59
56
  "FadeOut",
@@ -233,7 +230,7 @@ function reanimated() {
233
230
  function makeAnimatedHost(name) {
234
231
  const Comp = react.default.forwardRef((props, ref) => {
235
232
  const Base = getRN()[name];
236
- if (!Base) throw new Error(`[vitest-native] reanimated preset: react-native '${name}' is unavailable`);
233
+ if (!Base) throw new require_errors.VitestNativeError("PRESET_UNAVAILABLE", `The reanimated preset needs React Native's '${name}' component to build Animated.${name}, and react-native did not provide it.\nThis usually means react-native resolved to something unexpected — a partially installed copy, or a mock replacing the whole module. Check that 'react-native' resolves in your project and that no vi.mock replaces it wholesale.`);
237
234
  return react.default.createElement(Base, {
238
235
  ...props,
239
236
  ref
@@ -280,11 +277,6 @@ function reanimated() {
280
277
  addWhitelistedUIProps,
281
278
  addWhitelistedNativeProps,
282
279
  configureProps,
283
- View,
284
- Text,
285
- Image,
286
- ScrollView,
287
- FlatList,
288
280
  useSharedValue,
289
281
  useAnimatedStyle,
290
282
  useAnimatedProps,
@@ -644,10 +636,7 @@ function safeAreaContext() {
644
636
  "useSafeAreaFrame",
645
637
  "withSafeAreaInsets",
646
638
  "initialWindowMetrics",
647
- "initialWindowSafeAreaInsets",
648
- "EdgeInsets",
649
- "Rect",
650
- "Metrics"
639
+ "initialWindowSafeAreaInsets"
651
640
  ],
652
641
  factory: () => {
653
642
  const defaultInsets = {
@@ -1265,12 +1254,29 @@ function screens() {
1265
1254
  "screensEnabled",
1266
1255
  "enableFreeze",
1267
1256
  "freezeEnabled",
1257
+ "featureFlags",
1258
+ "compatibilityFlags",
1259
+ "executeNativeBackPress",
1260
+ "isSearchBarAvailableForCurrentPlatform",
1261
+ "useTransitionProgress",
1268
1262
  "Screen",
1263
+ "InnerScreen",
1269
1264
  "ScreenContainer",
1265
+ "ScreenContentWrapper",
1266
+ "ScreenContext",
1267
+ "ScreenFooter",
1270
1268
  "ScreenStack",
1269
+ "ScreenStackItem",
1271
1270
  "ScreenStackHeaderConfig",
1271
+ "ScreenStackHeaderBackButtonImage",
1272
+ "ScreenStackHeaderCenterView",
1273
+ "ScreenStackHeaderLeftView",
1274
+ "ScreenStackHeaderRightView",
1275
+ "ScreenStackHeaderSearchBarView",
1276
+ "ScreenStackHeaderSubview",
1272
1277
  "SearchBar",
1273
1278
  "FullWindowOverlay",
1279
+ "Tabs",
1274
1280
  "NativeScreen",
1275
1281
  "NativeScreenContainer"
1276
1282
  ],
@@ -1301,6 +1307,24 @@ function screens() {
1301
1307
  const FullWindowOverlay = createScreenComponent("FullWindowOverlay");
1302
1308
  const NativeScreen = createScreenComponent("NativeScreen");
1303
1309
  const NativeScreenContainer = createScreenComponent("NativeScreenContainer");
1310
+ const InnerScreen = createScreenComponent("InnerScreen");
1311
+ const ScreenContentWrapper = createScreenComponent("ScreenContentWrapper");
1312
+ const ScreenFooter = createScreenComponent("ScreenFooter");
1313
+ const ScreenStackItem = createScreenComponent("ScreenStackItem");
1314
+ const ScreenStackHeaderBackButtonImage = createScreenComponent("ScreenStackHeaderBackButtonImage");
1315
+ const ScreenStackHeaderCenterView = createScreenComponent("ScreenStackHeaderCenterView");
1316
+ const ScreenStackHeaderLeftView = createScreenComponent("ScreenStackHeaderLeftView");
1317
+ const ScreenStackHeaderRightView = createScreenComponent("ScreenStackHeaderRightView");
1318
+ const ScreenStackHeaderSearchBarView = createScreenComponent("ScreenStackHeaderSearchBarView");
1319
+ const ScreenStackHeaderSubview = createScreenComponent("ScreenStackHeaderSubview");
1320
+ const Tabs = createScreenComponent("Tabs");
1321
+ const ScreenContext = react.default.createContext(Screen);
1322
+ const useTransitionProgress = vitest.vi.fn(() => ({
1323
+ progress: 1,
1324
+ closing: 0,
1325
+ goingForward: 0
1326
+ }));
1327
+ const executeNativeBackPress = vitest.vi.fn(() => true);
1304
1328
  return {
1305
1329
  default: {
1306
1330
  Screen,
@@ -1319,7 +1343,27 @@ function screens() {
1319
1343
  SearchBar,
1320
1344
  FullWindowOverlay,
1321
1345
  NativeScreen,
1322
- NativeScreenContainer
1346
+ NativeScreenContainer,
1347
+ InnerScreen,
1348
+ ScreenContentWrapper,
1349
+ ScreenContext,
1350
+ ScreenFooter,
1351
+ ScreenStackItem,
1352
+ ScreenStackHeaderBackButtonImage,
1353
+ ScreenStackHeaderCenterView,
1354
+ ScreenStackHeaderLeftView,
1355
+ ScreenStackHeaderRightView,
1356
+ ScreenStackHeaderSearchBarView,
1357
+ ScreenStackHeaderSubview,
1358
+ Tabs,
1359
+ useTransitionProgress,
1360
+ executeNativeBackPress,
1361
+ isSearchBarAvailableForCurrentPlatform: true,
1362
+ featureFlags: {
1363
+ experiment: {},
1364
+ flags: {}
1365
+ },
1366
+ compatibilityFlags: {}
1323
1367
  };
1324
1368
  }
1325
1369
  } }
@@ -1333,42 +1377,44 @@ function expo() {
1333
1377
  modules: {
1334
1378
  "expo-constants": {
1335
1379
  exports: [
1336
- "expoConfig",
1337
- "executionEnvironment",
1338
- "appOwnership",
1339
- "isDevice",
1340
- "platform",
1341
- "manifest",
1342
- "manifest2",
1343
- "expoGoConfig",
1344
- "easConfig",
1345
- "experienceUrl",
1346
- "linkingUri",
1347
- "getWebViewUserAgentAsync"
1380
+ "AppOwnership",
1381
+ "ExecutionEnvironment",
1382
+ "UserInterfaceIdiom"
1348
1383
  ],
1349
1384
  factory: () => {
1350
- const Constants = {
1351
- expoConfig: {
1352
- name: "test-app",
1353
- slug: "test-app",
1354
- version: "1.0.0",
1355
- extra: {}
1356
- },
1357
- executionEnvironment: "storeClient",
1358
- appOwnership: "standalone",
1359
- isDevice: true,
1360
- platform: {},
1361
- manifest: null,
1362
- manifest2: null,
1363
- expoGoConfig: null,
1364
- easConfig: null,
1365
- experienceUrl: "",
1366
- linkingUri: "",
1367
- getWebViewUserAgentAsync: vitest.vi.fn(async () => "test-user-agent")
1368
- };
1369
1385
  return {
1370
- default: Constants,
1371
- ...Constants
1386
+ default: {
1387
+ expoConfig: {
1388
+ name: "test-app",
1389
+ slug: "test-app",
1390
+ version: "1.0.0",
1391
+ extra: {}
1392
+ },
1393
+ executionEnvironment: "storeClient",
1394
+ appOwnership: "standalone",
1395
+ isDevice: true,
1396
+ platform: {},
1397
+ manifest: null,
1398
+ manifest2: null,
1399
+ expoGoConfig: null,
1400
+ easConfig: null,
1401
+ experienceUrl: "",
1402
+ linkingUri: "",
1403
+ getWebViewUserAgentAsync: vitest.vi.fn(async () => "test-user-agent")
1404
+ },
1405
+ AppOwnership: { Expo: "expo" },
1406
+ ExecutionEnvironment: {
1407
+ Bare: "bare",
1408
+ Standalone: "standalone",
1409
+ StoreClient: "storeClient"
1410
+ },
1411
+ UserInterfaceIdiom: {
1412
+ Handset: "handset",
1413
+ Tablet: "tablet",
1414
+ Desktop: "desktop",
1415
+ TV: "tv",
1416
+ Unsupported: "unsupported"
1417
+ }
1372
1418
  };
1373
1419
  }
1374
1420
  },
@@ -1667,6 +1713,123 @@ function mmkv() {
1667
1713
  };
1668
1714
  }
1669
1715
  //#endregion
1716
+ //#region src/presets/netinfo.ts
1717
+ /**
1718
+ * The state every fetch/listener resolves to until a test changes it.
1719
+ *
1720
+ * Derived from ONE constant so `_reset()` and the initial value cannot drift — the
1721
+ * failure mode where `beforeEach(_reset())` masks the default it claims to test.
1722
+ *
1723
+ * The real library starts at `{ type: 'unknown', isConnected: null, … }` and resolves
1724
+ * to the device's actual connection a moment later. A mock has no device, and a null
1725
+ * resting state would send every component under test down its offline branch, so the
1726
+ * resting state here is a connected wifi device — the same reasoning that gives
1727
+ * Dimensions a device-shaped default.
1728
+ */
1729
+ const RESTING = {
1730
+ type: "wifi",
1731
+ isConnected: true,
1732
+ isInternetReachable: true,
1733
+ details: {
1734
+ isConnectionExpensive: false,
1735
+ ssid: null,
1736
+ bssid: null,
1737
+ strength: null,
1738
+ ipAddress: null,
1739
+ subnet: null,
1740
+ frequency: null,
1741
+ linkSpeed: null,
1742
+ rxLinkSpeed: null,
1743
+ txLinkSpeed: null
1744
+ }
1745
+ };
1746
+ const state = () => structuredClone(RESTING);
1747
+ function netInfo() {
1748
+ return {
1749
+ name: "netInfo",
1750
+ modules: { "@react-native-community/netinfo": {
1751
+ exports: [
1752
+ "configure",
1753
+ "fetch",
1754
+ "refresh",
1755
+ "addEventListener",
1756
+ "useNetInfo",
1757
+ "useNetInfoInstance",
1758
+ "NetInfoStateType",
1759
+ "NetInfoCellularGeneration"
1760
+ ],
1761
+ factory: () => {
1762
+ let current = state();
1763
+ const listeners = /* @__PURE__ */ new Set();
1764
+ const emit = () => {
1765
+ for (const listener of listeners) listener(current);
1766
+ };
1767
+ const fetch = vitest.vi.fn(async () => current);
1768
+ const refresh = vitest.vi.fn(async () => current);
1769
+ const configure = vitest.vi.fn(() => {
1770
+ listeners.clear();
1771
+ });
1772
+ const addEventListener = vitest.vi.fn((listener) => {
1773
+ listeners.add(listener);
1774
+ listener(current);
1775
+ return () => {
1776
+ listeners.delete(listener);
1777
+ };
1778
+ });
1779
+ const useNetInfo = vitest.vi.fn(() => current);
1780
+ const useNetInfoInstance = vitest.vi.fn(() => ({
1781
+ netInfo: current,
1782
+ refresh
1783
+ }));
1784
+ const NetInfoStateType = {
1785
+ unknown: "unknown",
1786
+ none: "none",
1787
+ cellular: "cellular",
1788
+ wifi: "wifi",
1789
+ bluetooth: "bluetooth",
1790
+ ethernet: "ethernet",
1791
+ wimax: "wimax",
1792
+ vpn: "vpn",
1793
+ other: "other"
1794
+ };
1795
+ const NetInfoCellularGeneration = {
1796
+ "2g": "2g",
1797
+ "3g": "3g",
1798
+ "4g": "4g",
1799
+ "5g": "5g"
1800
+ };
1801
+ const api = {
1802
+ configure,
1803
+ fetch,
1804
+ refresh,
1805
+ addEventListener,
1806
+ useNetInfo,
1807
+ useNetInfoInstance
1808
+ };
1809
+ return {
1810
+ ...api,
1811
+ NetInfoStateType,
1812
+ NetInfoCellularGeneration,
1813
+ default: api,
1814
+ /** Drive the connection state from a test. */
1815
+ _setState: (next) => {
1816
+ current = {
1817
+ ...current,
1818
+ ...next
1819
+ };
1820
+ emit();
1821
+ },
1822
+ /** Internal: restore the resting state. Called by resetAllMocks(). */
1823
+ _reset: () => {
1824
+ current = state();
1825
+ listeners.clear();
1826
+ }
1827
+ };
1828
+ }
1829
+ } }
1830
+ };
1831
+ }
1832
+ //#endregion
1670
1833
  //#region src/presets/svg.ts
1671
1834
  const SVG_COMPONENTS = [
1672
1835
  "Svg",
@@ -1830,7 +1993,6 @@ function flashList() {
1830
1993
  "FlashList",
1831
1994
  "AnimatedFlashList",
1832
1995
  "LayoutCommitObserver",
1833
- "ViewToken",
1834
1996
  "RenderTargetOptions",
1835
1997
  "useRecyclingState",
1836
1998
  "useLayoutState",
@@ -2557,7 +2719,7 @@ function worklets() {
2557
2719
  }
2558
2720
  //#endregion
2559
2721
  //#region src/presets/index.ts
2560
- var presets_exports = /* @__PURE__ */ require_chunk.__exportAll({
2722
+ var presets_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
2561
2723
  asyncStorage: () => asyncStorage,
2562
2724
  bottomSheet: () => bottomSheet,
2563
2725
  deviceInfo: () => deviceInfo,
@@ -2567,6 +2729,7 @@ var presets_exports = /* @__PURE__ */ require_chunk.__exportAll({
2567
2729
  keyboardController: () => keyboardController,
2568
2730
  mmkv: () => mmkv,
2569
2731
  navigation: () => navigation,
2732
+ netInfo: () => netInfo,
2570
2733
  reanimated: () => reanimated,
2571
2734
  safeAreaContext: () => safeAreaContext,
2572
2735
  screens: () => screens,
@@ -2696,6 +2859,12 @@ Object.defineProperty(exports, "navigation", {
2696
2859
  return navigation;
2697
2860
  }
2698
2861
  });
2862
+ Object.defineProperty(exports, "netInfo", {
2863
+ enumerable: true,
2864
+ get: function() {
2865
+ return netInfo;
2866
+ }
2867
+ });
2699
2868
  Object.defineProperty(exports, "presets_exports", {
2700
2869
  enumerable: true,
2701
2870
  get: function() {