vitest-native 0.14.0-rc.8 → 0.14.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 (99) hide show
  1. package/README.md +91 -72
  2. package/dist/cli.d.mts +1 -3
  3. package/dist/cli.mjs +215 -76
  4. package/dist/context.d.mts +45 -0
  5. package/dist/context.mjs +243 -0
  6. package/dist/errors.d.mts +3 -0
  7. package/dist/helpers.cjs +53 -4
  8. package/dist/helpers.d.cts +1 -3
  9. package/dist/helpers.d.mts +1 -3
  10. package/dist/helpers.mjs +2 -3
  11. package/dist/host-5o48Ujzs.mjs +939 -0
  12. package/dist/{index-BSyUeoga.d.mts → index-DqU4YO3D.d.mts} +32 -53
  13. package/dist/index.d.mts +1 -3
  14. package/dist/index.mjs +464 -596
  15. package/dist/jest-compat/error-equality.mjs +127 -0
  16. package/dist/jest-compat/jest-object.mjs +149 -4
  17. package/dist/jest-compat/node-registry.mjs +233 -58
  18. package/dist/jest-compat/setup.mjs +34 -4
  19. package/dist/jest-compat.cjs +227 -52
  20. package/dist/jest-compat.d.cts +5 -6
  21. package/dist/jest-compat.d.mts +5 -6
  22. package/dist/jest-compat.mjs +204 -52
  23. package/dist/matchers.cjs +1 -2
  24. package/dist/matchers.d.cts +0 -2
  25. package/dist/matchers.d.mts +0 -2
  26. package/dist/matchers.mjs +1 -2
  27. package/dist/{memory-FYbP0_gg.mjs → memory-Couw0Esx.mjs} +31 -6
  28. package/dist/native/assets.d.mts +2 -0
  29. package/dist/native/assets.mjs +34 -0
  30. package/dist/native/babel-toolchain.mjs +190 -0
  31. package/dist/native/babel-worker.mjs +47 -0
  32. package/dist/native/boundary.mjs +23 -8
  33. package/dist/native/compile-cache.mjs +21 -9
  34. package/dist/native/coverage-v8.mjs +287 -0
  35. package/dist/native/esm-interop.mjs +216 -0
  36. package/dist/native/expo-native-modules.mjs +7 -1
  37. package/dist/native/globals.mjs +104 -6
  38. package/dist/native/hooks.mjs +271 -60
  39. package/dist/native/loader.mjs +409 -20
  40. package/dist/native/match.d.mts +24 -2
  41. package/dist/native/match.mjs +117 -12
  42. package/dist/native/metro-profile-compiler.mjs +2 -31
  43. package/dist/native/module-reset.mjs +37 -5
  44. package/dist/native/native-modules.d.mts +2 -3
  45. package/dist/native/native-modules.mjs +22 -21
  46. package/dist/native/ownership.d.mts +10 -0
  47. package/dist/native/ownership.mjs +96 -9
  48. package/dist/native/registry-compiler.mjs +6 -0
  49. package/dist/native/registry.mjs +138 -119
  50. package/dist/native/resident-health.mjs +133 -0
  51. package/dist/native/resolve.d.mts +6 -0
  52. package/dist/native/resolve.mjs +100 -9
  53. package/dist/native/rntl-hooks.mjs +157 -6
  54. package/dist/native/rntl-text-host.mjs +64 -0
  55. package/dist/native/runner.mjs +106 -1
  56. package/dist/native/setup.mjs +105 -77
  57. package/dist/native/state-manifest.mjs +14 -8
  58. package/dist/native/transform.d.mts +2 -0
  59. package/dist/native/transform.mjs +476 -59
  60. package/dist/native/worker.mjs +151 -46
  61. package/dist/{pool-DjpOjOf3.mjs → pool-CFSpNfyw.mjs} +37 -11
  62. package/dist/{preset-map-BlBriTA0.mjs → preset-map-CogjYmSw.mjs} +4 -19
  63. package/dist/preset-modules.mjs +2 -11
  64. package/dist/{presets--zrEWQC2.mjs → presets-CXDyg51l.mjs} +65 -82
  65. package/dist/presets.d.mts +1 -1
  66. package/dist/presets.mjs +1 -1
  67. package/dist/report-error.d.mts +20 -0
  68. package/dist/report-error.mjs +145 -0
  69. package/dist/rntl-support.d.mts +12 -0
  70. package/dist/rntl-support.mjs +189 -0
  71. package/dist/{rolldown-runtime-BhDjJH2R.mjs → rolldown-runtime-D70C1uOS.mjs} +1 -2
  72. package/dist/serializer.cjs +1 -2
  73. package/dist/serializer.d.cts +1 -3
  74. package/dist/serializer.d.mts +1 -3
  75. package/dist/serializer.mjs +1 -2
  76. package/dist/setup.mjs +95 -156
  77. package/dist/{worker-vitest-BGPo0ek6.mjs → worker-vitest-CILPFeRX.mjs} +2 -3
  78. package/docs/migrating-from-jest.md +76 -12
  79. package/docs/migrating-from-vitest-react-native.md +1 -1
  80. package/docs/release-readiness.md +6 -5
  81. package/docs/versioning.md +1 -1
  82. package/package.json +121 -103
  83. package/CHANGELOG.md +0 -2475
  84. package/dist/cli.cjs +0 -1924
  85. package/dist/cli.d.cts +0 -3
  86. package/dist/ecosystem-D6e1OVOg.mjs +0 -1019
  87. package/dist/ecosystem-MFwkbnaC.cjs +0 -1099
  88. package/dist/errors-B3lJK46O.cjs +0 -75
  89. package/dist/errors-CxoBUfVJ.mjs +0 -64
  90. package/dist/index-bZ7AHqLc.d.cts +0 -482
  91. package/dist/memory-6EPHrJA1.cjs +0 -144
  92. package/dist/pool-B4yesGhI.cjs +0 -121
  93. package/dist/preset-map-jSFsNy1Q.cjs +0 -241
  94. package/dist/preset-modules-BoLkaeEN.cjs +0 -53
  95. package/dist/preset-modules-CG8-G82P.mjs +0 -36
  96. package/dist/presets-9f83H0WW.cjs +0 -3939
  97. package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
  98. package/dist/worker-vitest-BfiQB8ND.cjs +0 -62
  99. package/docs/hot-default-design.md +0 -216
@@ -1,75 +0,0 @@
1
- //#region src/errors.mjs
2
- /**
3
- * The error types this package throws.
4
- *
5
- * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
6
- * verbatim and import this by relative path, and the test suite loads those same files
7
- * from src — so the module has to resolve identically in both trees. A .ts source would
8
- * only exist in one of them.
9
- *
10
- * WHAT SURVIVES WHERE, measured rather than assumed:
11
- *
12
- * - In the main process, and in a user's own try/catch inside a test, everything is
13
- * intact.
14
- * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
15
- * `stack`. `code` and every other own property is dropped.
16
- *
17
- * So the message must stay self-sufficient: nothing may move out of it into a field on
18
- * the assumption a reader will see it.
19
- *
20
- * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
21
- * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
22
- * prototype check would quietly fail across that seam. Shape does not care.
23
- */
24
- const PREFIX = "[vitest-native]";
25
- /** Guarantees the prefix exactly once, however the caller wrote the message. */
26
- function withPrefix(message) {
27
- return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
28
- }
29
- function buildMessage(message, options) {
30
- const base = withPrefix(message);
31
- return options?.docs ? `${base}\nSee ${options.docs}` : base;
32
- }
33
- /**
34
- * Error options, omitted entirely when there is no cause.
35
- *
36
- * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
37
- * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
38
- * print an empty cause and to make these errors shaped differently from every other
39
- * error in the process. Passing nothing keeps them identical.
40
- */
41
- function errorOptions(options) {
42
- return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
43
- }
44
- /** A failure originating in vitest-native. */
45
- var VitestNativeError = class extends Error {
46
- constructor(code, message, options) {
47
- super(buildMessage(message, options), errorOptions(options));
48
- this.name = "VitestNativeError";
49
- this.code = code;
50
- }
51
- };
52
- /**
53
- * A vitest-native failure that is also a type error — a badly typed option, say.
54
- * Extends TypeError so `instanceof TypeError` keeps working for consumers.
55
- */
56
- var VitestNativeTypeError = class extends TypeError {
57
- constructor(code, message, options) {
58
- super(buildMessage(message, options), errorOptions(options));
59
- this.name = "VitestNativeTypeError";
60
- this.code = code;
61
- }
62
- };
63
- //#endregion
64
- Object.defineProperty(exports, "VitestNativeError", {
65
- enumerable: true,
66
- get: function() {
67
- return VitestNativeError;
68
- }
69
- });
70
- Object.defineProperty(exports, "VitestNativeTypeError", {
71
- enumerable: true,
72
- get: function() {
73
- return VitestNativeTypeError;
74
- }
75
- });
@@ -1,64 +0,0 @@
1
- //#region src/errors.mjs
2
- /**
3
- * The error types this package throws.
4
- *
5
- * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
6
- * verbatim and import this by relative path, and the test suite loads those same files
7
- * from src — so the module has to resolve identically in both trees. A .ts source would
8
- * only exist in one of them.
9
- *
10
- * WHAT SURVIVES WHERE, measured rather than assumed:
11
- *
12
- * - In the main process, and in a user's own try/catch inside a test, everything is
13
- * intact.
14
- * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
15
- * `stack`. `code` and every other own property is dropped.
16
- *
17
- * So the message must stay self-sufficient: nothing may move out of it into a field on
18
- * the assumption a reader will see it.
19
- *
20
- * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
21
- * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
22
- * prototype check would quietly fail across that seam. Shape does not care.
23
- */
24
- const PREFIX = "[vitest-native]";
25
- /** Guarantees the prefix exactly once, however the caller wrote the message. */
26
- function withPrefix(message) {
27
- return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
28
- }
29
- function buildMessage(message, options) {
30
- const base = withPrefix(message);
31
- return options?.docs ? `${base}\nSee ${options.docs}` : base;
32
- }
33
- /**
34
- * Error options, omitted entirely when there is no cause.
35
- *
36
- * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
37
- * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
38
- * print an empty cause and to make these errors shaped differently from every other
39
- * error in the process. Passing nothing keeps them identical.
40
- */
41
- function errorOptions(options) {
42
- return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
43
- }
44
- /** A failure originating in vitest-native. */
45
- var VitestNativeError = class extends Error {
46
- constructor(code, message, options) {
47
- super(buildMessage(message, options), errorOptions(options));
48
- this.name = "VitestNativeError";
49
- this.code = code;
50
- }
51
- };
52
- /**
53
- * A vitest-native failure that is also a type error — a badly typed option, say.
54
- * Extends TypeError so `instanceof TypeError` keeps working for consumers.
55
- */
56
- var VitestNativeTypeError = class extends TypeError {
57
- constructor(code, message, options) {
58
- super(buildMessage(message, options), errorOptions(options));
59
- this.name = "VitestNativeTypeError";
60
- this.code = code;
61
- }
62
- };
63
- //#endregion
64
- export { VitestNativeTypeError as n, VitestNativeError as t };
@@ -1,482 +0,0 @@
1
- import { Mock } from "vitest";
2
- //#endregion
3
- //#region src/types.d.ts
4
- /** Static methods available on the Image component mock. */
5
- interface ImageStatic {
6
- getSize: Mock;
7
- getSizeWithHeaders: Mock;
8
- prefetch: Mock;
9
- queryCache: Mock;
10
- resolveAssetSource: Mock;
11
- }
12
- /** The Animated API mock shape. */
13
- interface AnimatedMock {
14
- Value: new (value?: number) => any;
15
- ValueXY: new (value?: {
16
- x: number;
17
- y: number;
18
- }) => any;
19
- Color: new () => any;
20
- timing: Mock;
21
- spring: Mock;
22
- decay: Mock;
23
- sequence: Mock;
24
- parallel: Mock;
25
- stagger: Mock;
26
- loop: Mock;
27
- delay: Mock;
28
- add: Mock;
29
- subtract: Mock;
30
- multiply: Mock;
31
- divide: Mock;
32
- modulo: Mock;
33
- diffClamp: Mock;
34
- event: Mock;
35
- forkEvent: Mock;
36
- unforkEvent: Mock;
37
- createAnimatedComponent: Mock;
38
- View: React.ComponentType<any>;
39
- Text: React.ComponentType<any>;
40
- Image: React.ComponentType<any>;
41
- ScrollView: React.ComponentType<any>;
42
- FlatList: React.ComponentType<any>;
43
- SectionList: React.ComponentType<any>;
44
- }
45
- /** Platform API mock shape. */
46
- interface PlatformMock {
47
- OS: "ios" | "android";
48
- Version: string | number;
49
- isPad: boolean;
50
- isTVOS: boolean;
51
- isTV: boolean;
52
- isVision: boolean;
53
- isTesting: boolean;
54
- select: Mock;
55
- constants: {
56
- reactNativeVersion: {
57
- major: number;
58
- minor: number;
59
- patch: number;
60
- };
61
- osVersion: number;
62
- systemName: string;
63
- isTesting: boolean;
64
- };
65
- }
66
- /** Dimensions API mock shape. */
67
- interface DimensionsMock {
68
- get: Mock;
69
- set: Mock;
70
- addEventListener: Mock;
71
- _reset: () => void;
72
- }
73
- /** Keyboard API mock shape. */
74
- interface KeyboardMock {
75
- dismiss: Mock;
76
- addListener: Mock;
77
- removeListener: Mock;
78
- removeAllListeners: Mock;
79
- isVisible: Mock;
80
- metrics: Mock;
81
- scheduleLayoutAnimation: Mock;
82
- _show: (height?: number) => void;
83
- _hide: () => void;
84
- _reset: () => void;
85
- }
86
- /** AppState API mock shape. */
87
- interface AppStateMock {
88
- currentState: string;
89
- isAvailable: boolean;
90
- addEventListener: Mock;
91
- _setState: (state: string) => void;
92
- _reset: () => void;
93
- }
94
- /** The full React Native mock object. */
95
- interface ReactNativeMock {
96
- View: React.ComponentType<any>;
97
- Text: React.ComponentType<any>;
98
- Image: React.ComponentType<any> & ImageStatic;
99
- TextInput: React.ComponentType<any>;
100
- ScrollView: React.ComponentType<any>;
101
- FlatList: React.ComponentType<any>;
102
- SectionList: React.ComponentType<any>;
103
- Modal: React.ComponentType<any>;
104
- Pressable: React.ComponentType<any>;
105
- TouchableOpacity: React.ComponentType<any>;
106
- TouchableHighlight: React.ComponentType<any>;
107
- TouchableWithoutFeedback: React.ComponentType<any>;
108
- TouchableNativeFeedback: React.ComponentType<any>;
109
- ActivityIndicator: React.ComponentType<any>;
110
- Button: React.ComponentType<any>;
111
- Switch: React.ComponentType<any>;
112
- RefreshControl: React.ComponentType<any>;
113
- StatusBar: Record<string, any>;
114
- SafeAreaView: React.ComponentType<any>;
115
- KeyboardAvoidingView: React.ComponentType<any>;
116
- ImageBackground: React.ComponentType<any>;
117
- VirtualizedList: React.ComponentType<any>;
118
- InputAccessoryView: React.ComponentType<any>;
119
- DrawerLayoutAndroid: React.ComponentType<any>;
120
- Platform: PlatformMock;
121
- Dimensions: DimensionsMock;
122
- StyleSheet: Record<string, any>;
123
- Animated: AnimatedMock;
124
- Alert: Record<string, Mock>;
125
- Linking: Record<string, Mock>;
126
- AppState: AppStateMock;
127
- Keyboard: KeyboardMock;
128
- BackHandler: Record<string, any>;
129
- Vibration: Record<string, Mock>;
130
- PermissionsAndroid: Record<string, any>;
131
- Appearance: Record<string, any>;
132
- PixelRatio: Record<string, Mock>;
133
- LayoutAnimation: Record<string, any>;
134
- Clipboard: Record<string, any>;
135
- Share: Record<string, Mock>;
136
- AccessibilityInfo: Record<string, Mock>;
137
- InteractionManager: Record<string, any>;
138
- PanResponder: Record<string, Mock>;
139
- ToastAndroid: Record<string, any>;
140
- ActionSheetIOS: Record<string, Mock>;
141
- LogBox: Record<string, Mock>;
142
- Easing: Record<string, Mock>;
143
- I18nManager: Record<string, any>;
144
- DeviceEventEmitter: Record<string, any>;
145
- useColorScheme: (() => "light" | "dark") & {
146
- _setScheme: (s: "light" | "dark") => void;
147
- _resetScheme: (s: "light" | "dark") => void;
148
- };
149
- useWindowDimensions: (() => {
150
- width: number;
151
- height: number;
152
- scale: number;
153
- fontScale: number;
154
- }) & {
155
- _setDimensions: (d: any) => void;
156
- _resetDimensions: (d: any) => void;
157
- };
158
- NativeModules: Record<string, any>;
159
- TurboModuleRegistry: Record<string, any>;
160
- UIManager: Record<string, any>;
161
- NativeEventEmitter: new (...args: any[]) => any;
162
- NativeAppEventEmitter: Record<string, any>;
163
- EventEmitter: new (...args: any[]) => any;
164
- NativeComponentRegistry: Record<string, any>;
165
- requireNativeComponent: Mock;
166
- AppRegistry: Record<string, Mock>;
167
- VirtualizedSectionList: React.ComponentType<any>;
168
- Touchable: Record<string, any>;
169
- processColor: Mock;
170
- findNodeHandle: Mock;
171
- PlatformColor: Mock;
172
- DynamicColorIOS: Mock;
173
- Settings: Record<string, Mock>;
174
- DeviceInfo: Record<string, any>;
175
- useAnimatedValue: Mock;
176
- useAnimatedValueXY: Mock;
177
- useAnimatedColor: Mock;
178
- RootTagContext: React.Context<any>;
179
- ReactNativeVersion: {
180
- major: number;
181
- minor: number;
182
- patch: number;
183
- };
184
- Systrace: Record<string, Mock>;
185
- DevSettings: Record<string, Mock>;
186
- Networking: Record<string, Mock>;
187
- unstable_batchedUpdates: Mock;
188
- registerCallableModule: Mock;
189
- codegenNativeCommands: Mock;
190
- codegenNativeComponent: Mock;
191
- UTFSequence: Record<string, string>;
192
- ProgressBarAndroid: React.ComponentType<any>;
193
- PushNotificationIOS: Record<string, Mock>;
194
- NativeDialogManagerAndroid: Record<string, Mock>;
195
- usePressability: Mock;
196
- default: ReactNativeMock;
197
- }
198
- interface PresetModule {
199
- /** Factory that builds the mock object. Only called in Vitest worker processes. */
200
- factory: () => Record<string, any>;
201
- /** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
202
- exports: string[];
203
- /**
204
- * Named exports read from the installed package, for a package whose API changes
205
- * between releases; replaces `exports` when present. Called once at Vite config time
206
- * with the project root and platform. `null` means the package is not installed, so
207
- * the module is not shadowed at all.
208
- */
209
- exportsFor?: (context: {
210
- projectRoot: string;
211
- platform: "ios" | "android";
212
- }) => string[] | null;
213
- }
214
- interface Preset {
215
- name: string;
216
- modules: Record<string, PresetModule>;
217
- /**
218
- * Optional async work the setup file awaits before each test file, ahead of any
219
- * `factory`. For a mock that needs something only an async API provides: the skia
220
- * preset loads CanvasKit (Skia's WebAssembly build) here.
221
- */
222
- prepare?: () => Promise<void>;
223
- /**
224
- * Optional JSON-serializable configuration for the preset. Presets are rebuilt
225
- * inside Vitest worker processes from their `name`, so any options passed to a
226
- * preset factory (e.g. `navigation({ defaultRouteParams })`) must be carried
227
- * here to survive the main-process → worker boundary. Read by the native setup
228
- * file and passed back into the factory in-worker. Must be JSON-serializable.
229
- */
230
- config?: Record<string, unknown>;
231
- }
232
- /** Options for the `navigation` preset. */
233
- interface NavigationPresetOptions {
234
- /**
235
- * Params returned by the mocked `useRoute().params` (and used as a `<Screen>`'s
236
- * fallback `initialParams`). Lets you test components that read route params at
237
- * mount — e.g. `useRoute().params.id` — without a custom `vi.mock`. Must be
238
- * JSON-serializable (it crosses the worker boundary).
239
- *
240
- * @example
241
- * ```ts
242
- * presets.navigation({ defaultRouteParams: { id: '1', mode: 'edit' } })
243
- * ```
244
- */
245
- defaultRouteParams?: Record<string, unknown>;
246
- }
247
- interface VitestNativeOptions {
248
- /** Target platform. Default: 'ios' */
249
- platform?: "ios" | "android";
250
- /**
251
- * Test engine.
252
- * - 'mock' — pure-JS reimplementation of React Native (fastest, lower fidelity).
253
- * - 'native' — runs real React Native JS, mocking only the native boundary
254
- * (highest fidelity).
255
- * - 'auto' — resolves to 'native' when '@react-native/babel-preset' and
256
- * '@babel/core' are available, otherwise falls back to 'mock'.
257
- * Default: 'auto'.
258
- */
259
- engine?: "auto" | "mock" | "native";
260
- /**
261
- * Built-in third-party library presets.
262
- *
263
- * An ARRAY replaces auto-detection entirely: only those presets are used.
264
- *
265
- * An OBJECT keeps auto-detection and turns individual presets off by name —
266
- * `{ navigation: false }` — which is what you want when one preset gets in the
267
- * way. Listing every other detected preset back by hand just to drop one is
268
- * both tedious and a thing that silently rots as dependencies change.
269
- *
270
- * Preset modules of your own are listed by path: a module whose default export is a
271
- * `Preset` or a function returning one. In an array they sit beside vitest-native's
272
- * presets (`presets.reanimated()`, ...); in the object form a path set to `true`
273
- * adds one to the auto-detected presets. A preset object of your own cannot be
274
- * listed directly, because its factories run in the test workers, which a function
275
- * in the config cannot reach; the plugin imports the module there instead. A
276
- * relative path resolves from the project root.
277
- *
278
- * @example
279
- * ```ts
280
- * import { reactNative, presets } from 'vitest-native';
281
- * reactNative({ presets: { navigation: false, './test/presets/my-lib.ts': true } })
282
- * reactNative({ presets: [presets.reanimated(), './test/presets/my-lib.ts'] })
283
- * ```
284
- */
285
- presets?: (Preset | string)[] | Record<string, boolean>;
286
- /**
287
- * `engine: 'mock'` only. Plain-data overrides merged into the react-native
288
- * module mock.
289
- * Values must be JSON-serializable (strings, numbers, booleans, plain
290
- * objects, arrays). Function values are not supported — use vi.mock()
291
- * in a setup file for function-based overrides.
292
- *
293
- * @example
294
- * ```ts
295
- * reactNative({ mocks: { Platform: { OS: 'web' } } })
296
- * ```
297
- */
298
- mocks?: Record<string, any>;
299
- /** Log plugin activity. Default: false */
300
- diagnostics?: boolean;
301
- /** Additional asset file extensions, loaded as Metro loads assets (e.g. ['.lottie', '.m4b']) */
302
- assetExts?: string[];
303
- /**
304
- * Experimental. Read the project's declarative Metro resolution profile in a
305
- * short-lived, memory-bounded child. Default: false (built-in React Native
306
- * extension/asset defaults). Pass true or an options object to opt in.
307
- *
308
- * Imperative `resolver.resolveRequest` behavior cannot be transferred as data:
309
- * when the config installs one, the source and asset extensions still apply and
310
- * a warning names the gap. Main fields and conditions are reported under
311
- * diagnostics but retain the engine's ownership policy.
312
- */
313
- metroConfig?: boolean | {
314
- configFile?: string;
315
- };
316
- /**
317
- * `engine: 'native'` only. Names of additional node_modules packages whose
318
- * source the native engine should transform (Flow/TS/JSX stripped) as it
319
- * loads them. By default only `react-native` / `@react-native` are
320
- * transformed; third-party RN libraries that ship untranspiled source
321
- * (e.g. `react-native-reanimated`, `react-native-safe-area-context`) need to
322
- * be listed here, analogous to Jest's `transformIgnorePatterns` allowlist.
323
- *
324
- * The object form adds `exclude`, which names packages the engine must NEVER
325
- * transform, whatever else would have selected them — auto-detection, a detected
326
- * package's dependency closure, or the engine's own built-in lists.
327
- *
328
- * `exclude` exists because the engine's judgement about what is React Native source
329
- * is a heuristic, and when it guesses wrong the failure is a parse error deep inside
330
- * a package the project never named. Build toolchains are the recurring case:
331
- * compiling one re-enters Babel while it is loading. The engine excludes the ones it
332
- * knows about, but that list is only as current as the last release — `exclude` is
333
- * how a project unblocks itself the same day, without waiting for one.
334
- *
335
- * Run with `diagnostics: true` to print the packages the engine chose to compile;
336
- * that list is what `exclude` subtracts from.
337
- *
338
- * @example
339
- * ```ts
340
- * reactNative({ engine: 'native', transform: ['react-native-reanimated'] })
341
- *
342
- * reactNative({
343
- * engine: 'native',
344
- * transform: {
345
- * include: ['react-native-reanimated'],
346
- * exclude: ['some-build-tool'], // never hand this to the Babel preset
347
- * },
348
- * })
349
- * ```
350
- */
351
- transform?: string[] | {
352
- include?: string[];
353
- exclude?: string[];
354
- };
355
- /**
356
- * `engine: 'native'` only. Built on Vitest's experimental custom-pool API.
357
- * Run tests in persistent
358
- * RN-hot workers: React Native's module graph loads once per worker and
359
- * stays resident across test files, while each file still gets a fresh
360
- * Vitest module runner (per-file isolation of your app/test modules).
361
- * Uses a custom Vitest pool + worker entry + runner; requires Vitest >= 4.
362
- *
363
- * Pass an object to tune worker recycling (self-defense against suites that
364
- * leak process-wide resources the per-file reset can't reclaim):
365
- * - `recycleAfterFiles`: retire a worker after it has run N test files. This
366
- * is enforced between Vitest scheduler tasks; a single task containing
367
- * multiple files cannot be interrupted.
368
- * - `memoryLimit`: retire a worker when its reported JS heap (bytes) meets
369
- * or exceeds this value, also between scheduler tasks. By default a
370
- * constrained-memory-aware plan derives this threshold, caps automatic
371
- * concurrency at four, reserves main-process and worker-replacement RSS,
372
- * and stops before crossing 90% of the host/container limit.
373
- * - `allowUnboundedMemory`: explicitly permit configurations where Vitest
374
- * cannot enforce file-boundary recycling, notably `maxWorkers: 1`. This
375
- * also disables the automatic worker cap and process-RSS hard stop. Use
376
- * only when an external scheduler provides the memory boundary.
377
- * - `preserveGlobals`: exact globalThis property names intentionally owned
378
- * by resident external libraries. App/test globals are otherwise removed
379
- * between files. Storybook's preview registry is preserved automatically.
380
- * - `esmGeneration`: re-evaluate externalized packages a test file `import`s,
381
- * so their module-level state does not carry into the next file. Node's ESM
382
- * registry cannot be invalidated, so the loader stamps a per-file generation
383
- * onto the resolved URL instead. On by default, because without it those
384
- * packages behave differently under hot than under stock isolation. It costs
385
- * re-execution: a suite whose files import many externalized (non-React
386
- * Native) packages measured 55% more wall clock at the extreme — still 9x
387
- * stock isolation, against 13.9x with it off. Set false to trade that back,
388
- * accepting that a package holding state across files will keep it.
389
- *
390
- * `'auto'` selects the bounded hot runtime when the configuration has recyclable
391
- * task boundaries (enough memory headroom for at least two workers) and no
392
- * explicit custom pool; otherwise the run keeps per-file isolation. Set
393
- * explicitly, it prints the reason for falling back; as the default it falls
394
- * back quietly (`diagnostics: true` shows the reason).
395
- *
396
- * Default: `'auto'`. `false` always runs each file in a fresh worker, with React
397
- * Native reloaded per file.
398
- */
399
- hotRuntime?: boolean | "auto" | {
400
- recycleAfterFiles?: number;
401
- memoryLimit?: number;
402
- allowUnboundedMemory?: boolean;
403
- preserveGlobals?: string[];
404
- esmGeneration?: boolean;
405
- };
406
- /**
407
- * `engine: 'native'` only. How native module lookups answer.
408
- *
409
- * - `'device'`: as on a device. `NativeModules[name]` and
410
- * `TurboModuleRegistry.get(name)` find React Native's own modules and those
411
- * registered with `mockNativeModule()`, and are `undefined`/`null` for any other
412
- * name. A React Native module's stub has only the members of its codegen spec.
413
- * - `'permissive'`: every name is present for every lookup, and every stub answers
414
- * every property with a method. An escape hatch for suites written against that
415
- * behaviour; prefer registering the modules a test needs with `mockNativeModule()`.
416
- *
417
- * Default: `'device'`.
418
- */
419
- nativeModules?: "device" | "permissive";
420
- }
421
- //#endregion
422
- //#region src/presets/reanimated.d.ts
423
- declare function reanimated(): Preset;
424
- //#endregion
425
- //#region src/presets/gesture-handler.d.ts
426
- declare function gestureHandler(): Preset;
427
- //#endregion
428
- //#region src/presets/safe-area.d.ts
429
- declare function safeAreaContext(): Preset;
430
- //#endregion
431
- //#region src/presets/navigation.d.ts
432
- declare function navigation(presetOptions?: NavigationPresetOptions): Preset;
433
- //#endregion
434
- //#region src/presets/async-storage.d.ts
435
- declare function asyncStorage(): Preset;
436
- //#endregion
437
- //#region src/presets/screens.d.ts
438
- declare function screens(): Preset;
439
- //#endregion
440
- //#region src/presets/expo.d.ts
441
- declare function expo(): Preset;
442
- //#endregion
443
- //#region src/presets/device-info.d.ts
444
- declare function deviceInfo(): Preset;
445
- //#endregion
446
- //#region src/presets/mmkv.d.ts
447
- declare function mmkv(): Preset;
448
- //#endregion
449
- //#region src/presets/netinfo.d.ts
450
- declare function netInfo(): Preset;
451
- //#endregion
452
- //#region src/presets/svg.d.ts
453
- declare function svg(): Preset;
454
- //#endregion
455
- //#region src/presets/webview.d.ts
456
- declare function webview(): Preset;
457
- //#endregion
458
- //#region src/presets/vector-icons.d.ts
459
- declare function vectorIcons(): Preset;
460
- //#endregion
461
- //#region src/presets/flash-list.d.ts
462
- declare function flashList(): Preset;
463
- //#endregion
464
- //#region src/presets/bottom-sheet.d.ts
465
- declare function bottomSheet(): Preset;
466
- //#endregion
467
- //#region src/presets/keyboard-controller.d.ts
468
- declare function keyboardController(): Preset;
469
- //#endregion
470
- //#region src/presets/worklets.d.ts
471
- declare function worklets(): Preset;
472
- //#endregion
473
- //#region src/presets/unistyles.d.ts
474
- declare function unistyles(): Preset;
475
- //#endregion
476
- //#region src/presets/skia.d.ts
477
- declare function skia(): Preset;
478
- declare namespace index_d_exports {
479
- export { asyncStorage, bottomSheet, deviceInfo, expo, flashList, gestureHandler, keyboardController, mmkv, navigation, netInfo, reanimated, safeAreaContext, screens, skia, svg, unistyles, vectorIcons, webview, worklets };
480
- }
481
- //#endregion
482
- export { VitestNativeOptions as C, ReactNativeMock as S, navigation as _, keyboardController as a, reanimated as b, vectorIcons as c, netInfo as d, mmkv as f, asyncStorage as g, screens as h, worklets as i, webview as l, expo as m, skia as n, bottomSheet as o, deviceInfo as p, unistyles as r, flashList as s, index_d_exports as t, svg as u, safeAreaContext as v, Preset as x, gestureHandler as y };