vitest-native 0.13.0 → 0.14.0-rc.2

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 (77) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/README.md +138 -48
  3. package/dist/cli.cjs +70 -5
  4. package/dist/cli.d.cts +2 -3
  5. package/dist/cli.d.mts +2 -3
  6. package/dist/cli.mjs +70 -5
  7. package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
  8. package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
  9. package/dist/errors.d.mts +12 -0
  10. package/dist/helpers.cjs +6 -3
  11. package/dist/helpers.d.cts +8 -9
  12. package/dist/helpers.d.mts +8 -9
  13. package/dist/helpers.mjs +6 -3
  14. package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
  15. package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
  16. package/dist/index.d.mts +4 -4
  17. package/dist/index.mjs +537 -118
  18. package/dist/jest-compat/aliases.d.mts +5 -0
  19. package/dist/jest-compat/aliases.mjs +65 -0
  20. package/dist/jest-compat/caller.mjs +53 -0
  21. package/dist/jest-compat/setup.mjs +72 -36
  22. package/dist/jest-compat.cjs +1 -3
  23. package/dist/jest-compat.d.cts +4 -5
  24. package/dist/jest-compat.d.mts +4 -5
  25. package/dist/jest-compat.mjs +1 -1
  26. package/dist/matchers.d.cts +9 -9
  27. package/dist/matchers.d.mts +9 -9
  28. package/dist/memory-6EPHrJA1.cjs +144 -0
  29. package/dist/memory-FYbP0_gg.mjs +126 -0
  30. package/dist/native/boundary.mjs +13 -2
  31. package/dist/native/bounded-process.mjs +165 -0
  32. package/dist/native/export-condition-recovery-preload.mjs +5 -0
  33. package/dist/native/export-condition-recovery.mjs +195 -0
  34. package/dist/native/globals.mjs +133 -5
  35. package/dist/native/hooks.mjs +131 -71
  36. package/dist/native/loader.mjs +41 -28
  37. package/dist/native/match.d.mts +3 -0
  38. package/dist/native/match.mjs +38 -2
  39. package/dist/native/metro-profile-compiler.mjs +234 -0
  40. package/dist/native/metro-profile.mjs +115 -0
  41. package/dist/native/module-reset.mjs +111 -6
  42. package/dist/native/ownership.d.mts +105 -0
  43. package/dist/native/ownership.mjs +474 -0
  44. package/dist/native/registry-compiler.mjs +43 -0
  45. package/dist/native/registry-process.mjs +124 -0
  46. package/dist/native/registry.mjs +139 -32
  47. package/dist/native/reset.mjs +305 -135
  48. package/dist/native/resolve.d.mts +20 -3
  49. package/dist/native/resolve.mjs +32 -12
  50. package/dist/native/rntl-hooks.mjs +76 -0
  51. package/dist/native/setup.mjs +81 -32
  52. package/dist/native/state-manifest.d.mts +22 -0
  53. package/dist/native/state-manifest.mjs +136 -0
  54. package/dist/native/transform.mjs +29 -8
  55. package/dist/native/worker.mjs +52 -4
  56. package/dist/pool-B4yesGhI.cjs +121 -0
  57. package/dist/pool-DjpOjOf3.mjs +119 -0
  58. package/dist/{presets-CoNf4ByH.cjs → presets-BYHmi7-W.cjs} +117 -18
  59. package/dist/{presets-DGProTaA.mjs → presets-DC-eM5IA.mjs} +117 -18
  60. package/dist/presets.d.mts +1 -1
  61. package/dist/presets.mjs +1 -1
  62. package/dist/rntl-matchers.d.ts +58 -12
  63. package/dist/serializer.cjs +4 -2
  64. package/dist/serializer.d.cts +3 -4
  65. package/dist/serializer.d.mts +3 -4
  66. package/dist/serializer.mjs +4 -2
  67. package/dist/setup.mjs +61 -50
  68. package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
  69. package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
  70. package/docs/hot-default-design.md +175 -88
  71. package/docs/migrating-from-jest.md +12 -5
  72. package/docs/migrating-from-vitest-react-native.md +4 -4
  73. package/docs/release-readiness.md +39 -13
  74. package/docs/versioning.md +19 -18
  75. package/package.json +42 -31
  76. package/dist/pool-BU-1ecIF.cjs +0 -122
  77. package/dist/pool-Bcxn9a3I.mjs +0 -118
@@ -0,0 +1,121 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ const require_errors = require("./errors-B3lJK46O.cjs");
3
+ const require_worker_vitest = require("./worker-vitest-BfiQB8ND.cjs");
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path, 1);
6
+ let vitest_node = require("vitest/node");
7
+ //#region src/native/pool.ts
8
+ function deepEqual(a, b) {
9
+ if (a === b) return true;
10
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
11
+ const ka = Object.keys(a);
12
+ const kb = Object.keys(b);
13
+ if (ka.length !== kb.length) return false;
14
+ return ka.every((k) => kb.includes(k) && deepEqual(a[k], b[k]));
15
+ }
16
+ var NativeMemoryCoordinator = class {
17
+ recyclingWorker = null;
18
+ tryRecycle(worker) {
19
+ if (this.recyclingWorker !== null) return this.recyclingWorker === worker;
20
+ this.recyclingWorker = worker;
21
+ return true;
22
+ }
23
+ finished(worker) {
24
+ if (this.recyclingWorker === worker) this.recyclingWorker = null;
25
+ }
26
+ };
27
+ var NativePoolWorker = class extends vitest_node.ThreadsPoolWorker {
28
+ name = "vitest-native";
29
+ reportMemory;
30
+ entrypoint;
31
+ environment;
32
+ recycleAfterFiles;
33
+ memoryLimit;
34
+ memoryPlan;
35
+ memoryCoordinator;
36
+ allowUnboundedMemory;
37
+ sampleRss;
38
+ diagnostics;
39
+ filesRun = 0;
40
+ lastHeapUsed = 0;
41
+ memoryListenerAttached = false;
42
+ batchWarningShown = false;
43
+ constructor(options, native, memoryCoordinator) {
44
+ super(options);
45
+ this.entrypoint = node_path.default.resolve(native.workerEntry);
46
+ this.environment = options.environment;
47
+ this.recycleAfterFiles = native.recycleAfterFiles ?? 0;
48
+ this.memoryLimit = native.memoryLimit ?? 0;
49
+ this.memoryPlan = native.memoryPlan;
50
+ this.memoryCoordinator = memoryCoordinator;
51
+ this.allowUnboundedMemory = native.allowUnboundedMemory ?? false;
52
+ this.sampleRss = native.sampleRss ?? (() => process.memoryUsage.rss());
53
+ this.diagnostics = native.diagnostics ?? false;
54
+ this.reportMemory = this.memoryLimit > 0;
55
+ }
56
+ async start() {
57
+ this.assertInsideHardRssLimit("starting another worker");
58
+ await super.start();
59
+ if (this.reportMemory && !this.memoryListenerAttached) {
60
+ this.memoryListenerAttached = true;
61
+ this.on("message", (message) => {
62
+ if (message?.__vitest_worker_response__ && typeof message.usedMemory === "number") this.lastHeapUsed = message.usedMemory;
63
+ });
64
+ }
65
+ }
66
+ async stop() {
67
+ try {
68
+ await super.stop();
69
+ } finally {
70
+ this.memoryCoordinator.finished(this);
71
+ }
72
+ }
73
+ assertInsideHardRssLimit(action) {
74
+ const hard = this.allowUnboundedMemory ? null : this.memoryPlan?.hardRssLimit;
75
+ if (hard == null) return;
76
+ const rss = this.sampleRss();
77
+ if (rss < hard) return;
78
+ throw new require_errors.VitestNativeError("HOT_MEMORY_BUDGET_EXCEEDED", `hotRuntime stopped before ${action}: process RSS is ${Math.round(rss / 1024 / 1024)} MiB, at or above the ${Math.round(hard / 1024 / 1024)} MiB hard limit derived from ${this.memoryPlan?.source ?? "the effective memory ceiling"}. Continuing could let the OS or container kill the test process without a useful result. Reduce maxWorkers, run without hotRuntime, or set hotRuntime.allowUnboundedMemory:true only when an external scheduler provides the memory boundary.`);
79
+ }
80
+ send(message) {
81
+ if (message.type === "run" || message.type === "collect") {
82
+ this.assertInsideHardRssLimit("starting the next test task");
83
+ if (!this.batchWarningShown && message.context.files.length > 1 && (this.recycleAfterFiles > 0 || this.memoryLimit > 0)) {
84
+ this.batchWarningShown = true;
85
+ const explanation = `Vitest batched ${message.context.files.length} files into one task in single-worker mode, so hotRuntime cannot recycle at file boundaries and its memory limits are inert.`;
86
+ if (!this.allowUnboundedMemory) throw new require_errors.VitestNativeError("HOT_MEMORY_UNBOUNDED", `${explanation} Use maxWorkers >= 2, disable hotRuntime, or explicitly accept this risk with hotRuntime:{ allowUnboundedMemory:true }.`);
87
+ console.warn(`[vitest-native] ${explanation} Continuing because allowUnboundedMemory:true was set.`);
88
+ }
89
+ this.filesRun += message.context.files.length;
90
+ }
91
+ super.send(message);
92
+ }
93
+ canReuse(task) {
94
+ let recycleReason = null;
95
+ if (this.recycleAfterFiles > 0 && this.filesRun >= this.recycleAfterFiles) recycleReason = `${this.filesRun} files`;
96
+ else if (this.memoryLimit > 0 && this.lastHeapUsed >= this.memoryLimit) recycleReason = `${Math.round(this.lastHeapUsed / 1024 / 1024)} MiB worker heap`;
97
+ else {
98
+ const soft = this.allowUnboundedMemory ? null : this.memoryPlan?.softRssLimit;
99
+ const rss = soft == null ? 0 : this.sampleRss();
100
+ if (soft != null && rss >= soft) recycleReason = `${Math.round(rss / 1024 / 1024)} MiB process RSS`;
101
+ }
102
+ if (recycleReason !== null && this.memoryCoordinator.tryRecycle(this)) {
103
+ if (this.diagnostics) console.log(`[vitest-native] recycling hot worker after ${recycleReason}`);
104
+ return false;
105
+ }
106
+ const env = task.context.environment;
107
+ return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
108
+ }
109
+ };
110
+ /** Pool initializer for `test.pool` — keeps RN-hot workers alive across files. */
111
+ function nativePool(options) {
112
+ const mismatch = require_worker_vitest.workerVitestMismatch(node_path.default.resolve(options.workerEntry), options.projectRoot);
113
+ if (mismatch) throw require_worker_vitest.workerVitestMismatchError(mismatch);
114
+ const memoryCoordinator = new NativeMemoryCoordinator();
115
+ return {
116
+ name: "vitest-native",
117
+ createPoolWorker: (poolOptions) => new NativePoolWorker(poolOptions, options, memoryCoordinator)
118
+ };
119
+ }
120
+ //#endregion
121
+ exports.nativePool = nativePool;
@@ -0,0 +1,119 @@
1
+ import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
2
+ import { n as workerVitestMismatchError, t as workerVitestMismatch } from "./worker-vitest-BGPo0ek6.mjs";
3
+ import path from "node:path";
4
+ import { ThreadsPoolWorker } from "vitest/node";
5
+ //#region src/native/pool.ts
6
+ function deepEqual(a, b) {
7
+ if (a === b) return true;
8
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
9
+ const ka = Object.keys(a);
10
+ const kb = Object.keys(b);
11
+ if (ka.length !== kb.length) return false;
12
+ return ka.every((k) => kb.includes(k) && deepEqual(a[k], b[k]));
13
+ }
14
+ var NativeMemoryCoordinator = class {
15
+ recyclingWorker = null;
16
+ tryRecycle(worker) {
17
+ if (this.recyclingWorker !== null) return this.recyclingWorker === worker;
18
+ this.recyclingWorker = worker;
19
+ return true;
20
+ }
21
+ finished(worker) {
22
+ if (this.recyclingWorker === worker) this.recyclingWorker = null;
23
+ }
24
+ };
25
+ var NativePoolWorker = class extends ThreadsPoolWorker {
26
+ name = "vitest-native";
27
+ reportMemory;
28
+ entrypoint;
29
+ environment;
30
+ recycleAfterFiles;
31
+ memoryLimit;
32
+ memoryPlan;
33
+ memoryCoordinator;
34
+ allowUnboundedMemory;
35
+ sampleRss;
36
+ diagnostics;
37
+ filesRun = 0;
38
+ lastHeapUsed = 0;
39
+ memoryListenerAttached = false;
40
+ batchWarningShown = false;
41
+ constructor(options, native, memoryCoordinator) {
42
+ super(options);
43
+ this.entrypoint = path.resolve(native.workerEntry);
44
+ this.environment = options.environment;
45
+ this.recycleAfterFiles = native.recycleAfterFiles ?? 0;
46
+ this.memoryLimit = native.memoryLimit ?? 0;
47
+ this.memoryPlan = native.memoryPlan;
48
+ this.memoryCoordinator = memoryCoordinator;
49
+ this.allowUnboundedMemory = native.allowUnboundedMemory ?? false;
50
+ this.sampleRss = native.sampleRss ?? (() => process.memoryUsage.rss());
51
+ this.diagnostics = native.diagnostics ?? false;
52
+ this.reportMemory = this.memoryLimit > 0;
53
+ }
54
+ async start() {
55
+ this.assertInsideHardRssLimit("starting another worker");
56
+ await super.start();
57
+ if (this.reportMemory && !this.memoryListenerAttached) {
58
+ this.memoryListenerAttached = true;
59
+ this.on("message", (message) => {
60
+ if (message?.__vitest_worker_response__ && typeof message.usedMemory === "number") this.lastHeapUsed = message.usedMemory;
61
+ });
62
+ }
63
+ }
64
+ async stop() {
65
+ try {
66
+ await super.stop();
67
+ } finally {
68
+ this.memoryCoordinator.finished(this);
69
+ }
70
+ }
71
+ assertInsideHardRssLimit(action) {
72
+ const hard = this.allowUnboundedMemory ? null : this.memoryPlan?.hardRssLimit;
73
+ if (hard == null) return;
74
+ const rss = this.sampleRss();
75
+ if (rss < hard) return;
76
+ throw new VitestNativeError("HOT_MEMORY_BUDGET_EXCEEDED", `hotRuntime stopped before ${action}: process RSS is ${Math.round(rss / 1024 / 1024)} MiB, at or above the ${Math.round(hard / 1024 / 1024)} MiB hard limit derived from ${this.memoryPlan?.source ?? "the effective memory ceiling"}. Continuing could let the OS or container kill the test process without a useful result. Reduce maxWorkers, run without hotRuntime, or set hotRuntime.allowUnboundedMemory:true only when an external scheduler provides the memory boundary.`);
77
+ }
78
+ send(message) {
79
+ if (message.type === "run" || message.type === "collect") {
80
+ this.assertInsideHardRssLimit("starting the next test task");
81
+ if (!this.batchWarningShown && message.context.files.length > 1 && (this.recycleAfterFiles > 0 || this.memoryLimit > 0)) {
82
+ this.batchWarningShown = true;
83
+ const explanation = `Vitest batched ${message.context.files.length} files into one task in single-worker mode, so hotRuntime cannot recycle at file boundaries and its memory limits are inert.`;
84
+ if (!this.allowUnboundedMemory) throw new VitestNativeError("HOT_MEMORY_UNBOUNDED", `${explanation} Use maxWorkers >= 2, disable hotRuntime, or explicitly accept this risk with hotRuntime:{ allowUnboundedMemory:true }.`);
85
+ console.warn(`[vitest-native] ${explanation} Continuing because allowUnboundedMemory:true was set.`);
86
+ }
87
+ this.filesRun += message.context.files.length;
88
+ }
89
+ super.send(message);
90
+ }
91
+ canReuse(task) {
92
+ let recycleReason = null;
93
+ if (this.recycleAfterFiles > 0 && this.filesRun >= this.recycleAfterFiles) recycleReason = `${this.filesRun} files`;
94
+ else if (this.memoryLimit > 0 && this.lastHeapUsed >= this.memoryLimit) recycleReason = `${Math.round(this.lastHeapUsed / 1024 / 1024)} MiB worker heap`;
95
+ else {
96
+ const soft = this.allowUnboundedMemory ? null : this.memoryPlan?.softRssLimit;
97
+ const rss = soft == null ? 0 : this.sampleRss();
98
+ if (soft != null && rss >= soft) recycleReason = `${Math.round(rss / 1024 / 1024)} MiB process RSS`;
99
+ }
100
+ if (recycleReason !== null && this.memoryCoordinator.tryRecycle(this)) {
101
+ if (this.diagnostics) console.log(`[vitest-native] recycling hot worker after ${recycleReason}`);
102
+ return false;
103
+ }
104
+ const env = task.context.environment;
105
+ return env.name === this.environment.name && deepEqual(env.options, this.environment.options);
106
+ }
107
+ };
108
+ /** Pool initializer for `test.pool` — keeps RN-hot workers alive across files. */
109
+ function nativePool(options) {
110
+ const mismatch = workerVitestMismatch(path.resolve(options.workerEntry), options.projectRoot);
111
+ if (mismatch) throw workerVitestMismatchError(mismatch);
112
+ const memoryCoordinator = new NativeMemoryCoordinator();
113
+ return {
114
+ name: "vitest-native",
115
+ createPoolWorker: (poolOptions) => new NativePoolWorker(poolOptions, options, memoryCoordinator)
116
+ };
117
+ }
118
+ //#endregion
119
+ export { nativePool };
@@ -784,11 +784,75 @@ function navigation(presetOptions = {}) {
784
784
  const NavigationContainerRefContext = react.default.createContext(null);
785
785
  const NavigationHelpersContext = react.default.createContext(null);
786
786
  const CurrentRenderContext = react.default.createContext(void 0);
787
- const ThemeContext = react.default.createContext({
788
- dark: false,
789
- colors: {}
790
- });
791
787
  const PreventRemoveContext = react.default.createContext(null);
788
+ const LinkingContext = react.default.createContext({ options: void 0 });
789
+ const LocaleDirContext = react.default.createContext("ltr");
790
+ const UNSTABLE_UnhandledLinkingContext = react.default.createContext({
791
+ lastUnhandledLink: void 0,
792
+ setLastUnhandledLink: () => {}
793
+ });
794
+ const themeFonts = (() => {
795
+ return process.env.VITEST_NATIVE_PLATFORM !== "android" ? {
796
+ regular: {
797
+ fontFamily: "System",
798
+ fontWeight: "400"
799
+ },
800
+ medium: {
801
+ fontFamily: "System",
802
+ fontWeight: "500"
803
+ },
804
+ bold: {
805
+ fontFamily: "System",
806
+ fontWeight: "600"
807
+ },
808
+ heavy: {
809
+ fontFamily: "System",
810
+ fontWeight: "700"
811
+ }
812
+ } : {
813
+ regular: {
814
+ fontFamily: "sans-serif",
815
+ fontWeight: "normal"
816
+ },
817
+ medium: {
818
+ fontFamily: "sans-serif-medium",
819
+ fontWeight: "normal"
820
+ },
821
+ bold: {
822
+ fontFamily: "sans-serif",
823
+ fontWeight: "600"
824
+ },
825
+ heavy: {
826
+ fontFamily: "sans-serif",
827
+ fontWeight: "700"
828
+ }
829
+ };
830
+ })();
831
+ const DefaultTheme = {
832
+ dark: false,
833
+ colors: {
834
+ primary: "rgb(0, 122, 255)",
835
+ background: "rgb(242, 242, 242)",
836
+ card: "rgb(255, 255, 255)",
837
+ text: "rgb(28, 28, 30)",
838
+ border: "rgb(216, 216, 216)",
839
+ notification: "rgb(255, 59, 48)"
840
+ },
841
+ fonts: themeFonts
842
+ };
843
+ const DarkTheme = {
844
+ dark: true,
845
+ colors: {
846
+ primary: "rgb(10, 132, 255)",
847
+ background: "rgb(1, 1, 1)",
848
+ card: "rgb(18, 18, 18)",
849
+ text: "rgb(229, 229, 231)",
850
+ border: "rgb(39, 39, 41)",
851
+ notification: "rgb(255, 69, 58)"
852
+ },
853
+ fonts: themeFonts
854
+ };
855
+ const ThemeContext = react.default.createContext(DefaultTheme);
792
856
  const Screen = createMockScreen(NavigationContext, NavigationRouteContext, defaultRouteParams);
793
857
  return {
794
858
  name: "navigation",
@@ -835,6 +899,17 @@ function navigation(presetOptions = {}) {
835
899
  "useStateForPath",
836
900
  "validatePathConfig",
837
901
  "BaseNavigationContainer",
902
+ "LinkingContext",
903
+ "LocaleDirContext",
904
+ "UNSTABLE_UnhandledLinkingContext",
905
+ "DefaultTheme",
906
+ "DarkTheme",
907
+ "createStaticNavigation",
908
+ "ServerContainer",
909
+ "useLinkBuilder",
910
+ "useLinkProps",
911
+ "useLocale",
912
+ "useRoutePath",
838
913
  "createComponentForStaticNavigation",
839
914
  "createPathConfigForStaticNavigation",
840
915
  "BaseRouter"
@@ -926,22 +1001,15 @@ function navigation(presetOptions = {}) {
926
1001
  function useNavigationContainerRef() {
927
1002
  return createNavigationContainerRef();
928
1003
  }
929
- const defaultTheme = {
930
- dark: false,
931
- colors: {
932
- primary: "rgb(0, 122, 255)",
933
- background: "rgb(242, 242, 242)",
934
- card: "rgb(255, 255, 255)",
935
- text: "rgb(28, 28, 30)",
936
- border: "rgb(216, 216, 216)",
937
- notification: "rgb(255, 59, 48)"
938
- }
939
- };
940
1004
  function ThemeProvider({ value, children }) {
941
- return react.default.createElement(ThemeContext.Provider, { value: value ?? defaultTheme }, children);
1005
+ return react.default.createElement(ThemeContext.Provider, { value: value ?? DefaultTheme }, children);
942
1006
  }
943
1007
  function useTheme() {
944
- return defaultTheme;
1008
+ try {
1009
+ return react.default.useContext(ThemeContext) ?? DefaultTheme;
1010
+ } catch {
1011
+ return DefaultTheme;
1012
+ }
945
1013
  }
946
1014
  function NavigationIndependentTree({ children }) {
947
1015
  return children;
@@ -967,7 +1035,17 @@ function navigation(presetOptions = {}) {
967
1035
  useNavigationState,
968
1036
  useNavigationContainerRef,
969
1037
  createNavigationContainerRef,
970
- createNavigatorFactory: vitest.vi.fn(() => vitest.vi.fn()),
1038
+ createNavigatorFactory: vitest.vi.fn((Navigator) => () => ({
1039
+ Navigator: Navigator ?? react.default.forwardRef((props, ref) => react.default.createElement("Navigator", {
1040
+ ...props,
1041
+ ref
1042
+ }, props.children)),
1043
+ Screen,
1044
+ Group: react.default.forwardRef((props, ref) => react.default.createElement("Group", {
1045
+ ...props,
1046
+ ref
1047
+ }, props.children))
1048
+ })),
971
1049
  useNavigationBuilder: vitest.vi.fn(() => ({
972
1050
  state: getState(),
973
1051
  navigation: useNavigation(),
@@ -1017,6 +1095,27 @@ function navigation(presetOptions = {}) {
1017
1095
  BaseNavigationContainer,
1018
1096
  createComponentForStaticNavigation: vitest.vi.fn(() => () => null),
1019
1097
  createPathConfigForStaticNavigation: vitest.vi.fn(() => ({})),
1098
+ LinkingContext,
1099
+ LocaleDirContext,
1100
+ UNSTABLE_UnhandledLinkingContext,
1101
+ DefaultTheme,
1102
+ DarkTheme,
1103
+ createStaticNavigation: vitest.vi.fn(() => NavigationContainer),
1104
+ ServerContainer: react.default.forwardRef((props, _ref) => react.default.createElement(react.default.Fragment, null, props.children)),
1105
+ useLinkBuilder: vitest.vi.fn(() => ({
1106
+ buildHref: (name) => `/${name}`,
1107
+ buildAction: (href) => ({
1108
+ type: "NAVIGATE",
1109
+ payload: { name: href }
1110
+ })
1111
+ })),
1112
+ useLinkProps: vitest.vi.fn(({ href, action }) => ({
1113
+ href,
1114
+ accessibilityRole: "link",
1115
+ onPress: () => action
1116
+ })),
1117
+ useLocale: vitest.vi.fn(() => ({ direction: "ltr" })),
1118
+ useRoutePath: vitest.vi.fn(() => void 0),
1020
1119
  BaseRouter: {
1021
1120
  getInitialState: vitest.vi.fn(() => getState()),
1022
1121
  getRehydratedState: vitest.vi.fn((state) => state),
@@ -782,11 +782,75 @@ function navigation(presetOptions = {}) {
782
782
  const NavigationContainerRefContext = React.createContext(null);
783
783
  const NavigationHelpersContext = React.createContext(null);
784
784
  const CurrentRenderContext = React.createContext(void 0);
785
- const ThemeContext = React.createContext({
786
- dark: false,
787
- colors: {}
788
- });
789
785
  const PreventRemoveContext = React.createContext(null);
786
+ const LinkingContext = React.createContext({ options: void 0 });
787
+ const LocaleDirContext = React.createContext("ltr");
788
+ const UNSTABLE_UnhandledLinkingContext = React.createContext({
789
+ lastUnhandledLink: void 0,
790
+ setLastUnhandledLink: () => {}
791
+ });
792
+ const themeFonts = (() => {
793
+ return process.env.VITEST_NATIVE_PLATFORM !== "android" ? {
794
+ regular: {
795
+ fontFamily: "System",
796
+ fontWeight: "400"
797
+ },
798
+ medium: {
799
+ fontFamily: "System",
800
+ fontWeight: "500"
801
+ },
802
+ bold: {
803
+ fontFamily: "System",
804
+ fontWeight: "600"
805
+ },
806
+ heavy: {
807
+ fontFamily: "System",
808
+ fontWeight: "700"
809
+ }
810
+ } : {
811
+ regular: {
812
+ fontFamily: "sans-serif",
813
+ fontWeight: "normal"
814
+ },
815
+ medium: {
816
+ fontFamily: "sans-serif-medium",
817
+ fontWeight: "normal"
818
+ },
819
+ bold: {
820
+ fontFamily: "sans-serif",
821
+ fontWeight: "600"
822
+ },
823
+ heavy: {
824
+ fontFamily: "sans-serif",
825
+ fontWeight: "700"
826
+ }
827
+ };
828
+ })();
829
+ const DefaultTheme = {
830
+ dark: false,
831
+ colors: {
832
+ primary: "rgb(0, 122, 255)",
833
+ background: "rgb(242, 242, 242)",
834
+ card: "rgb(255, 255, 255)",
835
+ text: "rgb(28, 28, 30)",
836
+ border: "rgb(216, 216, 216)",
837
+ notification: "rgb(255, 59, 48)"
838
+ },
839
+ fonts: themeFonts
840
+ };
841
+ const DarkTheme = {
842
+ dark: true,
843
+ colors: {
844
+ primary: "rgb(10, 132, 255)",
845
+ background: "rgb(1, 1, 1)",
846
+ card: "rgb(18, 18, 18)",
847
+ text: "rgb(229, 229, 231)",
848
+ border: "rgb(39, 39, 41)",
849
+ notification: "rgb(255, 69, 58)"
850
+ },
851
+ fonts: themeFonts
852
+ };
853
+ const ThemeContext = React.createContext(DefaultTheme);
790
854
  const Screen = createMockScreen(NavigationContext, NavigationRouteContext, defaultRouteParams);
791
855
  return {
792
856
  name: "navigation",
@@ -833,6 +897,17 @@ function navigation(presetOptions = {}) {
833
897
  "useStateForPath",
834
898
  "validatePathConfig",
835
899
  "BaseNavigationContainer",
900
+ "LinkingContext",
901
+ "LocaleDirContext",
902
+ "UNSTABLE_UnhandledLinkingContext",
903
+ "DefaultTheme",
904
+ "DarkTheme",
905
+ "createStaticNavigation",
906
+ "ServerContainer",
907
+ "useLinkBuilder",
908
+ "useLinkProps",
909
+ "useLocale",
910
+ "useRoutePath",
836
911
  "createComponentForStaticNavigation",
837
912
  "createPathConfigForStaticNavigation",
838
913
  "BaseRouter"
@@ -924,22 +999,15 @@ function navigation(presetOptions = {}) {
924
999
  function useNavigationContainerRef() {
925
1000
  return createNavigationContainerRef();
926
1001
  }
927
- const defaultTheme = {
928
- dark: false,
929
- colors: {
930
- primary: "rgb(0, 122, 255)",
931
- background: "rgb(242, 242, 242)",
932
- card: "rgb(255, 255, 255)",
933
- text: "rgb(28, 28, 30)",
934
- border: "rgb(216, 216, 216)",
935
- notification: "rgb(255, 59, 48)"
936
- }
937
- };
938
1002
  function ThemeProvider({ value, children }) {
939
- return React.createElement(ThemeContext.Provider, { value: value ?? defaultTheme }, children);
1003
+ return React.createElement(ThemeContext.Provider, { value: value ?? DefaultTheme }, children);
940
1004
  }
941
1005
  function useTheme() {
942
- return defaultTheme;
1006
+ try {
1007
+ return React.useContext(ThemeContext) ?? DefaultTheme;
1008
+ } catch {
1009
+ return DefaultTheme;
1010
+ }
943
1011
  }
944
1012
  function NavigationIndependentTree({ children }) {
945
1013
  return children;
@@ -965,7 +1033,17 @@ function navigation(presetOptions = {}) {
965
1033
  useNavigationState,
966
1034
  useNavigationContainerRef,
967
1035
  createNavigationContainerRef,
968
- createNavigatorFactory: vi.fn(() => vi.fn()),
1036
+ createNavigatorFactory: vi.fn((Navigator) => () => ({
1037
+ Navigator: Navigator ?? React.forwardRef((props, ref) => React.createElement("Navigator", {
1038
+ ...props,
1039
+ ref
1040
+ }, props.children)),
1041
+ Screen,
1042
+ Group: React.forwardRef((props, ref) => React.createElement("Group", {
1043
+ ...props,
1044
+ ref
1045
+ }, props.children))
1046
+ })),
969
1047
  useNavigationBuilder: vi.fn(() => ({
970
1048
  state: getState(),
971
1049
  navigation: useNavigation(),
@@ -1015,6 +1093,27 @@ function navigation(presetOptions = {}) {
1015
1093
  BaseNavigationContainer,
1016
1094
  createComponentForStaticNavigation: vi.fn(() => () => null),
1017
1095
  createPathConfigForStaticNavigation: vi.fn(() => ({})),
1096
+ LinkingContext,
1097
+ LocaleDirContext,
1098
+ UNSTABLE_UnhandledLinkingContext,
1099
+ DefaultTheme,
1100
+ DarkTheme,
1101
+ createStaticNavigation: vi.fn(() => NavigationContainer),
1102
+ ServerContainer: React.forwardRef((props, _ref) => React.createElement(React.Fragment, null, props.children)),
1103
+ useLinkBuilder: vi.fn(() => ({
1104
+ buildHref: (name) => `/${name}`,
1105
+ buildAction: (href) => ({
1106
+ type: "NAVIGATE",
1107
+ payload: { name: href }
1108
+ })
1109
+ })),
1110
+ useLinkProps: vi.fn(({ href, action }) => ({
1111
+ href,
1112
+ accessibilityRole: "link",
1113
+ onPress: () => action
1114
+ })),
1115
+ useLocale: vi.fn(() => ({ direction: "ltr" })),
1116
+ useRoutePath: vi.fn(() => void 0),
1018
1117
  BaseRouter: {
1019
1118
  getInitialState: vi.fn(() => getState()),
1020
1119
  getRehydratedState: vi.fn((state) => state),
@@ -1,2 +1,2 @@
1
- import { _ as gestureHandler, a as flashList, c as svg, d as deviceInfo, f as expo, g as safeAreaContext, h as navigation, i as bottomSheet, l as netInfo, m as asyncStorage, n as worklets, o as vectorIcons, p as screens, r as keyboardController, s as webview, u as mmkv, v as reanimated } from "./index-CmETArCM.mjs";
1
+ import { _ as gestureHandler, a as flashList, c as svg, d as deviceInfo, f as expo, g as safeAreaContext, h as navigation, i as bottomSheet, l as netInfo, m as asyncStorage, n as worklets, o as vectorIcons, p as screens, r as keyboardController, s as webview, u as mmkv, v as reanimated } from "./index-CEbwa4QU.mjs";
2
2
  export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
package/dist/presets.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { C as asyncStorage, E as gestureHandler, S as screens, T as safeAreaContext, _ as svg, a as bottomSheet, b as deviceInfo, g as webview, h as vectorIcons, k as reanimated, m as flashList, n as worklets, r as keyboardController, v as netInfo, w as navigation, x as expo, y as mmkv } from "./presets-DGProTaA.mjs";
1
+ import { C as asyncStorage, E as gestureHandler, S as screens, T as safeAreaContext, _ as svg, a as bottomSheet, b as deviceInfo, g as webview, h as vectorIcons, k as reanimated, m as flashList, n as worklets, r as keyboardController, v as netInfo, w as navigation, x as expo, y as mmkv } from "./presets-DC-eM5IA.mjs";
2
2
  export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, svg, vectorIcons, webview, worklets };
@@ -1,11 +1,12 @@
1
+ /// <reference types="vitest" />
1
2
  /**
2
3
  * Opt-in types for React Native Testing Library's matchers under Vitest.
3
4
  *
4
- * RNTL's matchers work at runtime under this plugin, but it declares their types only
5
- * for Jest — `dist/matchers/types.d.ts` augments the global `jest` namespace and the
6
- * `@jest/expect` module, and neither reaches Vitest's `Assertion`. Without this,
7
- * `toHaveTextContent`, `toHaveStyle`, `toBeVisible` and the rest are
8
- * `Property 'x' does not exist on type 'Assertion<...>'` for anyone who typechecks.
5
+ * RNTL's matchers work at runtime under this plugin, but RNTL declares their types for
6
+ * Jest. Before RNTL 14 nothing reached Vitest's `Assertion`, so `toHaveTextContent`,
7
+ * `toHaveStyle`, `toBeVisible` and the rest were `Property 'x' does not exist on type
8
+ * 'Assertion<...>'` for anyone who typechecks. RNTL 14 also augments the global
9
+ * `jest.Matchers<R>`, which Vitest 4's `JestAssertion<T>` extends as `Matchers<void, T>`.
9
10
  *
10
11
  * Reference it once, anywhere in the project:
11
12
  *
@@ -20,16 +21,61 @@
20
21
  * projects that use the mock engine without RNTL. Measured both ways before choosing
21
22
  * this shape. @testing-library/jest-dom ships its `/vitest` entry for the same reason.
22
23
  *
23
- * The import is a deep path because RNTL does not re-export the interface from its
24
- * entry point. It has no `exports` map, so the path resolves; if a future RNTL moves
25
- * it, this file fails loudly at the reference site rather than silently dropping the
26
- * matchers.
24
+ * The matcher interface is declared here rather than imported: RNTL does not export it
25
+ * from its entry point, and its internal location differs by major (`build/` in 12 and
26
+ * 13, `dist/` in 14), so a deep import typed the matchers on one major and silently
27
+ * dropped them on the others. Only the element type is version-specific
28
+ * (`ReactTestInstance` before 14, `TestInstance` from 14); it is read from RNTL's public
29
+ * `screen` API, so it is identical to the type RNTL's own global augmentation uses. A
30
+ * different type declares `toContainElement` twice on Vitest 4, which TypeScript 7
31
+ * reports as TS2320 under `skipLibCheck: false`.
32
+ * tests/rntl-matchers-types.test.ts compares these members with the installed RNTL's.
27
33
  */
28
- import type { JestNativeMatchers } from "@testing-library/react-native/dist/matchers/types";
34
+ import type { screen } from "@testing-library/react-native";
35
+ import type { ImageStyle, StyleProp, TextStyle, ViewStyle } from "react-native";
36
+
37
+ type HostElement = NonNullable<ReturnType<typeof screen.queryByText>>;
38
+ type TextMatch = string | RegExp;
39
+ type TextMatchOptions = { exact?: boolean; normalizer?: (text: string) => string };
40
+
41
+ interface RNTLMatchers<R> {
42
+ toBeOnTheScreen(): R;
43
+ toBeChecked(): R;
44
+ toBeCollapsed(): R;
45
+ toBeDisabled(): R;
46
+ toBeBusy(): R;
47
+ toBeEmptyElement(): R;
48
+ toBeEnabled(): R;
49
+ toBeExpanded(): R;
50
+ toBePartiallyChecked(): R;
51
+ toBeSelected(): R;
52
+ toBeVisible(): R;
53
+ toContainElement(instance: HostElement | null): R;
54
+ toHaveAccessibilityValue(expectedValue: {
55
+ min?: number;
56
+ max?: number;
57
+ now?: number;
58
+ text?: TextMatch;
59
+ }): R;
60
+ toHaveAccessibleName(expectedName?: TextMatch, options?: TextMatchOptions): R;
61
+ toHaveDisplayValue(expectedValue: TextMatch, options?: TextMatchOptions): R;
62
+ toHaveProp(name: string, expectedValue?: unknown): R;
63
+ toHaveStyle(style: StyleProp<ViewStyle | TextStyle | ImageStyle>): R;
64
+ toHaveTextContent(expectedText: TextMatch, options?: TextMatchOptions): R;
65
+ }
29
66
 
30
67
  declare module "vitest" {
68
+ // `void`, the same instantiation Vitest 4's JestAssertion inherits from RNTL 14's global
69
+ // augmentation. Any other argument declares every matcher twice with different return
70
+ // types, which TypeScript 7 rejects (TS2320) for RNTL 14 users; Vitest's own matchers
71
+ // return void as well. The type parameters follow Vitest 5's `Assertion<R, T>`; on
72
+ // Vitest 4 with `skipLibCheck: false` that is reported as TS2428, and the matchers
73
+ // stay typed.
31
74
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
32
- interface Assertion<T = any> extends JestNativeMatchers<T> {}
75
+ interface Assertion<
76
+ R extends void | Promise<void> = void,
77
+ T = unknown,
78
+ > extends RNTLMatchers<void> {}
33
79
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
34
- interface AsymmetricMatchersContaining extends JestNativeMatchers<void> {}
80
+ interface AsymmetricMatchersContaining extends RNTLMatchers<void> {}
35
81
  }