vitest-native 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # vitest-native
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Add missing `@react-navigation/core` re-exports to navigation preset, including `useNavigationContainerRef`, `useTheme`, `ThemeProvider`, `NavigationIndependentTree`, `useNavigationBuilder`, `BaseRouter`, and 20+ other exports. Fixes tests that depend on these being available from `@react-navigation/native`.
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add Metro-compatible extensionless module resolution for node_modules. Add navigation preset mocks for @react-navigation/native-stack, @react-navigation/bottom-tabs, and @react-navigation/elements. Support custom presets.
14
+
3
15
  ## 0.1.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_presets = require("./presets-ArwboRy7.cjs");
3
- const require_preset_map = require("./preset-map-C5d8DSY7.cjs");
2
+ const require_presets = require("./presets-9Y4ssfiH.cjs");
3
+ const require_preset_map = require("./preset-map-Bt4dXkZO.cjs");
4
4
  let node_url = require("node:url");
5
5
  let node_path = require("node:path");
6
6
  node_path = require_presets.__toESM(node_path);
@@ -197,16 +197,6 @@ const RN_EXPORT_NAMES = [
197
197
  "NativeDialogManagerAndroid",
198
198
  "usePressability"
199
199
  ];
200
- /** Names of all built-in presets that can be reconstructed in the worker. */
201
- const BUILT_IN_PRESET_NAMES = new Set([
202
- "reanimated",
203
- "gestureHandler",
204
- "safeAreaContext",
205
- "navigation",
206
- "asyncStorage",
207
- "screens",
208
- "expo"
209
- ]);
210
200
  /** Check if a value (or any nested value) contains functions. */
211
201
  function containsFunctions(value, visited = /* @__PURE__ */ new WeakSet()) {
212
202
  if (typeof value === "function") return true;
@@ -224,9 +214,6 @@ function containsFunctions(value, visited = /* @__PURE__ */ new WeakSet()) {
224
214
  * React Native code in a Node/JSDOM environment.
225
215
  */
226
216
  function reactNative(options) {
227
- if (options?.presets) {
228
- for (const preset of options.presets) if (!BUILT_IN_PRESET_NAMES.has(preset.name)) throw new Error(`[vitest-native] Unknown preset "${preset.name}". Only built-in presets are supported: ${[...BUILT_IN_PRESET_NAMES].join(", ")}. For custom module mocking, use vi.mock() in a setup file.`);
229
- }
230
217
  if (options?.mocks && containsFunctions(options.mocks)) throw new Error("[vitest-native] The \"mocks\" option contains function values, which cannot be transferred to Vitest worker processes. Only JSON-serializable values (strings, numbers, booleans, plain objects, arrays) are supported.\n\nFor function-based mock overrides, use vi.mock() in a setup file:\n\n // vitest.setup.ts\n import { vi } from 'vitest';\n vi.mock('react-native', async (importOriginal) => {\n const actual = await importOriginal();\n return { ...actual, Alert: { alert: vi.fn() } };\n });");
231
218
  let resolved;
232
219
  const presetModules = /* @__PURE__ */ new Map();
@@ -272,10 +259,22 @@ function reactNative(options) {
272
259
  }
273
260
  assetPattern = new RegExp(`\\.(${resolved.assetExts.join("|")})$`);
274
261
  },
275
- resolveId(source) {
262
+ resolveId(source, importer) {
276
263
  if (source === "react-native") return "\0virtual:react-native";
277
264
  if (source.startsWith("react-native/")) return `\0virtual:rn-subpath:${source}`;
278
265
  if (presetModules.has(source)) return `\0virtual:preset:${source}`;
266
+ if (importer && importer.includes("node_modules") && source.startsWith(".") && !node_path.default.extname(source)) {
267
+ const importerDir = node_path.default.dirname(importer);
268
+ const absolute = node_path.default.resolve(importerDir, source);
269
+ for (const ext of extensions) {
270
+ const candidate = absolute + ext;
271
+ if (node_fs.default.existsSync(candidate)) return candidate;
272
+ }
273
+ for (const ext of extensions) {
274
+ const candidate = node_path.default.join(absolute, `index${ext}`);
275
+ if (node_fs.default.existsSync(candidate)) return candidate;
276
+ }
277
+ }
279
278
  },
280
279
  load(id) {
281
280
  if (id === "\0virtual:react-native") return "export default {};";
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { t as AUTO_DETECT_PRESETS } from "./preset-map-CTAjv5aa.mjs";
2
- import { t as presets_exports } from "./presets-DgEuMxfn.mjs";
1
+ import { t as AUTO_DETECT_PRESETS } from "./preset-map-D224CC5w.mjs";
2
+ import { t as presets_exports } from "./presets-CWH0gtM0.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import path from "node:path";
@@ -194,16 +194,6 @@ const RN_EXPORT_NAMES = [
194
194
  "NativeDialogManagerAndroid",
195
195
  "usePressability"
196
196
  ];
197
- /** Names of all built-in presets that can be reconstructed in the worker. */
198
- const BUILT_IN_PRESET_NAMES = new Set([
199
- "reanimated",
200
- "gestureHandler",
201
- "safeAreaContext",
202
- "navigation",
203
- "asyncStorage",
204
- "screens",
205
- "expo"
206
- ]);
207
197
  /** Check if a value (or any nested value) contains functions. */
208
198
  function containsFunctions(value, visited = /* @__PURE__ */ new WeakSet()) {
209
199
  if (typeof value === "function") return true;
@@ -221,9 +211,6 @@ function containsFunctions(value, visited = /* @__PURE__ */ new WeakSet()) {
221
211
  * React Native code in a Node/JSDOM environment.
222
212
  */
223
213
  function reactNative(options) {
224
- if (options?.presets) {
225
- for (const preset of options.presets) if (!BUILT_IN_PRESET_NAMES.has(preset.name)) throw new Error(`[vitest-native] Unknown preset "${preset.name}". Only built-in presets are supported: ${[...BUILT_IN_PRESET_NAMES].join(", ")}. For custom module mocking, use vi.mock() in a setup file.`);
226
- }
227
214
  if (options?.mocks && containsFunctions(options.mocks)) throw new Error("[vitest-native] The \"mocks\" option contains function values, which cannot be transferred to Vitest worker processes. Only JSON-serializable values (strings, numbers, booleans, plain objects, arrays) are supported.\n\nFor function-based mock overrides, use vi.mock() in a setup file:\n\n // vitest.setup.ts\n import { vi } from 'vitest';\n vi.mock('react-native', async (importOriginal) => {\n const actual = await importOriginal();\n return { ...actual, Alert: { alert: vi.fn() } };\n });");
228
215
  let resolved;
229
216
  const presetModules = /* @__PURE__ */ new Map();
@@ -269,10 +256,22 @@ function reactNative(options) {
269
256
  }
270
257
  assetPattern = new RegExp(`\\.(${resolved.assetExts.join("|")})$`);
271
258
  },
272
- resolveId(source) {
259
+ resolveId(source, importer) {
273
260
  if (source === "react-native") return "\0virtual:react-native";
274
261
  if (source.startsWith("react-native/")) return `\0virtual:rn-subpath:${source}`;
275
262
  if (presetModules.has(source)) return `\0virtual:preset:${source}`;
263
+ if (importer && importer.includes("node_modules") && source.startsWith(".") && !path.extname(source)) {
264
+ const importerDir = path.dirname(importer);
265
+ const absolute = path.resolve(importerDir, source);
266
+ for (const ext of extensions) {
267
+ const candidate = absolute + ext;
268
+ if (fs.existsSync(candidate)) return candidate;
269
+ }
270
+ for (const ext of extensions) {
271
+ const candidate = path.join(absolute, `index${ext}`);
272
+ if (fs.existsSync(candidate)) return candidate;
273
+ }
274
+ }
276
275
  },
277
276
  load(id) {
278
277
  if (id === "\0virtual:react-native") return "export default {};";
@@ -8,6 +8,9 @@ const AUTO_DETECT_PRESETS = {
8
8
  "react-native-gesture-handler": "gestureHandler",
9
9
  "react-native-safe-area-context": "safeAreaContext",
10
10
  "@react-navigation/native": "navigation",
11
+ "@react-navigation/native-stack": "navigation",
12
+ "@react-navigation/bottom-tabs": "navigation",
13
+ "@react-navigation/elements": "navigation",
11
14
  "@react-native-async-storage/async-storage": "asyncStorage",
12
15
  "react-native-screens": "screens",
13
16
  "expo-constants": "expo"
@@ -8,6 +8,9 @@ const AUTO_DETECT_PRESETS = {
8
8
  "react-native-gesture-handler": "gestureHandler",
9
9
  "react-native-safe-area-context": "safeAreaContext",
10
10
  "@react-navigation/native": "navigation",
11
+ "@react-navigation/native-stack": "navigation",
12
+ "@react-navigation/bottom-tabs": "navigation",
13
+ "@react-navigation/elements": "navigation",
11
14
  "@react-native-async-storage/async-storage": "asyncStorage",
12
15
  "react-native-screens": "screens",
13
16
  "expo-constants": "expo"
@@ -467,138 +467,350 @@ function safeAreaContext() {
467
467
  function navigation() {
468
468
  return {
469
469
  name: "navigation",
470
- modules: { "@react-navigation/native": {
471
- exports: [
472
- "NavigationContainer",
473
- "useNavigation",
474
- "useRoute",
475
- "useFocusEffect",
476
- "useIsFocused",
477
- "useNavigationState",
478
- "createNavigationContainerRef",
479
- "NavigationContext",
480
- "NavigationRouteContext",
481
- "CommonActions",
482
- "StackActions",
483
- "TabActions",
484
- "DrawerActions",
485
- "useLinkTo",
486
- "Link"
487
- ],
488
- factory: () => {
489
- const NavigationContainer = react.default.forwardRef((props, ref) => react.default.createElement("NavigationContainer", {
490
- ...props,
491
- ref
492
- }, props.children));
493
- NavigationContainer.displayName = "NavigationContainer";
494
- const navigate = vitest.vi.fn();
495
- const goBack = vitest.vi.fn();
496
- const reset = vitest.vi.fn();
497
- const setParams = vitest.vi.fn();
498
- const setOptions = vitest.vi.fn();
499
- const dispatch = vitest.vi.fn();
500
- const canGoBack = vitest.vi.fn(() => false);
501
- const getParent = vitest.vi.fn(() => void 0);
502
- const getState = vitest.vi.fn(() => ({
503
- index: 0,
504
- key: "root",
505
- routeNames: [],
506
- routes: [],
507
- type: "stack",
508
- stale: false
509
- }));
510
- function useNavigation() {
470
+ modules: {
471
+ "@react-navigation/native": {
472
+ exports: [
473
+ "NavigationContainer",
474
+ "useLinkTo",
475
+ "Link",
476
+ "useNavigation",
477
+ "useRoute",
478
+ "useFocusEffect",
479
+ "useIsFocused",
480
+ "useNavigationState",
481
+ "useNavigationContainerRef",
482
+ "createNavigationContainerRef",
483
+ "createNavigatorFactory",
484
+ "useNavigationBuilder",
485
+ "NavigationContext",
486
+ "NavigationRouteContext",
487
+ "NavigationContainerRefContext",
488
+ "NavigationHelpersContext",
489
+ "CurrentRenderContext",
490
+ "ThemeContext",
491
+ "ThemeProvider",
492
+ "useTheme",
493
+ "NavigationIndependentTree",
494
+ "useNavigationIndependentTree",
495
+ "PreventRemoveContext",
496
+ "PreventRemoveProvider",
497
+ "usePreventRemove",
498
+ "usePreventRemoveContext",
499
+ "CommonActions",
500
+ "StackActions",
501
+ "TabActions",
502
+ "DrawerActions",
503
+ "findFocusedRoute",
504
+ "getFocusedRouteNameFromRoute",
505
+ "getActionFromState",
506
+ "getPathFromState",
507
+ "getStateFromPath",
508
+ "useStateForPath",
509
+ "validatePathConfig",
510
+ "BaseNavigationContainer",
511
+ "createComponentForStaticNavigation",
512
+ "createPathConfigForStaticNavigation",
513
+ "BaseRouter"
514
+ ],
515
+ factory: () => {
516
+ const NavigationContainer = react.default.forwardRef((props, ref) => react.default.createElement("NavigationContainer", {
517
+ ...props,
518
+ ref
519
+ }, props.children));
520
+ NavigationContainer.displayName = "NavigationContainer";
521
+ const navigate = vitest.vi.fn();
522
+ const goBack = vitest.vi.fn();
523
+ const reset = vitest.vi.fn();
524
+ const setParams = vitest.vi.fn();
525
+ const setOptions = vitest.vi.fn();
526
+ const dispatch = vitest.vi.fn();
527
+ const canGoBack = vitest.vi.fn(() => false);
528
+ const getParent = vitest.vi.fn(() => void 0);
529
+ const getState = vitest.vi.fn(() => ({
530
+ index: 0,
531
+ key: "root",
532
+ routeNames: [],
533
+ routes: [],
534
+ type: "stack",
535
+ stale: false
536
+ }));
537
+ function useNavigation() {
538
+ return {
539
+ navigate,
540
+ goBack,
541
+ reset,
542
+ setParams,
543
+ setOptions,
544
+ dispatch,
545
+ canGoBack,
546
+ getParent,
547
+ getState,
548
+ isFocused: vitest.vi.fn(() => true),
549
+ addListener: vitest.vi.fn(() => vitest.vi.fn()),
550
+ removeListener: vitest.vi.fn(),
551
+ getId: vitest.vi.fn(() => void 0)
552
+ };
553
+ }
554
+ function useRoute() {
555
+ return {
556
+ key: "test-route-key",
557
+ name: "TestScreen",
558
+ params: {}
559
+ };
560
+ }
561
+ function useFocusEffect(callback) {
562
+ react.default.useEffect(callback, []);
563
+ }
564
+ function useIsFocused() {
565
+ return true;
566
+ }
567
+ function useNavigationState(selector) {
568
+ return selector(getState());
569
+ }
570
+ function createNavigationContainerRef() {
571
+ return {
572
+ current: null,
573
+ isReady: vitest.vi.fn(() => true),
574
+ navigate,
575
+ goBack,
576
+ reset,
577
+ dispatch,
578
+ canGoBack,
579
+ getState,
580
+ getRootState: getState,
581
+ getCurrentRoute: vitest.vi.fn(() => ({
582
+ key: "test",
583
+ name: "TestScreen"
584
+ })),
585
+ getCurrentOptions: vitest.vi.fn(() => ({})),
586
+ addListener: vitest.vi.fn(() => vitest.vi.fn())
587
+ };
588
+ }
589
+ function useNavigationContainerRef() {
590
+ return createNavigationContainerRef();
591
+ }
592
+ const NavigationContext = react.default.createContext(null);
593
+ const NavigationRouteContext = react.default.createContext(null);
594
+ const NavigationContainerRefContext = react.default.createContext(null);
595
+ const NavigationHelpersContext = react.default.createContext(null);
596
+ const CurrentRenderContext = react.default.createContext(void 0);
597
+ const ThemeContext = react.default.createContext({
598
+ dark: false,
599
+ colors: {}
600
+ });
601
+ const PreventRemoveContext = react.default.createContext(null);
602
+ const defaultTheme = {
603
+ dark: false,
604
+ colors: {
605
+ primary: "rgb(0, 122, 255)",
606
+ background: "rgb(242, 242, 242)",
607
+ card: "rgb(255, 255, 255)",
608
+ text: "rgb(28, 28, 30)",
609
+ border: "rgb(216, 216, 216)",
610
+ notification: "rgb(255, 59, 48)"
611
+ }
612
+ };
613
+ function ThemeProvider({ value, children }) {
614
+ return react.default.createElement(ThemeContext.Provider, { value: value ?? defaultTheme }, children);
615
+ }
616
+ function useTheme() {
617
+ return defaultTheme;
618
+ }
619
+ function NavigationIndependentTree({ children }) {
620
+ return children;
621
+ }
622
+ function useNavigationIndependentTree() {
623
+ return true;
624
+ }
625
+ function PreventRemoveProvider({ children }) {
626
+ return children;
627
+ }
628
+ const BaseNavigationContainer = react.default.forwardRef((props, ref) => react.default.createElement("BaseNavigationContainer", {
629
+ ...props,
630
+ ref
631
+ }, props.children));
632
+ BaseNavigationContainer.displayName = "BaseNavigationContainer";
511
633
  return {
512
- navigate,
513
- goBack,
514
- reset,
515
- setParams,
516
- setOptions,
517
- dispatch,
518
- canGoBack,
519
- getParent,
520
- getState,
521
- isFocused: vitest.vi.fn(() => true),
522
- addListener: vitest.vi.fn(() => vitest.vi.fn()),
523
- removeListener: vitest.vi.fn(),
524
- getId: vitest.vi.fn(() => void 0)
634
+ default: { NavigationContainer },
635
+ NavigationContainer,
636
+ useNavigation,
637
+ useRoute,
638
+ useFocusEffect,
639
+ useIsFocused,
640
+ useNavigationState,
641
+ useNavigationContainerRef,
642
+ createNavigationContainerRef,
643
+ createNavigatorFactory: vitest.vi.fn(() => vitest.vi.fn()),
644
+ useNavigationBuilder: vitest.vi.fn(() => ({
645
+ state: getState(),
646
+ navigation: useNavigation(),
647
+ descriptors: {},
648
+ NavigationContent: ({ children }) => children
649
+ })),
650
+ NavigationContext,
651
+ NavigationRouteContext,
652
+ NavigationContainerRefContext,
653
+ NavigationHelpersContext,
654
+ CurrentRenderContext,
655
+ ThemeContext,
656
+ ThemeProvider,
657
+ useTheme,
658
+ NavigationIndependentTree,
659
+ useNavigationIndependentTree,
660
+ PreventRemoveContext,
661
+ PreventRemoveProvider,
662
+ usePreventRemove: vitest.vi.fn(),
663
+ usePreventRemoveContext: vitest.vi.fn(() => null),
664
+ CommonActions: {
665
+ navigate: vitest.vi.fn(),
666
+ reset: vitest.vi.fn(),
667
+ goBack: vitest.vi.fn(),
668
+ setParams: vitest.vi.fn()
669
+ },
670
+ StackActions: {
671
+ push: vitest.vi.fn(),
672
+ pop: vitest.vi.fn(),
673
+ popToTop: vitest.vi.fn(),
674
+ replace: vitest.vi.fn()
675
+ },
676
+ TabActions: { jumpTo: vitest.vi.fn() },
677
+ DrawerActions: {
678
+ openDrawer: vitest.vi.fn(),
679
+ closeDrawer: vitest.vi.fn(),
680
+ toggleDrawer: vitest.vi.fn(),
681
+ jumpTo: vitest.vi.fn()
682
+ },
683
+ findFocusedRoute: vitest.vi.fn((state) => state?.routes?.[state?.index ?? 0]),
684
+ getFocusedRouteNameFromRoute: vitest.vi.fn((route) => route?.state?.routes?.[route?.state?.index ?? 0]?.name),
685
+ getActionFromState: vitest.vi.fn(() => void 0),
686
+ getPathFromState: vitest.vi.fn(() => "/"),
687
+ getStateFromPath: vitest.vi.fn(() => void 0),
688
+ useStateForPath: vitest.vi.fn(() => void 0),
689
+ validatePathConfig: vitest.vi.fn(),
690
+ BaseNavigationContainer,
691
+ createComponentForStaticNavigation: vitest.vi.fn(() => () => null),
692
+ createPathConfigForStaticNavigation: vitest.vi.fn(() => ({})),
693
+ BaseRouter: {
694
+ getInitialState: vitest.vi.fn(() => getState()),
695
+ getRehydratedState: vitest.vi.fn((state) => state),
696
+ getStateForRouteNamesChange: vitest.vi.fn((state) => state),
697
+ getStateForRouteFocus: vitest.vi.fn((state) => state),
698
+ getStateForAction: vitest.vi.fn((state) => state),
699
+ shouldActionChangeFocus: vitest.vi.fn(() => false)
700
+ },
701
+ useLinkTo: vitest.vi.fn(() => vitest.vi.fn()),
702
+ Link: react.default.forwardRef((props, ref) => react.default.createElement("Link", {
703
+ ...props,
704
+ ref
705
+ }, props.children))
525
706
  };
526
707
  }
527
- function useRoute() {
708
+ },
709
+ "@react-navigation/native-stack": {
710
+ exports: ["createNativeStackNavigator"],
711
+ factory: () => {
712
+ function createNativeStackNavigator() {
713
+ return {
714
+ Navigator: react.default.forwardRef((props, ref) => react.default.createElement("NativeStackNavigator", {
715
+ ...props,
716
+ ref
717
+ }, props.children)),
718
+ Screen: react.default.forwardRef((props, ref) => react.default.createElement("Screen", {
719
+ ...props,
720
+ ref
721
+ }, props.children)),
722
+ Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
723
+ ...props,
724
+ ref
725
+ }, props.children))
726
+ };
727
+ }
528
728
  return {
529
- key: "test-route-key",
530
- name: "TestScreen",
531
- params: {}
729
+ default: { createNativeStackNavigator },
730
+ createNativeStackNavigator
532
731
  };
533
732
  }
534
- function useFocusEffect(callback) {
535
- react.default.useEffect(callback, []);
536
- }
537
- function useIsFocused() {
538
- return true;
539
- }
540
- function useNavigationState(selector) {
541
- return selector(getState());
542
- }
543
- function createNavigationContainerRef() {
733
+ },
734
+ "@react-navigation/bottom-tabs": {
735
+ exports: ["createBottomTabNavigator"],
736
+ factory: () => {
737
+ function createBottomTabNavigator() {
738
+ return {
739
+ Navigator: react.default.forwardRef((props, ref) => react.default.createElement("BottomTabNavigator", {
740
+ ...props,
741
+ ref
742
+ }, props.children)),
743
+ Screen: react.default.forwardRef((props, ref) => react.default.createElement("Screen", {
744
+ ...props,
745
+ ref
746
+ }, props.children)),
747
+ Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
748
+ ...props,
749
+ ref
750
+ }, props.children))
751
+ };
752
+ }
544
753
  return {
545
- current: null,
546
- isReady: vitest.vi.fn(() => true),
547
- navigate,
548
- goBack,
549
- reset,
550
- dispatch,
551
- canGoBack,
552
- getState,
553
- getRootState: getState,
554
- getCurrentRoute: vitest.vi.fn(() => ({
555
- key: "test",
556
- name: "TestScreen"
557
- })),
558
- getCurrentOptions: vitest.vi.fn(() => ({})),
559
- addListener: vitest.vi.fn(() => vitest.vi.fn())
754
+ default: { createBottomTabNavigator },
755
+ createBottomTabNavigator
560
756
  };
561
757
  }
562
- const NavigationContext = react.default.createContext(null);
563
- const NavigationRouteContext = react.default.createContext(null);
564
- return {
565
- default: { NavigationContainer },
566
- NavigationContainer,
567
- useNavigation,
568
- useRoute,
569
- useFocusEffect,
570
- useIsFocused,
571
- useNavigationState,
572
- createNavigationContainerRef,
573
- NavigationContext,
574
- NavigationRouteContext,
575
- CommonActions: {
576
- navigate: vitest.vi.fn(),
577
- reset: vitest.vi.fn(),
578
- goBack: vitest.vi.fn(),
579
- setParams: vitest.vi.fn()
580
- },
581
- StackActions: {
582
- push: vitest.vi.fn(),
583
- pop: vitest.vi.fn(),
584
- popToTop: vitest.vi.fn(),
585
- replace: vitest.vi.fn()
586
- },
587
- TabActions: { jumpTo: vitest.vi.fn() },
588
- DrawerActions: {
589
- openDrawer: vitest.vi.fn(),
590
- closeDrawer: vitest.vi.fn(),
591
- toggleDrawer: vitest.vi.fn(),
592
- jumpTo: vitest.vi.fn()
593
- },
594
- useLinkTo: vitest.vi.fn(() => vitest.vi.fn()),
595
- Link: react.default.forwardRef((props, ref) => react.default.createElement("Link", {
758
+ },
759
+ "@react-navigation/elements": {
760
+ exports: [
761
+ "Header",
762
+ "HeaderBackground",
763
+ "HeaderBackButton",
764
+ "HeaderTitle",
765
+ "HeaderBackContext",
766
+ "HeaderShownContext",
767
+ "HeaderHeightContext",
768
+ "useHeaderHeight",
769
+ "getDefaultHeaderHeight",
770
+ "getHeaderTitle"
771
+ ],
772
+ factory: () => {
773
+ const Header = react.default.forwardRef((props, ref) => react.default.createElement("Header", {
596
774
  ...props,
597
775
  ref
598
- }, props.children))
599
- };
776
+ }, props.children));
777
+ Header.displayName = "Header";
778
+ const HeaderBackground = react.default.forwardRef((props, ref) => react.default.createElement("HeaderBackground", {
779
+ ...props,
780
+ ref
781
+ }, props.children));
782
+ HeaderBackground.displayName = "HeaderBackground";
783
+ const HeaderBackButton = react.default.forwardRef((props, ref) => react.default.createElement("HeaderBackButton", {
784
+ ...props,
785
+ ref
786
+ }));
787
+ HeaderBackButton.displayName = "HeaderBackButton";
788
+ const HeaderTitle = react.default.forwardRef((props, ref) => react.default.createElement("HeaderTitle", {
789
+ ...props,
790
+ ref
791
+ }, props.children));
792
+ HeaderTitle.displayName = "HeaderTitle";
793
+ return {
794
+ default: {
795
+ Header,
796
+ HeaderBackground,
797
+ HeaderBackButton,
798
+ HeaderTitle
799
+ },
800
+ Header,
801
+ HeaderBackground,
802
+ HeaderBackButton,
803
+ HeaderTitle,
804
+ HeaderBackContext: react.default.createContext(void 0),
805
+ HeaderShownContext: react.default.createContext(true),
806
+ HeaderHeightContext: react.default.createContext(64),
807
+ useHeaderHeight: () => 64,
808
+ getDefaultHeaderHeight: vitest.vi.fn(() => 64),
809
+ getHeaderTitle: vitest.vi.fn((options, fallback) => options?.headerTitle ?? options?.title ?? fallback)
810
+ };
811
+ }
600
812
  }
601
- } }
813
+ }
602
814
  };
603
815
  }
604
816
  //#endregion
@@ -436,138 +436,350 @@ function safeAreaContext() {
436
436
  function navigation() {
437
437
  return {
438
438
  name: "navigation",
439
- modules: { "@react-navigation/native": {
440
- exports: [
441
- "NavigationContainer",
442
- "useNavigation",
443
- "useRoute",
444
- "useFocusEffect",
445
- "useIsFocused",
446
- "useNavigationState",
447
- "createNavigationContainerRef",
448
- "NavigationContext",
449
- "NavigationRouteContext",
450
- "CommonActions",
451
- "StackActions",
452
- "TabActions",
453
- "DrawerActions",
454
- "useLinkTo",
455
- "Link"
456
- ],
457
- factory: () => {
458
- const NavigationContainer = React.forwardRef((props, ref) => React.createElement("NavigationContainer", {
459
- ...props,
460
- ref
461
- }, props.children));
462
- NavigationContainer.displayName = "NavigationContainer";
463
- const navigate = vi.fn();
464
- const goBack = vi.fn();
465
- const reset = vi.fn();
466
- const setParams = vi.fn();
467
- const setOptions = vi.fn();
468
- const dispatch = vi.fn();
469
- const canGoBack = vi.fn(() => false);
470
- const getParent = vi.fn(() => void 0);
471
- const getState = vi.fn(() => ({
472
- index: 0,
473
- key: "root",
474
- routeNames: [],
475
- routes: [],
476
- type: "stack",
477
- stale: false
478
- }));
479
- function useNavigation() {
439
+ modules: {
440
+ "@react-navigation/native": {
441
+ exports: [
442
+ "NavigationContainer",
443
+ "useLinkTo",
444
+ "Link",
445
+ "useNavigation",
446
+ "useRoute",
447
+ "useFocusEffect",
448
+ "useIsFocused",
449
+ "useNavigationState",
450
+ "useNavigationContainerRef",
451
+ "createNavigationContainerRef",
452
+ "createNavigatorFactory",
453
+ "useNavigationBuilder",
454
+ "NavigationContext",
455
+ "NavigationRouteContext",
456
+ "NavigationContainerRefContext",
457
+ "NavigationHelpersContext",
458
+ "CurrentRenderContext",
459
+ "ThemeContext",
460
+ "ThemeProvider",
461
+ "useTheme",
462
+ "NavigationIndependentTree",
463
+ "useNavigationIndependentTree",
464
+ "PreventRemoveContext",
465
+ "PreventRemoveProvider",
466
+ "usePreventRemove",
467
+ "usePreventRemoveContext",
468
+ "CommonActions",
469
+ "StackActions",
470
+ "TabActions",
471
+ "DrawerActions",
472
+ "findFocusedRoute",
473
+ "getFocusedRouteNameFromRoute",
474
+ "getActionFromState",
475
+ "getPathFromState",
476
+ "getStateFromPath",
477
+ "useStateForPath",
478
+ "validatePathConfig",
479
+ "BaseNavigationContainer",
480
+ "createComponentForStaticNavigation",
481
+ "createPathConfigForStaticNavigation",
482
+ "BaseRouter"
483
+ ],
484
+ factory: () => {
485
+ const NavigationContainer = React.forwardRef((props, ref) => React.createElement("NavigationContainer", {
486
+ ...props,
487
+ ref
488
+ }, props.children));
489
+ NavigationContainer.displayName = "NavigationContainer";
490
+ const navigate = vi.fn();
491
+ const goBack = vi.fn();
492
+ const reset = vi.fn();
493
+ const setParams = vi.fn();
494
+ const setOptions = vi.fn();
495
+ const dispatch = vi.fn();
496
+ const canGoBack = vi.fn(() => false);
497
+ const getParent = vi.fn(() => void 0);
498
+ const getState = vi.fn(() => ({
499
+ index: 0,
500
+ key: "root",
501
+ routeNames: [],
502
+ routes: [],
503
+ type: "stack",
504
+ stale: false
505
+ }));
506
+ function useNavigation() {
507
+ return {
508
+ navigate,
509
+ goBack,
510
+ reset,
511
+ setParams,
512
+ setOptions,
513
+ dispatch,
514
+ canGoBack,
515
+ getParent,
516
+ getState,
517
+ isFocused: vi.fn(() => true),
518
+ addListener: vi.fn(() => vi.fn()),
519
+ removeListener: vi.fn(),
520
+ getId: vi.fn(() => void 0)
521
+ };
522
+ }
523
+ function useRoute() {
524
+ return {
525
+ key: "test-route-key",
526
+ name: "TestScreen",
527
+ params: {}
528
+ };
529
+ }
530
+ function useFocusEffect(callback) {
531
+ React.useEffect(callback, []);
532
+ }
533
+ function useIsFocused() {
534
+ return true;
535
+ }
536
+ function useNavigationState(selector) {
537
+ return selector(getState());
538
+ }
539
+ function createNavigationContainerRef() {
540
+ return {
541
+ current: null,
542
+ isReady: vi.fn(() => true),
543
+ navigate,
544
+ goBack,
545
+ reset,
546
+ dispatch,
547
+ canGoBack,
548
+ getState,
549
+ getRootState: getState,
550
+ getCurrentRoute: vi.fn(() => ({
551
+ key: "test",
552
+ name: "TestScreen"
553
+ })),
554
+ getCurrentOptions: vi.fn(() => ({})),
555
+ addListener: vi.fn(() => vi.fn())
556
+ };
557
+ }
558
+ function useNavigationContainerRef() {
559
+ return createNavigationContainerRef();
560
+ }
561
+ const NavigationContext = React.createContext(null);
562
+ const NavigationRouteContext = React.createContext(null);
563
+ const NavigationContainerRefContext = React.createContext(null);
564
+ const NavigationHelpersContext = React.createContext(null);
565
+ const CurrentRenderContext = React.createContext(void 0);
566
+ const ThemeContext = React.createContext({
567
+ dark: false,
568
+ colors: {}
569
+ });
570
+ const PreventRemoveContext = React.createContext(null);
571
+ const defaultTheme = {
572
+ dark: false,
573
+ colors: {
574
+ primary: "rgb(0, 122, 255)",
575
+ background: "rgb(242, 242, 242)",
576
+ card: "rgb(255, 255, 255)",
577
+ text: "rgb(28, 28, 30)",
578
+ border: "rgb(216, 216, 216)",
579
+ notification: "rgb(255, 59, 48)"
580
+ }
581
+ };
582
+ function ThemeProvider({ value, children }) {
583
+ return React.createElement(ThemeContext.Provider, { value: value ?? defaultTheme }, children);
584
+ }
585
+ function useTheme() {
586
+ return defaultTheme;
587
+ }
588
+ function NavigationIndependentTree({ children }) {
589
+ return children;
590
+ }
591
+ function useNavigationIndependentTree() {
592
+ return true;
593
+ }
594
+ function PreventRemoveProvider({ children }) {
595
+ return children;
596
+ }
597
+ const BaseNavigationContainer = React.forwardRef((props, ref) => React.createElement("BaseNavigationContainer", {
598
+ ...props,
599
+ ref
600
+ }, props.children));
601
+ BaseNavigationContainer.displayName = "BaseNavigationContainer";
480
602
  return {
481
- navigate,
482
- goBack,
483
- reset,
484
- setParams,
485
- setOptions,
486
- dispatch,
487
- canGoBack,
488
- getParent,
489
- getState,
490
- isFocused: vi.fn(() => true),
491
- addListener: vi.fn(() => vi.fn()),
492
- removeListener: vi.fn(),
493
- getId: vi.fn(() => void 0)
603
+ default: { NavigationContainer },
604
+ NavigationContainer,
605
+ useNavigation,
606
+ useRoute,
607
+ useFocusEffect,
608
+ useIsFocused,
609
+ useNavigationState,
610
+ useNavigationContainerRef,
611
+ createNavigationContainerRef,
612
+ createNavigatorFactory: vi.fn(() => vi.fn()),
613
+ useNavigationBuilder: vi.fn(() => ({
614
+ state: getState(),
615
+ navigation: useNavigation(),
616
+ descriptors: {},
617
+ NavigationContent: ({ children }) => children
618
+ })),
619
+ NavigationContext,
620
+ NavigationRouteContext,
621
+ NavigationContainerRefContext,
622
+ NavigationHelpersContext,
623
+ CurrentRenderContext,
624
+ ThemeContext,
625
+ ThemeProvider,
626
+ useTheme,
627
+ NavigationIndependentTree,
628
+ useNavigationIndependentTree,
629
+ PreventRemoveContext,
630
+ PreventRemoveProvider,
631
+ usePreventRemove: vi.fn(),
632
+ usePreventRemoveContext: vi.fn(() => null),
633
+ CommonActions: {
634
+ navigate: vi.fn(),
635
+ reset: vi.fn(),
636
+ goBack: vi.fn(),
637
+ setParams: vi.fn()
638
+ },
639
+ StackActions: {
640
+ push: vi.fn(),
641
+ pop: vi.fn(),
642
+ popToTop: vi.fn(),
643
+ replace: vi.fn()
644
+ },
645
+ TabActions: { jumpTo: vi.fn() },
646
+ DrawerActions: {
647
+ openDrawer: vi.fn(),
648
+ closeDrawer: vi.fn(),
649
+ toggleDrawer: vi.fn(),
650
+ jumpTo: vi.fn()
651
+ },
652
+ findFocusedRoute: vi.fn((state) => state?.routes?.[state?.index ?? 0]),
653
+ getFocusedRouteNameFromRoute: vi.fn((route) => route?.state?.routes?.[route?.state?.index ?? 0]?.name),
654
+ getActionFromState: vi.fn(() => void 0),
655
+ getPathFromState: vi.fn(() => "/"),
656
+ getStateFromPath: vi.fn(() => void 0),
657
+ useStateForPath: vi.fn(() => void 0),
658
+ validatePathConfig: vi.fn(),
659
+ BaseNavigationContainer,
660
+ createComponentForStaticNavigation: vi.fn(() => () => null),
661
+ createPathConfigForStaticNavigation: vi.fn(() => ({})),
662
+ BaseRouter: {
663
+ getInitialState: vi.fn(() => getState()),
664
+ getRehydratedState: vi.fn((state) => state),
665
+ getStateForRouteNamesChange: vi.fn((state) => state),
666
+ getStateForRouteFocus: vi.fn((state) => state),
667
+ getStateForAction: vi.fn((state) => state),
668
+ shouldActionChangeFocus: vi.fn(() => false)
669
+ },
670
+ useLinkTo: vi.fn(() => vi.fn()),
671
+ Link: React.forwardRef((props, ref) => React.createElement("Link", {
672
+ ...props,
673
+ ref
674
+ }, props.children))
494
675
  };
495
676
  }
496
- function useRoute() {
677
+ },
678
+ "@react-navigation/native-stack": {
679
+ exports: ["createNativeStackNavigator"],
680
+ factory: () => {
681
+ function createNativeStackNavigator() {
682
+ return {
683
+ Navigator: React.forwardRef((props, ref) => React.createElement("NativeStackNavigator", {
684
+ ...props,
685
+ ref
686
+ }, props.children)),
687
+ Screen: React.forwardRef((props, ref) => React.createElement("Screen", {
688
+ ...props,
689
+ ref
690
+ }, props.children)),
691
+ Group: React.forwardRef((props, ref) => React.createElement("Group", {
692
+ ...props,
693
+ ref
694
+ }, props.children))
695
+ };
696
+ }
497
697
  return {
498
- key: "test-route-key",
499
- name: "TestScreen",
500
- params: {}
698
+ default: { createNativeStackNavigator },
699
+ createNativeStackNavigator
501
700
  };
502
701
  }
503
- function useFocusEffect(callback) {
504
- React.useEffect(callback, []);
505
- }
506
- function useIsFocused() {
507
- return true;
508
- }
509
- function useNavigationState(selector) {
510
- return selector(getState());
511
- }
512
- function createNavigationContainerRef() {
702
+ },
703
+ "@react-navigation/bottom-tabs": {
704
+ exports: ["createBottomTabNavigator"],
705
+ factory: () => {
706
+ function createBottomTabNavigator() {
707
+ return {
708
+ Navigator: React.forwardRef((props, ref) => React.createElement("BottomTabNavigator", {
709
+ ...props,
710
+ ref
711
+ }, props.children)),
712
+ Screen: React.forwardRef((props, ref) => React.createElement("Screen", {
713
+ ...props,
714
+ ref
715
+ }, props.children)),
716
+ Group: React.forwardRef((props, ref) => React.createElement("Group", {
717
+ ...props,
718
+ ref
719
+ }, props.children))
720
+ };
721
+ }
513
722
  return {
514
- current: null,
515
- isReady: vi.fn(() => true),
516
- navigate,
517
- goBack,
518
- reset,
519
- dispatch,
520
- canGoBack,
521
- getState,
522
- getRootState: getState,
523
- getCurrentRoute: vi.fn(() => ({
524
- key: "test",
525
- name: "TestScreen"
526
- })),
527
- getCurrentOptions: vi.fn(() => ({})),
528
- addListener: vi.fn(() => vi.fn())
723
+ default: { createBottomTabNavigator },
724
+ createBottomTabNavigator
529
725
  };
530
726
  }
531
- const NavigationContext = React.createContext(null);
532
- const NavigationRouteContext = React.createContext(null);
533
- return {
534
- default: { NavigationContainer },
535
- NavigationContainer,
536
- useNavigation,
537
- useRoute,
538
- useFocusEffect,
539
- useIsFocused,
540
- useNavigationState,
541
- createNavigationContainerRef,
542
- NavigationContext,
543
- NavigationRouteContext,
544
- CommonActions: {
545
- navigate: vi.fn(),
546
- reset: vi.fn(),
547
- goBack: vi.fn(),
548
- setParams: vi.fn()
549
- },
550
- StackActions: {
551
- push: vi.fn(),
552
- pop: vi.fn(),
553
- popToTop: vi.fn(),
554
- replace: vi.fn()
555
- },
556
- TabActions: { jumpTo: vi.fn() },
557
- DrawerActions: {
558
- openDrawer: vi.fn(),
559
- closeDrawer: vi.fn(),
560
- toggleDrawer: vi.fn(),
561
- jumpTo: vi.fn()
562
- },
563
- useLinkTo: vi.fn(() => vi.fn()),
564
- Link: React.forwardRef((props, ref) => React.createElement("Link", {
727
+ },
728
+ "@react-navigation/elements": {
729
+ exports: [
730
+ "Header",
731
+ "HeaderBackground",
732
+ "HeaderBackButton",
733
+ "HeaderTitle",
734
+ "HeaderBackContext",
735
+ "HeaderShownContext",
736
+ "HeaderHeightContext",
737
+ "useHeaderHeight",
738
+ "getDefaultHeaderHeight",
739
+ "getHeaderTitle"
740
+ ],
741
+ factory: () => {
742
+ const Header = React.forwardRef((props, ref) => React.createElement("Header", {
565
743
  ...props,
566
744
  ref
567
- }, props.children))
568
- };
745
+ }, props.children));
746
+ Header.displayName = "Header";
747
+ const HeaderBackground = React.forwardRef((props, ref) => React.createElement("HeaderBackground", {
748
+ ...props,
749
+ ref
750
+ }, props.children));
751
+ HeaderBackground.displayName = "HeaderBackground";
752
+ const HeaderBackButton = React.forwardRef((props, ref) => React.createElement("HeaderBackButton", {
753
+ ...props,
754
+ ref
755
+ }));
756
+ HeaderBackButton.displayName = "HeaderBackButton";
757
+ const HeaderTitle = React.forwardRef((props, ref) => React.createElement("HeaderTitle", {
758
+ ...props,
759
+ ref
760
+ }, props.children));
761
+ HeaderTitle.displayName = "HeaderTitle";
762
+ return {
763
+ default: {
764
+ Header,
765
+ HeaderBackground,
766
+ HeaderBackButton,
767
+ HeaderTitle
768
+ },
769
+ Header,
770
+ HeaderBackground,
771
+ HeaderBackButton,
772
+ HeaderTitle,
773
+ HeaderBackContext: React.createContext(void 0),
774
+ HeaderShownContext: React.createContext(true),
775
+ HeaderHeightContext: React.createContext(64),
776
+ useHeaderHeight: () => 64,
777
+ getDefaultHeaderHeight: vi.fn(() => 64),
778
+ getHeaderTitle: vi.fn((options, fallback) => options?.headerTitle ?? options?.title ?? fallback)
779
+ };
780
+ }
569
781
  }
570
- } }
782
+ }
571
783
  };
572
784
  }
573
785
  //#endregion
package/dist/presets.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_presets = require("./presets-ArwboRy7.cjs");
2
+ const require_presets = require("./presets-9Y4ssfiH.cjs");
3
3
  exports.asyncStorage = require_presets.asyncStorage;
4
4
  exports.expo = require_presets.expo;
5
5
  exports.gestureHandler = require_presets.gestureHandler;
package/dist/presets.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as navigation, c as reanimated, i as asyncStorage, n as expo, o as safeAreaContext, r as screens, s as gestureHandler } from "./presets-DgEuMxfn.mjs";
1
+ import { a as navigation, c as reanimated, i as asyncStorage, n as expo, o as safeAreaContext, r as screens, s as gestureHandler } from "./presets-CWH0gtM0.mjs";
2
2
  export { asyncStorage, expo, gestureHandler, navigation, reanimated, safeAreaContext, screens };
package/dist/setup.cjs CHANGED
@@ -1,5 +1,5 @@
1
- const require_presets = require("./presets-ArwboRy7.cjs");
2
- const require_preset_map = require("./preset-map-C5d8DSY7.cjs");
1
+ const require_presets = require("./presets-9Y4ssfiH.cjs");
2
+ const require_preset_map = require("./preset-map-Bt4dXkZO.cjs");
3
3
  const require_serializer = require("./serializer.cjs");
4
4
  let node_path = require("node:path");
5
5
  node_path = require_presets.__toESM(node_path);
package/dist/setup.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as __require } from "./chunk-CjcI7cDX.mjs";
2
- import { t as AUTO_DETECT_PRESETS } from "./preset-map-CTAjv5aa.mjs";
3
- import { t as presets_exports } from "./presets-DgEuMxfn.mjs";
2
+ import { t as AUTO_DETECT_PRESETS } from "./preset-map-D224CC5w.mjs";
3
+ import { t as presets_exports } from "./presets-CWH0gtM0.mjs";
4
4
  import { serializer } from "./serializer.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import path from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-native",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "A Vitest plugin for React Native. One install, zero config.",
6
6
  "license": "MIT",