vitest-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +456 -0
- package/dist/chunk-CjcI7cDX.mjs +15 -0
- package/dist/helpers.cjs +113 -0
- package/dist/helpers.d.cts +19 -0
- package/dist/helpers.d.mts +19 -0
- package/dist/helpers.mjs +108 -0
- package/dist/index-CJqS-y_M.d.cts +268 -0
- package/dist/index-h4vpIkQO.d.mts +266 -0
- package/dist/index.cjs +308 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +299 -0
- package/dist/preset-map-C5d8DSY7.cjs +21 -0
- package/dist/preset-map-CTAjv5aa.mjs +16 -0
- package/dist/presets-ArwboRy7.cjs +980 -0
- package/dist/presets-DgEuMxfn.mjs +896 -0
- package/dist/presets.cjs +9 -0
- package/dist/presets.d.cts +2 -0
- package/dist/presets.d.mts +2 -0
- package/dist/presets.mjs +2 -0
- package/dist/serializer.cjs +118 -0
- package/dist/serializer.d.cts +16 -0
- package/dist/serializer.d.mts +16 -0
- package/dist/serializer.mjs +117 -0
- package/dist/setup.cjs +1869 -0
- package/dist/setup.d.cts +1 -0
- package/dist/setup.d.mts +1 -0
- package/dist/setup.mjs +1869 -0
- package/package.json +124 -0
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//#region src/helpers.ts
|
|
2
|
+
/**
|
|
3
|
+
* Test helpers for vitest-native.
|
|
4
|
+
*
|
|
5
|
+
* These functions mutate the live mock instances created by the setup file.
|
|
6
|
+
* Import from 'vitest-native/helpers' in your test files.
|
|
7
|
+
*/
|
|
8
|
+
function getMock() {
|
|
9
|
+
const mock = globalThis.__vitest_native_mock;
|
|
10
|
+
if (!mock) throw new Error("vitest-native helpers called before setup. Ensure the vitest-native plugin is configured.");
|
|
11
|
+
return mock;
|
|
12
|
+
}
|
|
13
|
+
/** The original NativeModules instance, stored so resetAllMocks() can restore it. */
|
|
14
|
+
let originalNativeModules = null;
|
|
15
|
+
function setPlatform(os) {
|
|
16
|
+
const platform = getMock().Platform;
|
|
17
|
+
platform.OS = os;
|
|
18
|
+
platform.Version = os === "ios" ? "17.0" : 34;
|
|
19
|
+
platform.select.mockImplementation((specifics) => {
|
|
20
|
+
return specifics[os] ?? specifics.default;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function setDimensions(dims) {
|
|
24
|
+
const mock = getMock();
|
|
25
|
+
mock.Dimensions.set({
|
|
26
|
+
window: dims,
|
|
27
|
+
screen: dims
|
|
28
|
+
});
|
|
29
|
+
if (mock.useWindowDimensions._setDimensions) mock.useWindowDimensions._setDimensions(dims);
|
|
30
|
+
}
|
|
31
|
+
function setColorScheme(scheme) {
|
|
32
|
+
const mock = getMock();
|
|
33
|
+
const resolved = scheme ?? "light";
|
|
34
|
+
mock.Appearance.setColorScheme(resolved);
|
|
35
|
+
if (mock.useColorScheme._setScheme) mock.useColorScheme._setScheme(resolved);
|
|
36
|
+
}
|
|
37
|
+
function mockNativeModule(name, impl) {
|
|
38
|
+
const mock = getMock();
|
|
39
|
+
if (originalNativeModules === null) originalNativeModules = mock.NativeModules;
|
|
40
|
+
const existing = mock.NativeModules;
|
|
41
|
+
mock.NativeModules = new Proxy(existing, { get(target, prop) {
|
|
42
|
+
if (prop === name) return impl;
|
|
43
|
+
if (typeof prop === "symbol") return void 0;
|
|
44
|
+
return Reflect.get(target, prop) ?? new Proxy({}, { get(_, p) {
|
|
45
|
+
if (typeof p === "symbol") return void 0;
|
|
46
|
+
return () => {};
|
|
47
|
+
} });
|
|
48
|
+
} });
|
|
49
|
+
}
|
|
50
|
+
function clearMockFns(obj, visited = /* @__PURE__ */ new Set()) {
|
|
51
|
+
if (!obj || typeof obj !== "object" || visited.has(obj)) return;
|
|
52
|
+
visited.add(obj);
|
|
53
|
+
for (const [_key, value] of Object.entries(obj)) {
|
|
54
|
+
if (typeof value === "function" && "mockClear" in value) value.mockClear();
|
|
55
|
+
if (typeof value === "object" && value !== null) clearMockFns(value, visited);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function resetAllMocks() {
|
|
59
|
+
const mock = getMock();
|
|
60
|
+
clearMockFns(mock);
|
|
61
|
+
mock.Platform.OS = "ios";
|
|
62
|
+
mock.Platform.Version = "17.0";
|
|
63
|
+
mock.Platform.select.mockImplementation((specifics) => {
|
|
64
|
+
return specifics.ios ?? specifics.default;
|
|
65
|
+
});
|
|
66
|
+
if (mock.Dimensions._reset) mock.Dimensions._reset();
|
|
67
|
+
else mock.Dimensions.set({
|
|
68
|
+
window: {
|
|
69
|
+
width: 390,
|
|
70
|
+
height: 844,
|
|
71
|
+
scale: 3,
|
|
72
|
+
fontScale: 1
|
|
73
|
+
},
|
|
74
|
+
screen: {
|
|
75
|
+
width: 390,
|
|
76
|
+
height: 844,
|
|
77
|
+
scale: 3,
|
|
78
|
+
fontScale: 1
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
if (mock.useWindowDimensions._resetDimensions) mock.useWindowDimensions._resetDimensions({
|
|
82
|
+
width: 390,
|
|
83
|
+
height: 844,
|
|
84
|
+
scale: 3,
|
|
85
|
+
fontScale: 1
|
|
86
|
+
});
|
|
87
|
+
else if (mock.useWindowDimensions._setDimensions) mock.useWindowDimensions._setDimensions({
|
|
88
|
+
width: 390,
|
|
89
|
+
height: 844,
|
|
90
|
+
scale: 3,
|
|
91
|
+
fontScale: 1
|
|
92
|
+
});
|
|
93
|
+
if (mock.Appearance._reset) mock.Appearance._reset();
|
|
94
|
+
else mock.Appearance.setColorScheme("light");
|
|
95
|
+
if (mock.useColorScheme._resetScheme) mock.useColorScheme._resetScheme("light");
|
|
96
|
+
else if (mock.useColorScheme._setScheme) mock.useColorScheme._setScheme("light");
|
|
97
|
+
if (mock.Keyboard._reset) mock.Keyboard._reset();
|
|
98
|
+
if (mock.AppState._reset) mock.AppState._reset();
|
|
99
|
+
if (mock.BackHandler._reset) mock.BackHandler._reset();
|
|
100
|
+
if (mock.I18nManager._reset) mock.I18nManager._reset();
|
|
101
|
+
if (mock.DeviceEventEmitter._reset) mock.DeviceEventEmitter._reset();
|
|
102
|
+
if (originalNativeModules !== null) {
|
|
103
|
+
mock.NativeModules = originalNativeModules;
|
|
104
|
+
originalNativeModules = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
export { mockNativeModule, resetAllMocks, setColorScheme, setDimensions, setPlatform };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Mock } from "vitest";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/types.d.ts
|
|
6
|
+
/** Static methods available on the Image component mock. */
|
|
7
|
+
interface ImageStatic {
|
|
8
|
+
getSize: Mock;
|
|
9
|
+
getSizeWithHeaders: Mock;
|
|
10
|
+
prefetch: Mock;
|
|
11
|
+
queryCache: Mock;
|
|
12
|
+
resolveAssetSource: Mock;
|
|
13
|
+
}
|
|
14
|
+
/** The Animated API mock shape. */
|
|
15
|
+
interface AnimatedMock {
|
|
16
|
+
Value: new (value?: number) => any;
|
|
17
|
+
ValueXY: new (value?: {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}) => any;
|
|
21
|
+
Color: new () => any;
|
|
22
|
+
timing: Mock;
|
|
23
|
+
spring: Mock;
|
|
24
|
+
decay: Mock;
|
|
25
|
+
sequence: Mock;
|
|
26
|
+
parallel: Mock;
|
|
27
|
+
stagger: Mock;
|
|
28
|
+
loop: Mock;
|
|
29
|
+
delay: Mock;
|
|
30
|
+
add: Mock;
|
|
31
|
+
subtract: Mock;
|
|
32
|
+
multiply: Mock;
|
|
33
|
+
divide: Mock;
|
|
34
|
+
modulo: Mock;
|
|
35
|
+
diffClamp: Mock;
|
|
36
|
+
event: Mock;
|
|
37
|
+
forkEvent: Mock;
|
|
38
|
+
unforkEvent: Mock;
|
|
39
|
+
createAnimatedComponent: Mock;
|
|
40
|
+
View: React.ComponentType<any>;
|
|
41
|
+
Text: React.ComponentType<any>;
|
|
42
|
+
Image: React.ComponentType<any>;
|
|
43
|
+
ScrollView: React.ComponentType<any>;
|
|
44
|
+
FlatList: React.ComponentType<any>;
|
|
45
|
+
SectionList: React.ComponentType<any>;
|
|
46
|
+
}
|
|
47
|
+
/** Platform API mock shape. */
|
|
48
|
+
interface PlatformMock {
|
|
49
|
+
OS: "ios" | "android";
|
|
50
|
+
Version: string | number;
|
|
51
|
+
isPad: boolean;
|
|
52
|
+
isTVOS: boolean;
|
|
53
|
+
isTV: boolean;
|
|
54
|
+
isVision: boolean;
|
|
55
|
+
isTesting: boolean;
|
|
56
|
+
select: Mock;
|
|
57
|
+
constants: {
|
|
58
|
+
reactNativeVersion: {
|
|
59
|
+
major: number;
|
|
60
|
+
minor: number;
|
|
61
|
+
patch: number;
|
|
62
|
+
};
|
|
63
|
+
osVersion: number;
|
|
64
|
+
systemName: string;
|
|
65
|
+
isTesting: boolean;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Dimensions API mock shape. */
|
|
69
|
+
interface DimensionsMock {
|
|
70
|
+
get: Mock;
|
|
71
|
+
set: Mock;
|
|
72
|
+
addEventListener: Mock;
|
|
73
|
+
_reset: () => void;
|
|
74
|
+
}
|
|
75
|
+
/** Keyboard API mock shape. */
|
|
76
|
+
interface KeyboardMock {
|
|
77
|
+
dismiss: Mock;
|
|
78
|
+
addListener: Mock;
|
|
79
|
+
removeListener: Mock;
|
|
80
|
+
removeAllListeners: Mock;
|
|
81
|
+
isVisible: Mock;
|
|
82
|
+
metrics: Mock;
|
|
83
|
+
scheduleLayoutAnimation: Mock;
|
|
84
|
+
_show: (height?: number) => void;
|
|
85
|
+
_hide: () => void;
|
|
86
|
+
_reset: () => void;
|
|
87
|
+
}
|
|
88
|
+
/** AppState API mock shape. */
|
|
89
|
+
interface AppStateMock {
|
|
90
|
+
currentState: string;
|
|
91
|
+
isAvailable: boolean;
|
|
92
|
+
addEventListener: Mock;
|
|
93
|
+
_setState: (state: string) => void;
|
|
94
|
+
_reset: () => void;
|
|
95
|
+
}
|
|
96
|
+
/** The full React Native mock object. */
|
|
97
|
+
interface ReactNativeMock {
|
|
98
|
+
View: React.ComponentType<any>;
|
|
99
|
+
Text: React.ComponentType<any>;
|
|
100
|
+
Image: React.ComponentType<any> & ImageStatic;
|
|
101
|
+
TextInput: React.ComponentType<any>;
|
|
102
|
+
ScrollView: React.ComponentType<any>;
|
|
103
|
+
FlatList: React.ComponentType<any>;
|
|
104
|
+
SectionList: React.ComponentType<any>;
|
|
105
|
+
Modal: React.ComponentType<any>;
|
|
106
|
+
Pressable: React.ComponentType<any>;
|
|
107
|
+
TouchableOpacity: React.ComponentType<any>;
|
|
108
|
+
TouchableHighlight: React.ComponentType<any>;
|
|
109
|
+
TouchableWithoutFeedback: React.ComponentType<any>;
|
|
110
|
+
TouchableNativeFeedback: React.ComponentType<any>;
|
|
111
|
+
ActivityIndicator: React.ComponentType<any>;
|
|
112
|
+
Button: React.ComponentType<any>;
|
|
113
|
+
Switch: React.ComponentType<any>;
|
|
114
|
+
RefreshControl: React.ComponentType<any>;
|
|
115
|
+
StatusBar: Record<string, any>;
|
|
116
|
+
SafeAreaView: React.ComponentType<any>;
|
|
117
|
+
KeyboardAvoidingView: React.ComponentType<any>;
|
|
118
|
+
ImageBackground: React.ComponentType<any>;
|
|
119
|
+
VirtualizedList: React.ComponentType<any>;
|
|
120
|
+
InputAccessoryView: React.ComponentType<any>;
|
|
121
|
+
DrawerLayoutAndroid: React.ComponentType<any>;
|
|
122
|
+
Platform: PlatformMock;
|
|
123
|
+
Dimensions: DimensionsMock;
|
|
124
|
+
StyleSheet: Record<string, any>;
|
|
125
|
+
Animated: AnimatedMock;
|
|
126
|
+
Alert: Record<string, Mock>;
|
|
127
|
+
Linking: Record<string, Mock>;
|
|
128
|
+
AppState: AppStateMock;
|
|
129
|
+
Keyboard: KeyboardMock;
|
|
130
|
+
BackHandler: Record<string, any>;
|
|
131
|
+
Vibration: Record<string, Mock>;
|
|
132
|
+
PermissionsAndroid: Record<string, any>;
|
|
133
|
+
Appearance: Record<string, any>;
|
|
134
|
+
PixelRatio: Record<string, Mock>;
|
|
135
|
+
LayoutAnimation: Record<string, any>;
|
|
136
|
+
Clipboard: Record<string, any>;
|
|
137
|
+
Share: Record<string, Mock>;
|
|
138
|
+
AccessibilityInfo: Record<string, Mock>;
|
|
139
|
+
InteractionManager: Record<string, any>;
|
|
140
|
+
PanResponder: Record<string, Mock>;
|
|
141
|
+
ToastAndroid: Record<string, any>;
|
|
142
|
+
ActionSheetIOS: Record<string, Mock>;
|
|
143
|
+
LogBox: Record<string, Mock>;
|
|
144
|
+
Easing: Record<string, Mock>;
|
|
145
|
+
I18nManager: Record<string, any>;
|
|
146
|
+
DeviceEventEmitter: Record<string, any>;
|
|
147
|
+
useColorScheme: (() => "light" | "dark") & {
|
|
148
|
+
_setScheme: (s: "light" | "dark") => void;
|
|
149
|
+
_resetScheme: (s: "light" | "dark") => void;
|
|
150
|
+
};
|
|
151
|
+
useWindowDimensions: (() => {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
scale: number;
|
|
155
|
+
fontScale: number;
|
|
156
|
+
}) & {
|
|
157
|
+
_setDimensions: (d: any) => void;
|
|
158
|
+
_resetDimensions: (d: any) => void;
|
|
159
|
+
};
|
|
160
|
+
NativeModules: Record<string, any>;
|
|
161
|
+
TurboModuleRegistry: Record<string, any>;
|
|
162
|
+
UIManager: Record<string, any>;
|
|
163
|
+
NativeEventEmitter: new (...args: any[]) => any;
|
|
164
|
+
NativeAppEventEmitter: Record<string, any>;
|
|
165
|
+
NativeComponentRegistry: Record<string, any>;
|
|
166
|
+
requireNativeComponent: Mock;
|
|
167
|
+
AppRegistry: Record<string, Mock>;
|
|
168
|
+
VirtualizedSectionList: React.ComponentType<any>;
|
|
169
|
+
Touchable: Record<string, any>;
|
|
170
|
+
processColor: Mock;
|
|
171
|
+
findNodeHandle: Mock;
|
|
172
|
+
PlatformColor: Mock;
|
|
173
|
+
DynamicColorIOS: Mock;
|
|
174
|
+
Settings: Record<string, Mock>;
|
|
175
|
+
DeviceInfo: Record<string, any>;
|
|
176
|
+
useAnimatedValue: Mock;
|
|
177
|
+
RootTagContext: React.Context<any>;
|
|
178
|
+
ReactNativeVersion: {
|
|
179
|
+
major: number;
|
|
180
|
+
minor: number;
|
|
181
|
+
patch: number;
|
|
182
|
+
};
|
|
183
|
+
Systrace: Record<string, Mock>;
|
|
184
|
+
DevSettings: Record<string, Mock>;
|
|
185
|
+
Networking: Record<string, Mock>;
|
|
186
|
+
unstable_batchedUpdates: Mock;
|
|
187
|
+
registerCallableModule: Mock;
|
|
188
|
+
codegenNativeCommands: Mock;
|
|
189
|
+
codegenNativeComponent: Mock;
|
|
190
|
+
UTFSequence: Record<string, string>;
|
|
191
|
+
ProgressBarAndroid: React.ComponentType<any>;
|
|
192
|
+
PushNotificationIOS: Record<string, Mock>;
|
|
193
|
+
NativeDialogManagerAndroid: Record<string, Mock>;
|
|
194
|
+
usePressability: Mock;
|
|
195
|
+
default: ReactNativeMock;
|
|
196
|
+
}
|
|
197
|
+
interface PresetModule {
|
|
198
|
+
/** Factory that builds the mock object. Only called in Vitest worker processes. */
|
|
199
|
+
factory: () => Record<string, any>;
|
|
200
|
+
/** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
|
|
201
|
+
exports: string[];
|
|
202
|
+
}
|
|
203
|
+
interface Preset {
|
|
204
|
+
name: string;
|
|
205
|
+
modules: Record<string, PresetModule>;
|
|
206
|
+
}
|
|
207
|
+
interface VitestNativeOptions {
|
|
208
|
+
/** Target platform. Default: 'ios' */
|
|
209
|
+
platform?: "ios" | "android";
|
|
210
|
+
/**
|
|
211
|
+
* Built-in third-party library presets. When provided, only these presets
|
|
212
|
+
* are used. When omitted, vitest-native auto-detects installed packages
|
|
213
|
+
* and enables matching presets automatically.
|
|
214
|
+
*
|
|
215
|
+
* Only built-in presets are supported (reanimated, gestureHandler,
|
|
216
|
+
* safeAreaContext, navigation, asyncStorage, screens, expo). For custom
|
|
217
|
+
* module mocking, use vi.mock() in a setup file.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { reactNative, presets } from 'vitest-native';
|
|
222
|
+
* reactNative({ presets: [presets.reanimated(), presets.navigation()] })
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
presets?: Preset[];
|
|
226
|
+
/**
|
|
227
|
+
* Plain-data overrides merged into the react-native module mock.
|
|
228
|
+
* Values must be JSON-serializable (strings, numbers, booleans, plain
|
|
229
|
+
* objects, arrays). Function values are not supported — use vi.mock()
|
|
230
|
+
* in a setup file for function-based overrides.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* reactNative({ mocks: { Platform: { OS: 'web' } } })
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
mocks?: Record<string, any>;
|
|
238
|
+
/** Log plugin activity. Default: false */
|
|
239
|
+
diagnostics?: boolean;
|
|
240
|
+
/** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
|
|
241
|
+
assetExts?: string[];
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/presets/reanimated.d.ts
|
|
245
|
+
declare function reanimated(): Preset;
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/presets/gesture-handler.d.ts
|
|
248
|
+
declare function gestureHandler(): Preset;
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/presets/safe-area.d.ts
|
|
251
|
+
declare function safeAreaContext(): Preset;
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/presets/navigation.d.ts
|
|
254
|
+
declare function navigation(): Preset;
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/presets/async-storage.d.ts
|
|
257
|
+
declare function asyncStorage(): Preset;
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/presets/screens.d.ts
|
|
260
|
+
declare function screens(): Preset;
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/presets/expo.d.ts
|
|
263
|
+
declare function expo(): Preset;
|
|
264
|
+
declare namespace index_d_exports {
|
|
265
|
+
export { asyncStorage, expo, gestureHandler, navigation, reanimated, safeAreaContext, screens };
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { navigation as a, reanimated as c, VitestNativeOptions as d, asyncStorage as i, Preset as l, expo as n, safeAreaContext as o, screens as r, gestureHandler as s, index_d_exports as t, ReactNativeMock as u };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Mock } from "vitest";
|
|
2
|
+
|
|
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
|
+
NativeComponentRegistry: Record<string, any>;
|
|
164
|
+
requireNativeComponent: Mock;
|
|
165
|
+
AppRegistry: Record<string, Mock>;
|
|
166
|
+
VirtualizedSectionList: React.ComponentType<any>;
|
|
167
|
+
Touchable: Record<string, any>;
|
|
168
|
+
processColor: Mock;
|
|
169
|
+
findNodeHandle: Mock;
|
|
170
|
+
PlatformColor: Mock;
|
|
171
|
+
DynamicColorIOS: Mock;
|
|
172
|
+
Settings: Record<string, Mock>;
|
|
173
|
+
DeviceInfo: Record<string, any>;
|
|
174
|
+
useAnimatedValue: Mock;
|
|
175
|
+
RootTagContext: React.Context<any>;
|
|
176
|
+
ReactNativeVersion: {
|
|
177
|
+
major: number;
|
|
178
|
+
minor: number;
|
|
179
|
+
patch: number;
|
|
180
|
+
};
|
|
181
|
+
Systrace: Record<string, Mock>;
|
|
182
|
+
DevSettings: Record<string, Mock>;
|
|
183
|
+
Networking: Record<string, Mock>;
|
|
184
|
+
unstable_batchedUpdates: Mock;
|
|
185
|
+
registerCallableModule: Mock;
|
|
186
|
+
codegenNativeCommands: Mock;
|
|
187
|
+
codegenNativeComponent: Mock;
|
|
188
|
+
UTFSequence: Record<string, string>;
|
|
189
|
+
ProgressBarAndroid: React.ComponentType<any>;
|
|
190
|
+
PushNotificationIOS: Record<string, Mock>;
|
|
191
|
+
NativeDialogManagerAndroid: Record<string, Mock>;
|
|
192
|
+
usePressability: Mock;
|
|
193
|
+
default: ReactNativeMock;
|
|
194
|
+
}
|
|
195
|
+
interface PresetModule {
|
|
196
|
+
/** Factory that builds the mock object. Only called in Vitest worker processes. */
|
|
197
|
+
factory: () => Record<string, any>;
|
|
198
|
+
/** Static list of named exports for virtual ESM module generation. Read at Vite config time (no vitest available). */
|
|
199
|
+
exports: string[];
|
|
200
|
+
}
|
|
201
|
+
interface Preset {
|
|
202
|
+
name: string;
|
|
203
|
+
modules: Record<string, PresetModule>;
|
|
204
|
+
}
|
|
205
|
+
interface VitestNativeOptions {
|
|
206
|
+
/** Target platform. Default: 'ios' */
|
|
207
|
+
platform?: "ios" | "android";
|
|
208
|
+
/**
|
|
209
|
+
* Built-in third-party library presets. When provided, only these presets
|
|
210
|
+
* are used. When omitted, vitest-native auto-detects installed packages
|
|
211
|
+
* and enables matching presets automatically.
|
|
212
|
+
*
|
|
213
|
+
* Only built-in presets are supported (reanimated, gestureHandler,
|
|
214
|
+
* safeAreaContext, navigation, asyncStorage, screens, expo). For custom
|
|
215
|
+
* module mocking, use vi.mock() in a setup file.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { reactNative, presets } from 'vitest-native';
|
|
220
|
+
* reactNative({ presets: [presets.reanimated(), presets.navigation()] })
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
presets?: Preset[];
|
|
224
|
+
/**
|
|
225
|
+
* Plain-data overrides merged into the react-native module mock.
|
|
226
|
+
* Values must be JSON-serializable (strings, numbers, booleans, plain
|
|
227
|
+
* objects, arrays). Function values are not supported — use vi.mock()
|
|
228
|
+
* in a setup file for function-based overrides.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* reactNative({ mocks: { Platform: { OS: 'web' } } })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
mocks?: Record<string, any>;
|
|
236
|
+
/** Log plugin activity. Default: false */
|
|
237
|
+
diagnostics?: boolean;
|
|
238
|
+
/** Additional asset file extensions to stub (e.g. ['.lottie', '.m4b']) */
|
|
239
|
+
assetExts?: string[];
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/presets/reanimated.d.ts
|
|
243
|
+
declare function reanimated(): Preset;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/presets/gesture-handler.d.ts
|
|
246
|
+
declare function gestureHandler(): Preset;
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/presets/safe-area.d.ts
|
|
249
|
+
declare function safeAreaContext(): Preset;
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/presets/navigation.d.ts
|
|
252
|
+
declare function navigation(): Preset;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/presets/async-storage.d.ts
|
|
255
|
+
declare function asyncStorage(): Preset;
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/presets/screens.d.ts
|
|
258
|
+
declare function screens(): Preset;
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/presets/expo.d.ts
|
|
261
|
+
declare function expo(): Preset;
|
|
262
|
+
declare namespace index_d_exports {
|
|
263
|
+
export { asyncStorage, expo, gestureHandler, navigation, reanimated, safeAreaContext, screens };
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
export { navigation as a, reanimated as c, VitestNativeOptions as d, asyncStorage as i, Preset as l, expo as n, safeAreaContext as o, screens as r, gestureHandler as s, index_d_exports as t, ReactNativeMock as u };
|