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/setup.cjs
ADDED
|
@@ -0,0 +1,1869 @@
|
|
|
1
|
+
const require_presets = require("./presets-ArwboRy7.cjs");
|
|
2
|
+
const require_preset_map = require("./preset-map-C5d8DSY7.cjs");
|
|
3
|
+
const require_serializer = require("./serializer.cjs");
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_presets.__toESM(node_path);
|
|
6
|
+
let node_module = require("node:module");
|
|
7
|
+
let vitest = require("vitest");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
react = require_presets.__toESM(react);
|
|
10
|
+
//#region src/mocks/components/View.ts
|
|
11
|
+
function createViewMock() {
|
|
12
|
+
const View = react.default.forwardRef((props, ref) => {
|
|
13
|
+
return react.default.createElement("View", {
|
|
14
|
+
...props,
|
|
15
|
+
ref
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
View.displayName = "View";
|
|
19
|
+
return View;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/mocks/components/Text.ts
|
|
23
|
+
function createTextMock() {
|
|
24
|
+
const Text = react.default.forwardRef((props, ref) => {
|
|
25
|
+
return react.default.createElement("Text", {
|
|
26
|
+
...props,
|
|
27
|
+
ref
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
Text.displayName = "Text";
|
|
31
|
+
return Text;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/mocks/components/Image.ts
|
|
35
|
+
function createImageMock() {
|
|
36
|
+
const Image = react.default.forwardRef((props, ref) => {
|
|
37
|
+
return react.default.createElement("Image", {
|
|
38
|
+
...props,
|
|
39
|
+
ref
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
Image.displayName = "Image";
|
|
43
|
+
Image.getSize = vitest.vi.fn((_uri, success, _failure) => {
|
|
44
|
+
Promise.resolve().then(() => success(100, 100));
|
|
45
|
+
});
|
|
46
|
+
Image.getSizeWithHeaders = vitest.vi.fn((_uri, _headers, success, _failure) => {
|
|
47
|
+
Promise.resolve().then(() => success(100, 100));
|
|
48
|
+
});
|
|
49
|
+
Image.prefetch = vitest.vi.fn(() => Promise.resolve(true));
|
|
50
|
+
Image.queryCache = vitest.vi.fn(() => Promise.resolve({}));
|
|
51
|
+
Image.resolveAssetSource = vitest.vi.fn((source) => {
|
|
52
|
+
if (typeof source === "number") return {
|
|
53
|
+
uri: `asset://${source}`,
|
|
54
|
+
width: 100,
|
|
55
|
+
height: 100
|
|
56
|
+
};
|
|
57
|
+
return source;
|
|
58
|
+
});
|
|
59
|
+
return Image;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/mocks/components/TextInput.ts
|
|
63
|
+
function createTextInputMock() {
|
|
64
|
+
const TextInput = react.default.forwardRef((props, ref) => {
|
|
65
|
+
const instanceMethods = {
|
|
66
|
+
focus: vitest.vi.fn(),
|
|
67
|
+
blur: vitest.vi.fn(),
|
|
68
|
+
clear: vitest.vi.fn(),
|
|
69
|
+
isFocused: vitest.vi.fn(() => false),
|
|
70
|
+
setNativeProps: vitest.vi.fn()
|
|
71
|
+
};
|
|
72
|
+
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
73
|
+
return react.default.createElement("TextInput", {
|
|
74
|
+
...props,
|
|
75
|
+
ref
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
TextInput.displayName = "TextInput";
|
|
79
|
+
return TextInput;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/mocks/components/ScrollView.ts
|
|
83
|
+
function createScrollViewMock() {
|
|
84
|
+
const ScrollView = react.default.forwardRef((props, ref) => {
|
|
85
|
+
const instanceMethods = {
|
|
86
|
+
scrollTo: vitest.vi.fn(),
|
|
87
|
+
scrollToEnd: vitest.vi.fn(),
|
|
88
|
+
flashScrollIndicators: vitest.vi.fn(),
|
|
89
|
+
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
90
|
+
getInnerViewNode: vitest.vi.fn(),
|
|
91
|
+
setNativeProps: vitest.vi.fn()
|
|
92
|
+
};
|
|
93
|
+
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
94
|
+
return react.default.createElement("ScrollView", {
|
|
95
|
+
...props,
|
|
96
|
+
ref
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
ScrollView.displayName = "ScrollView";
|
|
100
|
+
return ScrollView;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/mocks/components/FlatList.ts
|
|
104
|
+
function createFlatListMock() {
|
|
105
|
+
const FlatList = react.default.forwardRef((props, ref) => {
|
|
106
|
+
const { data, renderItem, keyExtractor, ListHeaderComponent, ListFooterComponent, ListEmptyComponent, ItemSeparatorComponent, refreshControl, ...rest } = props;
|
|
107
|
+
const instanceMethods = {
|
|
108
|
+
scrollToEnd: vitest.vi.fn(),
|
|
109
|
+
scrollToIndex: vitest.vi.fn(),
|
|
110
|
+
scrollToItem: vitest.vi.fn(),
|
|
111
|
+
scrollToOffset: vitest.vi.fn(),
|
|
112
|
+
recordInteraction: vitest.vi.fn(),
|
|
113
|
+
flashScrollIndicators: vitest.vi.fn(),
|
|
114
|
+
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
115
|
+
getNativeScrollRef: vitest.vi.fn(),
|
|
116
|
+
getScrollableNode: vitest.vi.fn(),
|
|
117
|
+
setNativeProps: vitest.vi.fn()
|
|
118
|
+
};
|
|
119
|
+
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
120
|
+
const children = [];
|
|
121
|
+
if (ListHeaderComponent) children.push(react.default.createElement("FlatList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
122
|
+
if (data && data.length > 0) data.forEach((item, index) => {
|
|
123
|
+
const key = keyExtractor ? keyExtractor(item, index) : String(index);
|
|
124
|
+
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
125
|
+
item,
|
|
126
|
+
index,
|
|
127
|
+
separators: {
|
|
128
|
+
highlight: vitest.vi.fn(),
|
|
129
|
+
unhighlight: vitest.vi.fn(),
|
|
130
|
+
updateProps: vitest.vi.fn()
|
|
131
|
+
}
|
|
132
|
+
})));
|
|
133
|
+
if (ItemSeparatorComponent && index < data.length - 1) children.push(react.default.createElement(react.default.Fragment, { key: `separator-${index}` }, typeof ItemSeparatorComponent === "function" ? react.default.createElement(ItemSeparatorComponent) : ItemSeparatorComponent));
|
|
134
|
+
});
|
|
135
|
+
else if (ListEmptyComponent) children.push(react.default.createElement("FlatList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
136
|
+
if (ListFooterComponent) children.push(react.default.createElement("FlatList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
137
|
+
if (refreshControl) children.unshift(refreshControl);
|
|
138
|
+
return react.default.createElement("FlatList", {
|
|
139
|
+
...rest,
|
|
140
|
+
ref
|
|
141
|
+
}, ...children);
|
|
142
|
+
});
|
|
143
|
+
FlatList.displayName = "FlatList";
|
|
144
|
+
return FlatList;
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/mocks/components/SectionList.ts
|
|
148
|
+
function createSectionListMock() {
|
|
149
|
+
const SectionList = react.default.forwardRef((props, ref) => {
|
|
150
|
+
const { sections, renderItem, renderSectionHeader, renderSectionFooter, keyExtractor, refreshControl, ListEmptyComponent, ListHeaderComponent, ListFooterComponent, ItemSeparatorComponent, SectionSeparatorComponent, ...rest } = props;
|
|
151
|
+
const instanceMethods = {
|
|
152
|
+
scrollToEnd: vitest.vi.fn(),
|
|
153
|
+
scrollToIndex: vitest.vi.fn(),
|
|
154
|
+
scrollToLocation: vitest.vi.fn(),
|
|
155
|
+
recordInteraction: vitest.vi.fn(),
|
|
156
|
+
flashScrollIndicators: vitest.vi.fn(),
|
|
157
|
+
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
158
|
+
getNativeScrollRef: vitest.vi.fn(),
|
|
159
|
+
getScrollableNode: vitest.vi.fn(),
|
|
160
|
+
setNativeProps: vitest.vi.fn()
|
|
161
|
+
};
|
|
162
|
+
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
163
|
+
const children = [];
|
|
164
|
+
if (ListHeaderComponent) children.push(react.default.createElement("SectionList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
165
|
+
if (sections) sections.forEach((section, sectionIndex) => {
|
|
166
|
+
if (renderSectionHeader) children.push(react.default.createElement(react.default.Fragment, { key: `header-${sectionIndex}` }, renderSectionHeader({ section })));
|
|
167
|
+
if (SectionSeparatorComponent && sectionIndex > 0) children.push(react.default.createElement(react.default.Fragment, { key: `section-sep-${sectionIndex}` }, typeof SectionSeparatorComponent === "function" ? react.default.createElement(SectionSeparatorComponent) : SectionSeparatorComponent));
|
|
168
|
+
if (section.data) section.data.forEach((item, index) => {
|
|
169
|
+
const key = keyExtractor ? keyExtractor(item, index) : `${sectionIndex}-${index}`;
|
|
170
|
+
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
171
|
+
item,
|
|
172
|
+
index,
|
|
173
|
+
section,
|
|
174
|
+
separators: {
|
|
175
|
+
highlight: vitest.vi.fn(),
|
|
176
|
+
unhighlight: vitest.vi.fn(),
|
|
177
|
+
updateProps: vitest.vi.fn()
|
|
178
|
+
}
|
|
179
|
+
})));
|
|
180
|
+
if (ItemSeparatorComponent && index < section.data.length - 1) children.push(react.default.createElement(react.default.Fragment, { key: `sep-${sectionIndex}-${index}` }, typeof ItemSeparatorComponent === "function" ? react.default.createElement(ItemSeparatorComponent) : ItemSeparatorComponent));
|
|
181
|
+
});
|
|
182
|
+
if (renderSectionFooter) children.push(react.default.createElement(react.default.Fragment, { key: `footer-${sectionIndex}` }, renderSectionFooter({ section })));
|
|
183
|
+
});
|
|
184
|
+
if (ListFooterComponent) children.push(react.default.createElement("SectionList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
185
|
+
if (refreshControl) children.unshift(refreshControl);
|
|
186
|
+
if ((!sections || sections.length === 0) && ListEmptyComponent) children.push(react.default.createElement("SectionList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
187
|
+
return react.default.createElement("SectionList", {
|
|
188
|
+
...rest,
|
|
189
|
+
ref
|
|
190
|
+
}, ...children);
|
|
191
|
+
});
|
|
192
|
+
SectionList.displayName = "SectionList";
|
|
193
|
+
return SectionList;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/mocks/components/Modal.ts
|
|
197
|
+
function createModalMock() {
|
|
198
|
+
const Modal = react.default.forwardRef((props, ref) => {
|
|
199
|
+
const { visible = true, children, ...rest } = props;
|
|
200
|
+
if (!visible) return null;
|
|
201
|
+
return react.default.createElement("Modal", {
|
|
202
|
+
...rest,
|
|
203
|
+
visible,
|
|
204
|
+
ref
|
|
205
|
+
}, children);
|
|
206
|
+
});
|
|
207
|
+
Modal.displayName = "Modal";
|
|
208
|
+
return Modal;
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/mocks/components/Pressable.ts
|
|
212
|
+
function createPressableMock() {
|
|
213
|
+
const Pressable = react.default.forwardRef((props, ref) => {
|
|
214
|
+
return react.default.createElement("Pressable", {
|
|
215
|
+
...props,
|
|
216
|
+
ref
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
Pressable.displayName = "Pressable";
|
|
220
|
+
return Pressable;
|
|
221
|
+
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/mocks/components/TouchableOpacity.ts
|
|
224
|
+
function createTouchableOpacityMock() {
|
|
225
|
+
const TouchableOpacity = react.default.forwardRef((props, ref) => {
|
|
226
|
+
return react.default.createElement("TouchableOpacity", {
|
|
227
|
+
...props,
|
|
228
|
+
ref
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
TouchableOpacity.displayName = "TouchableOpacity";
|
|
232
|
+
return TouchableOpacity;
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
//#region src/mocks/components/TouchableHighlight.ts
|
|
236
|
+
function createTouchableHighlightMock() {
|
|
237
|
+
const TouchableHighlight = react.default.forwardRef((props, ref) => {
|
|
238
|
+
return react.default.createElement("TouchableHighlight", {
|
|
239
|
+
...props,
|
|
240
|
+
ref
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
TouchableHighlight.displayName = "TouchableHighlight";
|
|
244
|
+
return TouchableHighlight;
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/mocks/components/TouchableWithoutFeedback.ts
|
|
248
|
+
function createTouchableWithoutFeedbackMock() {
|
|
249
|
+
const TouchableWithoutFeedback = react.default.forwardRef((props, ref) => {
|
|
250
|
+
return react.default.createElement("TouchableWithoutFeedback", {
|
|
251
|
+
...props,
|
|
252
|
+
ref
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
TouchableWithoutFeedback.displayName = "TouchableWithoutFeedback";
|
|
256
|
+
return TouchableWithoutFeedback;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/mocks/components/TouchableNativeFeedback.ts
|
|
260
|
+
function createTouchableNativeFeedbackMock() {
|
|
261
|
+
const TouchableNativeFeedback = react.default.forwardRef((props, ref) => {
|
|
262
|
+
return react.default.createElement("TouchableNativeFeedback", {
|
|
263
|
+
...props,
|
|
264
|
+
ref
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
TouchableNativeFeedback.displayName = "TouchableNativeFeedback";
|
|
268
|
+
return TouchableNativeFeedback;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/mocks/components/ActivityIndicator.ts
|
|
272
|
+
function createActivityIndicatorMock() {
|
|
273
|
+
const ActivityIndicator = react.default.forwardRef((props, ref) => {
|
|
274
|
+
return react.default.createElement("ActivityIndicator", {
|
|
275
|
+
...props,
|
|
276
|
+
ref
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
ActivityIndicator.displayName = "ActivityIndicator";
|
|
280
|
+
return ActivityIndicator;
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/mocks/components/Button.ts
|
|
284
|
+
function createButtonMock() {
|
|
285
|
+
function Button(props) {
|
|
286
|
+
const { title, onPress, disabled, color, accessibilityLabel, testID, ...rest } = props;
|
|
287
|
+
return react.default.createElement("View", {
|
|
288
|
+
...rest,
|
|
289
|
+
testID
|
|
290
|
+
}, react.default.createElement("Text", {
|
|
291
|
+
onPress: disabled ? void 0 : onPress,
|
|
292
|
+
accessibilityLabel: accessibilityLabel || title,
|
|
293
|
+
accessibilityRole: "button",
|
|
294
|
+
disabled,
|
|
295
|
+
style: color ? { color } : void 0
|
|
296
|
+
}, title));
|
|
297
|
+
}
|
|
298
|
+
Button.displayName = "Button";
|
|
299
|
+
return Button;
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/mocks/components/Switch.ts
|
|
303
|
+
function createSwitchMock() {
|
|
304
|
+
const Switch = react.default.forwardRef((props, ref) => {
|
|
305
|
+
return react.default.createElement("Switch", {
|
|
306
|
+
...props,
|
|
307
|
+
ref
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
Switch.displayName = "Switch";
|
|
311
|
+
return Switch;
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/mocks/components/RefreshControl.ts
|
|
315
|
+
function createRefreshControlMock() {
|
|
316
|
+
const RefreshControl = react.default.forwardRef((props, ref) => {
|
|
317
|
+
return react.default.createElement("RefreshControl", {
|
|
318
|
+
...props,
|
|
319
|
+
ref
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
RefreshControl.displayName = "RefreshControl";
|
|
323
|
+
return RefreshControl;
|
|
324
|
+
}
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/mocks/components/StatusBar.ts
|
|
327
|
+
function createStatusBarMock() {
|
|
328
|
+
function StatusBar(props) {
|
|
329
|
+
return react.default.createElement("StatusBar", props);
|
|
330
|
+
}
|
|
331
|
+
StatusBar.displayName = "StatusBar";
|
|
332
|
+
StatusBar.setBarStyle = vitest.vi.fn();
|
|
333
|
+
StatusBar.setBackgroundColor = vitest.vi.fn();
|
|
334
|
+
StatusBar.setHidden = vitest.vi.fn();
|
|
335
|
+
StatusBar.setNetworkActivityIndicatorVisible = vitest.vi.fn();
|
|
336
|
+
StatusBar.setTranslucent = vitest.vi.fn();
|
|
337
|
+
StatusBar.pushStackEntry = vitest.vi.fn(() => ({}));
|
|
338
|
+
StatusBar.popStackEntry = vitest.vi.fn();
|
|
339
|
+
StatusBar.replaceStackEntry = vitest.vi.fn(() => ({}));
|
|
340
|
+
StatusBar.currentHeight = 44;
|
|
341
|
+
return StatusBar;
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/mocks/components/SafeAreaView.ts
|
|
345
|
+
function createSafeAreaViewMock() {
|
|
346
|
+
const SafeAreaView = react.default.forwardRef((props, ref) => {
|
|
347
|
+
return react.default.createElement("SafeAreaView", {
|
|
348
|
+
...props,
|
|
349
|
+
ref
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
SafeAreaView.displayName = "SafeAreaView";
|
|
353
|
+
return SafeAreaView;
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/mocks/components/KeyboardAvoidingView.ts
|
|
357
|
+
function createKeyboardAvoidingViewMock() {
|
|
358
|
+
const KeyboardAvoidingView = react.default.forwardRef((props, ref) => {
|
|
359
|
+
return react.default.createElement("KeyboardAvoidingView", {
|
|
360
|
+
...props,
|
|
361
|
+
ref
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
KeyboardAvoidingView.displayName = "KeyboardAvoidingView";
|
|
365
|
+
return KeyboardAvoidingView;
|
|
366
|
+
}
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/mocks/components/ImageBackground.ts
|
|
369
|
+
function createImageBackgroundMock() {
|
|
370
|
+
const ImageBackground = react.default.forwardRef((props, ref) => {
|
|
371
|
+
const { children, style, imageStyle, source, ...rest } = props;
|
|
372
|
+
return react.default.createElement("ImageBackground", {
|
|
373
|
+
...rest,
|
|
374
|
+
ref,
|
|
375
|
+
style
|
|
376
|
+
}, react.default.createElement("Image", {
|
|
377
|
+
source,
|
|
378
|
+
style: imageStyle
|
|
379
|
+
}), children);
|
|
380
|
+
});
|
|
381
|
+
ImageBackground.displayName = "ImageBackground";
|
|
382
|
+
return ImageBackground;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/mocks/components/VirtualizedList.ts
|
|
386
|
+
function createVirtualizedListMock() {
|
|
387
|
+
const VirtualizedList = react.default.forwardRef((props, ref) => {
|
|
388
|
+
const { data, renderItem, keyExtractor, getItemCount, getItem, ListHeaderComponent, ListFooterComponent, ListEmptyComponent, ...rest } = props;
|
|
389
|
+
const instanceMethods = {
|
|
390
|
+
scrollToEnd: vitest.vi.fn(),
|
|
391
|
+
scrollToIndex: vitest.vi.fn(),
|
|
392
|
+
scrollToItem: vitest.vi.fn(),
|
|
393
|
+
scrollToOffset: vitest.vi.fn(),
|
|
394
|
+
recordInteraction: vitest.vi.fn(),
|
|
395
|
+
flashScrollIndicators: vitest.vi.fn(),
|
|
396
|
+
getScrollResponder: vitest.vi.fn(() => ({})),
|
|
397
|
+
getNativeScrollRef: vitest.vi.fn(),
|
|
398
|
+
getScrollableNode: vitest.vi.fn(),
|
|
399
|
+
setNativeProps: vitest.vi.fn()
|
|
400
|
+
};
|
|
401
|
+
react.default.useImperativeHandle(ref, () => instanceMethods);
|
|
402
|
+
const children = [];
|
|
403
|
+
if (ListHeaderComponent) children.push(react.default.createElement("VirtualizedList-Header", { key: "__header" }, typeof ListHeaderComponent === "function" ? react.default.createElement(ListHeaderComponent) : ListHeaderComponent));
|
|
404
|
+
const itemCount = getItemCount ? getItemCount(data) : data ? data.length : 0;
|
|
405
|
+
if (itemCount > 0) for (let index = 0; index < itemCount; index++) {
|
|
406
|
+
const item = getItem ? getItem(data, index) : data[index];
|
|
407
|
+
const key = keyExtractor ? keyExtractor(item, index) : String(index);
|
|
408
|
+
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
409
|
+
item,
|
|
410
|
+
index,
|
|
411
|
+
separators: {}
|
|
412
|
+
})));
|
|
413
|
+
}
|
|
414
|
+
else if (ListEmptyComponent) children.push(react.default.createElement("VirtualizedList-Empty", { key: "__empty" }, typeof ListEmptyComponent === "function" ? react.default.createElement(ListEmptyComponent) : ListEmptyComponent));
|
|
415
|
+
if (ListFooterComponent) children.push(react.default.createElement("VirtualizedList-Footer", { key: "__footer" }, typeof ListFooterComponent === "function" ? react.default.createElement(ListFooterComponent) : ListFooterComponent));
|
|
416
|
+
return react.default.createElement("VirtualizedList", {
|
|
417
|
+
...rest,
|
|
418
|
+
ref
|
|
419
|
+
}, ...children);
|
|
420
|
+
});
|
|
421
|
+
VirtualizedList.displayName = "VirtualizedList";
|
|
422
|
+
return VirtualizedList;
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/mocks/components/InputAccessoryView.ts
|
|
426
|
+
function createInputAccessoryViewMock() {
|
|
427
|
+
const InputAccessoryView = react.default.forwardRef((props, ref) => {
|
|
428
|
+
return react.default.createElement("InputAccessoryView", {
|
|
429
|
+
...props,
|
|
430
|
+
ref
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
InputAccessoryView.displayName = "InputAccessoryView";
|
|
434
|
+
return InputAccessoryView;
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/mocks/components/DrawerLayoutAndroid.ts
|
|
438
|
+
function createDrawerLayoutAndroidMock() {
|
|
439
|
+
const DrawerLayoutAndroid = react.default.forwardRef((props, ref) => {
|
|
440
|
+
const { children, ...rest } = props;
|
|
441
|
+
return react.default.createElement("DrawerLayoutAndroid", {
|
|
442
|
+
...rest,
|
|
443
|
+
ref
|
|
444
|
+
}, children);
|
|
445
|
+
});
|
|
446
|
+
DrawerLayoutAndroid.displayName = "DrawerLayoutAndroid";
|
|
447
|
+
return DrawerLayoutAndroid;
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/mocks/apis/Platform.ts
|
|
451
|
+
function createPlatformMock(os = "ios") {
|
|
452
|
+
return {
|
|
453
|
+
OS: os,
|
|
454
|
+
Version: os === "ios" ? "17.0" : 34,
|
|
455
|
+
isPad: false,
|
|
456
|
+
isTVOS: false,
|
|
457
|
+
isTV: false,
|
|
458
|
+
isVision: false,
|
|
459
|
+
isTesting: true,
|
|
460
|
+
select: vitest.vi.fn((specifics) => {
|
|
461
|
+
return specifics[os] ?? specifics.default;
|
|
462
|
+
}),
|
|
463
|
+
constants: {
|
|
464
|
+
reactNativeVersion: {
|
|
465
|
+
major: 0,
|
|
466
|
+
minor: 76,
|
|
467
|
+
patch: 0
|
|
468
|
+
},
|
|
469
|
+
osVersion: os === "ios" ? 17 : 34,
|
|
470
|
+
systemName: os === "ios" ? "iOS" : "Android",
|
|
471
|
+
isTesting: true
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/mocks/apis/Dimensions.ts
|
|
477
|
+
function createDimensionsMock() {
|
|
478
|
+
const defaults = {
|
|
479
|
+
window: {
|
|
480
|
+
width: 390,
|
|
481
|
+
height: 844,
|
|
482
|
+
scale: 3,
|
|
483
|
+
fontScale: 1
|
|
484
|
+
},
|
|
485
|
+
screen: {
|
|
486
|
+
width: 390,
|
|
487
|
+
height: 844,
|
|
488
|
+
scale: 3,
|
|
489
|
+
fontScale: 1
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const state = {
|
|
493
|
+
window: { ...defaults.window },
|
|
494
|
+
screen: { ...defaults.screen }
|
|
495
|
+
};
|
|
496
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
497
|
+
return {
|
|
498
|
+
get: vitest.vi.fn((dim) => ({ ...state[dim] })),
|
|
499
|
+
set: vitest.vi.fn((dims) => {
|
|
500
|
+
for (const [key, value] of Object.entries(dims)) if (key in state && value) Object.assign(state[key], value);
|
|
501
|
+
listeners.forEach((fn) => fn({
|
|
502
|
+
window: { ...state.window },
|
|
503
|
+
screen: { ...state.screen }
|
|
504
|
+
}));
|
|
505
|
+
}),
|
|
506
|
+
addEventListener: vitest.vi.fn((_type, handler) => {
|
|
507
|
+
listeners.add(handler);
|
|
508
|
+
return { remove: () => listeners.delete(handler) };
|
|
509
|
+
}),
|
|
510
|
+
_reset: () => {
|
|
511
|
+
Object.assign(state.window, defaults.window);
|
|
512
|
+
Object.assign(state.screen, defaults.screen);
|
|
513
|
+
listeners.clear();
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/mocks/apis/StyleSheet.ts
|
|
519
|
+
function createStyleSheetMock() {
|
|
520
|
+
return {
|
|
521
|
+
create: vitest.vi.fn((styles) => {
|
|
522
|
+
return styles;
|
|
523
|
+
}),
|
|
524
|
+
flatten: vitest.vi.fn((...args) => Object.assign({}, ...args.flat(Infinity).filter(Boolean))),
|
|
525
|
+
compose: vitest.vi.fn((a, b) => [a, b]),
|
|
526
|
+
absoluteFill: {
|
|
527
|
+
position: "absolute",
|
|
528
|
+
left: 0,
|
|
529
|
+
right: 0,
|
|
530
|
+
top: 0,
|
|
531
|
+
bottom: 0
|
|
532
|
+
},
|
|
533
|
+
absoluteFillObject: {
|
|
534
|
+
position: "absolute",
|
|
535
|
+
left: 0,
|
|
536
|
+
right: 0,
|
|
537
|
+
top: 0,
|
|
538
|
+
bottom: 0
|
|
539
|
+
},
|
|
540
|
+
hairlineWidth: .5,
|
|
541
|
+
setStyleAttributePreprocessor: vitest.vi.fn()
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/mocks/apis/Animated.ts
|
|
546
|
+
var AnimatedValue = class AnimatedValue {
|
|
547
|
+
_value;
|
|
548
|
+
_listeners = /* @__PURE__ */ new Map();
|
|
549
|
+
_listenerIdCounter = 0;
|
|
550
|
+
constructor(value = 0) {
|
|
551
|
+
this._value = value;
|
|
552
|
+
}
|
|
553
|
+
setValue(value) {
|
|
554
|
+
this._value = value;
|
|
555
|
+
this._listeners.forEach((fn) => fn({ value }));
|
|
556
|
+
}
|
|
557
|
+
getValue() {
|
|
558
|
+
return this._value;
|
|
559
|
+
}
|
|
560
|
+
addListener(callback) {
|
|
561
|
+
const id = String(++this._listenerIdCounter);
|
|
562
|
+
this._listeners.set(id, callback);
|
|
563
|
+
return id;
|
|
564
|
+
}
|
|
565
|
+
removeListener(id) {
|
|
566
|
+
this._listeners.delete(id);
|
|
567
|
+
}
|
|
568
|
+
removeAllListeners() {
|
|
569
|
+
this._listeners.clear();
|
|
570
|
+
}
|
|
571
|
+
interpolate(config) {
|
|
572
|
+
const { inputRange, outputRange } = config || {};
|
|
573
|
+
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(this._value);
|
|
574
|
+
const val = Math.max(inputRange[0], Math.min(inputRange[inputRange.length - 1], this._value));
|
|
575
|
+
let i = 0;
|
|
576
|
+
for (; i < inputRange.length - 2; i++) if (val <= inputRange[i + 1]) break;
|
|
577
|
+
const inMin = inputRange[i];
|
|
578
|
+
const inMax = inputRange[i + 1];
|
|
579
|
+
const outMin = typeof outputRange[i] === "number" ? outputRange[i] : parseFloat(outputRange[i]) || 0;
|
|
580
|
+
const outMax = typeof outputRange[i + 1] === "number" ? outputRange[i + 1] : parseFloat(outputRange[i + 1]) || 0;
|
|
581
|
+
return new AnimatedValue(outMin + (inMax === inMin ? 0 : (val - inMin) / (inMax - inMin)) * (outMax - outMin));
|
|
582
|
+
}
|
|
583
|
+
stopAnimation(callback) {
|
|
584
|
+
callback?.(this._value);
|
|
585
|
+
}
|
|
586
|
+
resetAnimation(callback) {
|
|
587
|
+
callback?.(this._value);
|
|
588
|
+
}
|
|
589
|
+
setOffset(_offset) {}
|
|
590
|
+
flattenOffset() {}
|
|
591
|
+
extractOffset() {}
|
|
592
|
+
};
|
|
593
|
+
var AnimatedValueXY = class {
|
|
594
|
+
x;
|
|
595
|
+
y;
|
|
596
|
+
constructor(value) {
|
|
597
|
+
this.x = new AnimatedValue(value?.x ?? 0);
|
|
598
|
+
this.y = new AnimatedValue(value?.y ?? 0);
|
|
599
|
+
}
|
|
600
|
+
setValue(value) {
|
|
601
|
+
this.x.setValue(value.x);
|
|
602
|
+
this.y.setValue(value.y);
|
|
603
|
+
}
|
|
604
|
+
setOffset(_offset) {}
|
|
605
|
+
flattenOffset() {}
|
|
606
|
+
extractOffset() {}
|
|
607
|
+
stopAnimation(callback) {
|
|
608
|
+
callback?.({
|
|
609
|
+
x: this.x.getValue(),
|
|
610
|
+
y: this.y.getValue()
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
resetAnimation(callback) {
|
|
614
|
+
callback?.({
|
|
615
|
+
x: this.x.getValue(),
|
|
616
|
+
y: this.y.getValue()
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
addListener(_callback) {
|
|
620
|
+
return {
|
|
621
|
+
x: this.x.addListener(() => {}),
|
|
622
|
+
y: this.y.addListener(() => {})
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
removeListener(id) {
|
|
626
|
+
this.x.removeListener(id.x);
|
|
627
|
+
this.y.removeListener(id.y);
|
|
628
|
+
}
|
|
629
|
+
getLayout() {
|
|
630
|
+
return {
|
|
631
|
+
left: this.x,
|
|
632
|
+
top: this.y
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
getTranslateTransform() {
|
|
636
|
+
return [{ translateX: this.x }, { translateY: this.y }];
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
var AnimatedColor = class {
|
|
640
|
+
r;
|
|
641
|
+
g;
|
|
642
|
+
b;
|
|
643
|
+
a;
|
|
644
|
+
constructor() {
|
|
645
|
+
this.r = new AnimatedValue(0);
|
|
646
|
+
this.g = new AnimatedValue(0);
|
|
647
|
+
this.b = new AnimatedValue(0);
|
|
648
|
+
this.a = new AnimatedValue(1);
|
|
649
|
+
}
|
|
650
|
+
setValue(_value) {}
|
|
651
|
+
setOffset(_offset) {}
|
|
652
|
+
flattenOffset() {}
|
|
653
|
+
stopAnimation(callback) {
|
|
654
|
+
callback?.(0);
|
|
655
|
+
}
|
|
656
|
+
resetAnimation(callback) {
|
|
657
|
+
callback?.(0);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
function createAnimation() {
|
|
661
|
+
return {
|
|
662
|
+
start: vitest.vi.fn((callback) => {
|
|
663
|
+
callback?.({ finished: true });
|
|
664
|
+
}),
|
|
665
|
+
stop: vitest.vi.fn(),
|
|
666
|
+
reset: vitest.vi.fn()
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function createAnimatedWrapper(displayName) {
|
|
670
|
+
const Component = react.default.forwardRef((props, ref) => {
|
|
671
|
+
return react.default.createElement(displayName, {
|
|
672
|
+
...props,
|
|
673
|
+
ref
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
Component.displayName = displayName;
|
|
677
|
+
return Component;
|
|
678
|
+
}
|
|
679
|
+
function createAnimatedMock() {
|
|
680
|
+
return {
|
|
681
|
+
Value: AnimatedValue,
|
|
682
|
+
ValueXY: AnimatedValueXY,
|
|
683
|
+
Color: AnimatedColor,
|
|
684
|
+
timing: vitest.vi.fn((_value, _config) => createAnimation()),
|
|
685
|
+
spring: vitest.vi.fn((_value, _config) => createAnimation()),
|
|
686
|
+
decay: vitest.vi.fn((_value, _config) => createAnimation()),
|
|
687
|
+
sequence: vitest.vi.fn((_animations) => createAnimation()),
|
|
688
|
+
parallel: vitest.vi.fn((_animations) => createAnimation()),
|
|
689
|
+
stagger: vitest.vi.fn((_time, _animations) => createAnimation()),
|
|
690
|
+
loop: vitest.vi.fn((_animation, _config) => createAnimation()),
|
|
691
|
+
delay: vitest.vi.fn((_time) => createAnimation()),
|
|
692
|
+
add: vitest.vi.fn((a, b) => {
|
|
693
|
+
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) + (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
694
|
+
}),
|
|
695
|
+
subtract: vitest.vi.fn((a, b) => {
|
|
696
|
+
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) - (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
697
|
+
}),
|
|
698
|
+
multiply: vitest.vi.fn((a, b) => {
|
|
699
|
+
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) * (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
700
|
+
}),
|
|
701
|
+
divide: vitest.vi.fn((a, b) => {
|
|
702
|
+
const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
|
|
703
|
+
const bVal = b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0;
|
|
704
|
+
return new AnimatedValue(bVal === 0 ? 0 : aVal / bVal);
|
|
705
|
+
}),
|
|
706
|
+
modulo: vitest.vi.fn((a, modulus) => {
|
|
707
|
+
return new AnimatedValue(((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) % modulus + modulus) % modulus);
|
|
708
|
+
}),
|
|
709
|
+
diffClamp: vitest.vi.fn((a, min, max) => {
|
|
710
|
+
const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
|
|
711
|
+
return new AnimatedValue(Math.min(Math.max(aVal, min), max));
|
|
712
|
+
}),
|
|
713
|
+
event: vitest.vi.fn((_argMapping, _config) => vitest.vi.fn()),
|
|
714
|
+
forkEvent: vitest.vi.fn(),
|
|
715
|
+
unforkEvent: vitest.vi.fn(),
|
|
716
|
+
createAnimatedComponent: vitest.vi.fn((component) => {
|
|
717
|
+
const Wrapper = react.default.forwardRef((props, ref) => {
|
|
718
|
+
return react.default.createElement(component, {
|
|
719
|
+
...props,
|
|
720
|
+
ref
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
Wrapper.displayName = `Animated(${component.displayName || component.name || "Component"})`;
|
|
724
|
+
return Wrapper;
|
|
725
|
+
}),
|
|
726
|
+
View: createAnimatedWrapper("Animated.View"),
|
|
727
|
+
Text: createAnimatedWrapper("Animated.Text"),
|
|
728
|
+
Image: createAnimatedWrapper("Animated.Image"),
|
|
729
|
+
ScrollView: createAnimatedWrapper("Animated.ScrollView"),
|
|
730
|
+
FlatList: createAnimatedWrapper("Animated.FlatList"),
|
|
731
|
+
SectionList: createAnimatedWrapper("Animated.SectionList")
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/mocks/apis/Alert.ts
|
|
736
|
+
function createAlertMock() {
|
|
737
|
+
return {
|
|
738
|
+
alert: vitest.vi.fn(),
|
|
739
|
+
prompt: vitest.vi.fn()
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/mocks/apis/Linking.ts
|
|
744
|
+
function createLinkingMock() {
|
|
745
|
+
return {
|
|
746
|
+
openURL: vitest.vi.fn(() => Promise.resolve()),
|
|
747
|
+
canOpenURL: vitest.vi.fn(() => Promise.resolve(true)),
|
|
748
|
+
getInitialURL: vitest.vi.fn(() => Promise.resolve(null)),
|
|
749
|
+
openSettings: vitest.vi.fn(() => Promise.resolve()),
|
|
750
|
+
sendIntent: vitest.vi.fn(() => Promise.resolve()),
|
|
751
|
+
addEventListener: vitest.vi.fn(() => ({ remove: vitest.vi.fn() }))
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
//#endregion
|
|
755
|
+
//#region src/mocks/apis/AppState.ts
|
|
756
|
+
function createAppStateMock() {
|
|
757
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
758
|
+
const mock = {
|
|
759
|
+
currentState: "active",
|
|
760
|
+
isAvailable: true,
|
|
761
|
+
addEventListener: vitest.vi.fn((type, handler) => {
|
|
762
|
+
if (!listeners.has(type)) listeners.set(type, /* @__PURE__ */ new Set());
|
|
763
|
+
listeners.get(type).add(handler);
|
|
764
|
+
return { remove: vitest.vi.fn(() => listeners.get(type)?.delete(handler)) };
|
|
765
|
+
}),
|
|
766
|
+
_setState: (state) => {
|
|
767
|
+
mock.currentState = state;
|
|
768
|
+
listeners.get("change")?.forEach((fn) => fn(state));
|
|
769
|
+
},
|
|
770
|
+
_reset: () => {
|
|
771
|
+
mock.currentState = "active";
|
|
772
|
+
listeners.clear();
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
return mock;
|
|
776
|
+
}
|
|
777
|
+
//#endregion
|
|
778
|
+
//#region src/mocks/apis/Keyboard.ts
|
|
779
|
+
function createKeyboardMock() {
|
|
780
|
+
let visible = false;
|
|
781
|
+
let keyboardHeight = 0;
|
|
782
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
783
|
+
return {
|
|
784
|
+
dismiss: vitest.vi.fn(() => {
|
|
785
|
+
visible = false;
|
|
786
|
+
keyboardHeight = 0;
|
|
787
|
+
}),
|
|
788
|
+
addListener: vitest.vi.fn((event, handler) => {
|
|
789
|
+
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
790
|
+
listeners.get(event).add(handler);
|
|
791
|
+
return { remove: vitest.vi.fn(() => listeners.get(event)?.delete(handler)) };
|
|
792
|
+
}),
|
|
793
|
+
removeListener: vitest.vi.fn((event, handler) => {
|
|
794
|
+
listeners.get(event)?.delete(handler);
|
|
795
|
+
}),
|
|
796
|
+
removeAllListeners: vitest.vi.fn((event) => {
|
|
797
|
+
if (event) listeners.delete(event);
|
|
798
|
+
else listeners.clear();
|
|
799
|
+
}),
|
|
800
|
+
isVisible: vitest.vi.fn(() => visible),
|
|
801
|
+
metrics: vitest.vi.fn(() => visible ? {
|
|
802
|
+
screenX: 0,
|
|
803
|
+
screenY: 844 - keyboardHeight,
|
|
804
|
+
width: 390,
|
|
805
|
+
height: keyboardHeight
|
|
806
|
+
} : void 0),
|
|
807
|
+
scheduleLayoutAnimation: vitest.vi.fn(),
|
|
808
|
+
_show: (height = 336) => {
|
|
809
|
+
visible = true;
|
|
810
|
+
keyboardHeight = height;
|
|
811
|
+
listeners.get("keyboardDidShow")?.forEach((fn) => fn({ endCoordinates: {
|
|
812
|
+
screenX: 0,
|
|
813
|
+
screenY: 844 - height,
|
|
814
|
+
width: 390,
|
|
815
|
+
height
|
|
816
|
+
} }));
|
|
817
|
+
},
|
|
818
|
+
_hide: () => {
|
|
819
|
+
visible = false;
|
|
820
|
+
keyboardHeight = 0;
|
|
821
|
+
listeners.get("keyboardDidHide")?.forEach((fn) => fn({}));
|
|
822
|
+
},
|
|
823
|
+
_reset: () => {
|
|
824
|
+
visible = false;
|
|
825
|
+
keyboardHeight = 0;
|
|
826
|
+
listeners.clear();
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/mocks/apis/BackHandler.ts
|
|
832
|
+
function createBackHandlerMock() {
|
|
833
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
834
|
+
return {
|
|
835
|
+
exitApp: vitest.vi.fn(),
|
|
836
|
+
addEventListener: vitest.vi.fn((event, handler) => {
|
|
837
|
+
if (event === "hardwareBackPress") listeners.add(handler);
|
|
838
|
+
return { remove: vitest.vi.fn(() => listeners.delete(handler)) };
|
|
839
|
+
}),
|
|
840
|
+
_simulateBackPress: () => {
|
|
841
|
+
const handlers = [...listeners].reverse();
|
|
842
|
+
for (const handler of handlers) if (handler() === true) return;
|
|
843
|
+
},
|
|
844
|
+
_reset: () => {
|
|
845
|
+
listeners.clear();
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
//#endregion
|
|
850
|
+
//#region src/mocks/apis/Vibration.ts
|
|
851
|
+
function createVibrationMock() {
|
|
852
|
+
return {
|
|
853
|
+
vibrate: vitest.vi.fn(),
|
|
854
|
+
cancel: vitest.vi.fn()
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/mocks/apis/PermissionsAndroid.ts
|
|
859
|
+
function createPermissionsAndroidMock() {
|
|
860
|
+
return {
|
|
861
|
+
PERMISSIONS: {
|
|
862
|
+
ACCEPT_HANDOVER: "android.permission.ACCEPT_HANDOVER",
|
|
863
|
+
ACCESS_BACKGROUND_LOCATION: "android.permission.ACCESS_BACKGROUND_LOCATION",
|
|
864
|
+
ACCESS_COARSE_LOCATION: "android.permission.ACCESS_COARSE_LOCATION",
|
|
865
|
+
ACCESS_FINE_LOCATION: "android.permission.ACCESS_FINE_LOCATION",
|
|
866
|
+
ACCESS_MEDIA_LOCATION: "android.permission.ACCESS_MEDIA_LOCATION",
|
|
867
|
+
ACTIVITY_RECOGNITION: "android.permission.ACTIVITY_RECOGNITION",
|
|
868
|
+
BLUETOOTH_ADVERTISE: "android.permission.BLUETOOTH_ADVERTISE",
|
|
869
|
+
BLUETOOTH_CONNECT: "android.permission.BLUETOOTH_CONNECT",
|
|
870
|
+
BLUETOOTH_SCAN: "android.permission.BLUETOOTH_SCAN",
|
|
871
|
+
BODY_SENSORS: "android.permission.BODY_SENSORS",
|
|
872
|
+
BODY_SENSORS_BACKGROUND: "android.permission.BODY_SENSORS_BACKGROUND",
|
|
873
|
+
CALL_PHONE: "android.permission.CALL_PHONE",
|
|
874
|
+
CAMERA: "android.permission.CAMERA",
|
|
875
|
+
GET_ACCOUNTS: "android.permission.GET_ACCOUNTS",
|
|
876
|
+
NEARBY_WIFI_DEVICES: "android.permission.NEARBY_WIFI_DEVICES",
|
|
877
|
+
POST_NOTIFICATIONS: "android.permission.POST_NOTIFICATIONS",
|
|
878
|
+
PROCESS_OUTGOING_CALLS: "android.permission.PROCESS_OUTGOING_CALLS",
|
|
879
|
+
READ_CALENDAR: "android.permission.READ_CALENDAR",
|
|
880
|
+
READ_CALL_LOG: "android.permission.READ_CALL_LOG",
|
|
881
|
+
READ_CONTACTS: "android.permission.READ_CONTACTS",
|
|
882
|
+
READ_EXTERNAL_STORAGE: "android.permission.READ_EXTERNAL_STORAGE",
|
|
883
|
+
READ_MEDIA_AUDIO: "android.permission.READ_MEDIA_AUDIO",
|
|
884
|
+
READ_MEDIA_IMAGES: "android.permission.READ_MEDIA_IMAGES",
|
|
885
|
+
READ_MEDIA_VIDEO: "android.permission.READ_MEDIA_VIDEO",
|
|
886
|
+
READ_PHONE_NUMBERS: "android.permission.READ_PHONE_NUMBERS",
|
|
887
|
+
READ_PHONE_STATE: "android.permission.READ_PHONE_STATE",
|
|
888
|
+
READ_SMS: "android.permission.READ_SMS",
|
|
889
|
+
RECEIVE_MMS: "android.permission.RECEIVE_MMS",
|
|
890
|
+
RECEIVE_SMS: "android.permission.RECEIVE_SMS",
|
|
891
|
+
RECEIVE_WAP_PUSH: "android.permission.RECEIVE_WAP_PUSH",
|
|
892
|
+
RECORD_AUDIO: "android.permission.RECORD_AUDIO",
|
|
893
|
+
SEND_SMS: "android.permission.SEND_SMS",
|
|
894
|
+
USE_SIP: "android.permission.USE_SIP",
|
|
895
|
+
WRITE_CALENDAR: "android.permission.WRITE_CALENDAR",
|
|
896
|
+
WRITE_CALL_LOG: "android.permission.WRITE_CALL_LOG",
|
|
897
|
+
WRITE_CONTACTS: "android.permission.WRITE_CONTACTS",
|
|
898
|
+
WRITE_EXTERNAL_STORAGE: "android.permission.WRITE_EXTERNAL_STORAGE"
|
|
899
|
+
},
|
|
900
|
+
RESULTS: {
|
|
901
|
+
GRANTED: "granted",
|
|
902
|
+
DENIED: "denied",
|
|
903
|
+
NEVER_ASK_AGAIN: "never_ask_again"
|
|
904
|
+
},
|
|
905
|
+
check: vitest.vi.fn(() => Promise.resolve(true)),
|
|
906
|
+
request: vitest.vi.fn(() => Promise.resolve("granted")),
|
|
907
|
+
requestMultiple: vitest.vi.fn((permissions) => Promise.resolve(permissions.reduce((acc, p) => ({
|
|
908
|
+
...acc,
|
|
909
|
+
[p]: "granted"
|
|
910
|
+
}), {})))
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
//#endregion
|
|
914
|
+
//#region src/mocks/apis/Appearance.ts
|
|
915
|
+
function createAppearanceMock() {
|
|
916
|
+
let colorScheme = "light";
|
|
917
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
918
|
+
return {
|
|
919
|
+
getColorScheme: vitest.vi.fn(() => colorScheme),
|
|
920
|
+
setColorScheme: vitest.vi.fn((scheme) => {
|
|
921
|
+
colorScheme = scheme;
|
|
922
|
+
listeners.forEach((fn) => fn({ colorScheme: scheme }));
|
|
923
|
+
}),
|
|
924
|
+
addChangeListener: vitest.vi.fn((listener) => {
|
|
925
|
+
listeners.add(listener);
|
|
926
|
+
return { remove: () => {
|
|
927
|
+
listeners.delete(listener);
|
|
928
|
+
} };
|
|
929
|
+
}),
|
|
930
|
+
_reset: () => {
|
|
931
|
+
colorScheme = "light";
|
|
932
|
+
listeners.clear();
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
//#endregion
|
|
937
|
+
//#region src/mocks/apis/PixelRatio.ts
|
|
938
|
+
function createPixelRatioMock() {
|
|
939
|
+
return {
|
|
940
|
+
get: vitest.vi.fn(() => 3),
|
|
941
|
+
getFontScale: vitest.vi.fn(() => 1),
|
|
942
|
+
getPixelSizeForLayoutSize: vitest.vi.fn((layoutSize) => Math.round(layoutSize * 3)),
|
|
943
|
+
roundToNearestPixel: vitest.vi.fn((layoutSize) => Math.round(layoutSize * 3) / 3)
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
//#endregion
|
|
947
|
+
//#region src/mocks/apis/LayoutAnimation.ts
|
|
948
|
+
function createLayoutAnimationMock() {
|
|
949
|
+
return {
|
|
950
|
+
configureNext: vitest.vi.fn(),
|
|
951
|
+
create: vitest.vi.fn(() => ({
|
|
952
|
+
duration: 300,
|
|
953
|
+
create: {
|
|
954
|
+
type: "easeInEaseOut",
|
|
955
|
+
property: "opacity"
|
|
956
|
+
},
|
|
957
|
+
update: { type: "easeInEaseOut" },
|
|
958
|
+
delete: {
|
|
959
|
+
type: "easeInEaseOut",
|
|
960
|
+
property: "opacity"
|
|
961
|
+
}
|
|
962
|
+
})),
|
|
963
|
+
Types: {
|
|
964
|
+
spring: "spring",
|
|
965
|
+
linear: "linear",
|
|
966
|
+
easeInEaseOut: "easeInEaseOut",
|
|
967
|
+
easeIn: "easeIn",
|
|
968
|
+
easeOut: "easeOut"
|
|
969
|
+
},
|
|
970
|
+
Properties: {
|
|
971
|
+
opacity: "opacity",
|
|
972
|
+
scaleX: "scaleX",
|
|
973
|
+
scaleY: "scaleY",
|
|
974
|
+
scaleXY: "scaleXY"
|
|
975
|
+
},
|
|
976
|
+
Presets: {
|
|
977
|
+
easeInEaseOut: {
|
|
978
|
+
duration: 300,
|
|
979
|
+
create: {
|
|
980
|
+
type: "easeInEaseOut",
|
|
981
|
+
property: "opacity"
|
|
982
|
+
},
|
|
983
|
+
update: { type: "easeInEaseOut" },
|
|
984
|
+
delete: {
|
|
985
|
+
type: "easeInEaseOut",
|
|
986
|
+
property: "opacity"
|
|
987
|
+
}
|
|
988
|
+
},
|
|
989
|
+
linear: {
|
|
990
|
+
duration: 500,
|
|
991
|
+
create: {
|
|
992
|
+
type: "linear",
|
|
993
|
+
property: "opacity"
|
|
994
|
+
},
|
|
995
|
+
update: { type: "linear" },
|
|
996
|
+
delete: {
|
|
997
|
+
type: "linear",
|
|
998
|
+
property: "opacity"
|
|
999
|
+
}
|
|
1000
|
+
},
|
|
1001
|
+
spring: {
|
|
1002
|
+
duration: 700,
|
|
1003
|
+
create: {
|
|
1004
|
+
type: "linear",
|
|
1005
|
+
property: "opacity"
|
|
1006
|
+
},
|
|
1007
|
+
update: {
|
|
1008
|
+
type: "spring",
|
|
1009
|
+
springDamping: .4
|
|
1010
|
+
},
|
|
1011
|
+
delete: {
|
|
1012
|
+
type: "linear",
|
|
1013
|
+
property: "opacity"
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region src/mocks/apis/Clipboard.ts
|
|
1021
|
+
function createClipboardMock() {
|
|
1022
|
+
let content = "";
|
|
1023
|
+
return {
|
|
1024
|
+
getString: vitest.vi.fn(() => Promise.resolve(content)),
|
|
1025
|
+
setString: vitest.vi.fn((text) => {
|
|
1026
|
+
content = text;
|
|
1027
|
+
}),
|
|
1028
|
+
hasString: vitest.vi.fn(() => Promise.resolve(content.length > 0))
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
//#endregion
|
|
1032
|
+
//#region src/mocks/apis/Share.ts
|
|
1033
|
+
function createShareMock() {
|
|
1034
|
+
return {
|
|
1035
|
+
share: vitest.vi.fn(async () => ({ action: "sharedAction" })),
|
|
1036
|
+
sharedAction: "sharedAction",
|
|
1037
|
+
dismissedAction: "dismissedAction"
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/mocks/apis/AccessibilityInfo.ts
|
|
1042
|
+
function createAccessibilityInfoMock() {
|
|
1043
|
+
return {
|
|
1044
|
+
isScreenReaderEnabled: vitest.vi.fn(async () => false),
|
|
1045
|
+
isBoldTextEnabled: vitest.vi.fn(async () => false),
|
|
1046
|
+
isGrayscaleEnabled: vitest.vi.fn(async () => false),
|
|
1047
|
+
isInvertColorsEnabled: vitest.vi.fn(async () => false),
|
|
1048
|
+
isReduceMotionEnabled: vitest.vi.fn(async () => false),
|
|
1049
|
+
isReduceTransparencyEnabled: vitest.vi.fn(async () => false),
|
|
1050
|
+
prefersCrossFadeTransitions: vitest.vi.fn(async () => false),
|
|
1051
|
+
addEventListener: vitest.vi.fn((_eventName, _handler) => ({ remove: vitest.vi.fn() })),
|
|
1052
|
+
announceForAccessibility: vitest.vi.fn(),
|
|
1053
|
+
announceForAccessibilityWithOptions: vitest.vi.fn(),
|
|
1054
|
+
setAccessibilityFocus: vitest.vi.fn(),
|
|
1055
|
+
sendAccessibilityEvent: vitest.vi.fn(),
|
|
1056
|
+
getRecommendedTimeoutMillis: vitest.vi.fn(async (originalTimeout) => originalTimeout)
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/mocks/apis/InteractionManager.ts
|
|
1061
|
+
function createInteractionManagerMock() {
|
|
1062
|
+
return {
|
|
1063
|
+
runAfterInteractions: vitest.vi.fn((task) => {
|
|
1064
|
+
(typeof task === "function" ? task : task?.gen)?.();
|
|
1065
|
+
const promise = Promise.resolve();
|
|
1066
|
+
return {
|
|
1067
|
+
then: promise.then.bind(promise),
|
|
1068
|
+
done: promise.then.bind(promise),
|
|
1069
|
+
cancel: vitest.vi.fn()
|
|
1070
|
+
};
|
|
1071
|
+
}),
|
|
1072
|
+
createInteractionHandle: vitest.vi.fn(() => 1),
|
|
1073
|
+
clearInteractionHandle: vitest.vi.fn(),
|
|
1074
|
+
setDeadline: vitest.vi.fn()
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/mocks/apis/PanResponder.ts
|
|
1079
|
+
function createPanResponderMock() {
|
|
1080
|
+
return { create: vitest.vi.fn((config = {}) => ({ panHandlers: {
|
|
1081
|
+
onStartShouldSetResponder: config.onStartShouldSetPanResponder ? vitest.vi.fn((...args) => config.onStartShouldSetPanResponder(...args)) : vitest.vi.fn(() => false),
|
|
1082
|
+
onMoveShouldSetResponder: config.onMoveShouldSetPanResponder ? vitest.vi.fn((...args) => config.onMoveShouldSetPanResponder(...args)) : vitest.vi.fn(() => false),
|
|
1083
|
+
onStartShouldSetResponderCapture: config.onStartShouldSetPanResponderCapture ? vitest.vi.fn((...args) => config.onStartShouldSetPanResponderCapture(...args)) : vitest.vi.fn(() => false),
|
|
1084
|
+
onMoveShouldSetResponderCapture: config.onMoveShouldSetPanResponderCapture ? vitest.vi.fn((...args) => config.onMoveShouldSetPanResponderCapture(...args)) : vitest.vi.fn(() => false),
|
|
1085
|
+
onResponderGrant: config.onPanResponderGrant ?? vitest.vi.fn(),
|
|
1086
|
+
onResponderReject: config.onPanResponderReject ?? vitest.vi.fn(),
|
|
1087
|
+
onResponderStart: config.onPanResponderStart ?? vitest.vi.fn(),
|
|
1088
|
+
onResponderMove: config.onPanResponderMove ?? vitest.vi.fn(),
|
|
1089
|
+
onResponderEnd: config.onPanResponderEnd ?? vitest.vi.fn(),
|
|
1090
|
+
onResponderRelease: config.onPanResponderRelease ?? vitest.vi.fn(),
|
|
1091
|
+
onResponderTerminate: config.onPanResponderTerminate ?? vitest.vi.fn(),
|
|
1092
|
+
onResponderTerminationRequest: config.onPanResponderTerminationRequest ?? vitest.vi.fn(() => true)
|
|
1093
|
+
} })) };
|
|
1094
|
+
}
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region src/mocks/apis/ToastAndroid.ts
|
|
1097
|
+
function createToastAndroidMock() {
|
|
1098
|
+
return {
|
|
1099
|
+
show: vitest.vi.fn(),
|
|
1100
|
+
showWithGravity: vitest.vi.fn(),
|
|
1101
|
+
showWithGravityAndOffset: vitest.vi.fn(),
|
|
1102
|
+
SHORT: 0,
|
|
1103
|
+
LONG: 1,
|
|
1104
|
+
TOP: 0,
|
|
1105
|
+
BOTTOM: 1,
|
|
1106
|
+
CENTER: 2
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
//#endregion
|
|
1110
|
+
//#region src/mocks/apis/ActionSheetIOS.ts
|
|
1111
|
+
function createActionSheetIOSMock() {
|
|
1112
|
+
return {
|
|
1113
|
+
showActionSheetWithOptions: vitest.vi.fn(),
|
|
1114
|
+
showShareActionSheetWithOptions: vitest.vi.fn()
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
//#endregion
|
|
1118
|
+
//#region src/mocks/apis/LogBox.ts
|
|
1119
|
+
function createLogBoxMock() {
|
|
1120
|
+
return {
|
|
1121
|
+
ignoreLogs: vitest.vi.fn(),
|
|
1122
|
+
ignoreAllLogs: vitest.vi.fn(),
|
|
1123
|
+
uninstall: vitest.vi.fn(),
|
|
1124
|
+
install: vitest.vi.fn()
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/mocks/apis/Easing.ts
|
|
1129
|
+
function createEasingMock() {
|
|
1130
|
+
return {
|
|
1131
|
+
linear: vitest.vi.fn((t) => t),
|
|
1132
|
+
ease: vitest.vi.fn((t) => t * t * (3 - 2 * t)),
|
|
1133
|
+
quad: vitest.vi.fn((t) => t * t),
|
|
1134
|
+
cubic: vitest.vi.fn((t) => t * t * t),
|
|
1135
|
+
poly: vitest.vi.fn((n) => (t) => Math.pow(t, n)),
|
|
1136
|
+
sin: vitest.vi.fn((t) => 1 - Math.cos(t * Math.PI / 2)),
|
|
1137
|
+
circle: vitest.vi.fn((t) => 1 - Math.sqrt(1 - t * t)),
|
|
1138
|
+
exp: vitest.vi.fn((t) => Math.pow(2, 10 * (t - 1))),
|
|
1139
|
+
elastic: vitest.vi.fn((bounciness = 1) => (t) => {
|
|
1140
|
+
const p = bounciness * Math.PI;
|
|
1141
|
+
return 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p);
|
|
1142
|
+
}),
|
|
1143
|
+
back: vitest.vi.fn((s = 1.70158) => (t) => t * t * ((s + 1) * t - s)),
|
|
1144
|
+
bounce: vitest.vi.fn((t) => {
|
|
1145
|
+
if (t < 1 / 2.75) return 7.5625 * t * t;
|
|
1146
|
+
if (t < 2 / 2.75) {
|
|
1147
|
+
t -= 1.5 / 2.75;
|
|
1148
|
+
return 7.5625 * t * t + .75;
|
|
1149
|
+
}
|
|
1150
|
+
if (t < 2.5 / 2.75) {
|
|
1151
|
+
t -= 2.25 / 2.75;
|
|
1152
|
+
return 7.5625 * t * t + .9375;
|
|
1153
|
+
}
|
|
1154
|
+
t -= 2.625 / 2.75;
|
|
1155
|
+
return 7.5625 * t * t + .984375;
|
|
1156
|
+
}),
|
|
1157
|
+
bezier: vitest.vi.fn((x1, _y1, x2, _y2) => (t) => {
|
|
1158
|
+
const cx = 3 * x1;
|
|
1159
|
+
const bx = 3 * (x2 - x1) - cx;
|
|
1160
|
+
return (((1 - cx - bx) * t + bx) * t + cx) * t;
|
|
1161
|
+
}),
|
|
1162
|
+
in: vitest.vi.fn((easing) => easing),
|
|
1163
|
+
out: vitest.vi.fn((easing) => (t) => 1 - easing(1 - t)),
|
|
1164
|
+
inOut: vitest.vi.fn((easing) => (t) => {
|
|
1165
|
+
if (t < .5) return easing(t * 2) / 2;
|
|
1166
|
+
return 1 - easing((1 - t) * 2) / 2;
|
|
1167
|
+
}),
|
|
1168
|
+
step0: vitest.vi.fn((t) => t > 0 ? 1 : 0),
|
|
1169
|
+
step1: vitest.vi.fn((t) => t >= 1 ? 1 : 0)
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region src/mocks/apis/I18nManager.ts
|
|
1174
|
+
function createI18nManagerMock() {
|
|
1175
|
+
const mock = {
|
|
1176
|
+
isRTL: false,
|
|
1177
|
+
doLeftAndRightSwapInRTL: true,
|
|
1178
|
+
allowRTL: vitest.vi.fn((_allow) => {}),
|
|
1179
|
+
forceRTL: vitest.vi.fn((force) => {
|
|
1180
|
+
mock.isRTL = force;
|
|
1181
|
+
}),
|
|
1182
|
+
swapLeftAndRightInRTL: vitest.vi.fn((swap) => {
|
|
1183
|
+
mock.doLeftAndRightSwapInRTL = swap;
|
|
1184
|
+
}),
|
|
1185
|
+
getConstants: vitest.vi.fn(() => ({
|
|
1186
|
+
isRTL: mock.isRTL,
|
|
1187
|
+
doLeftAndRightSwapInRTL: mock.doLeftAndRightSwapInRTL
|
|
1188
|
+
})),
|
|
1189
|
+
_reset: () => {
|
|
1190
|
+
mock.isRTL = false;
|
|
1191
|
+
mock.doLeftAndRightSwapInRTL = true;
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
return mock;
|
|
1195
|
+
}
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region src/mocks/apis/DeviceEventEmitter.ts
|
|
1198
|
+
function createDeviceEventEmitterMock() {
|
|
1199
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
1200
|
+
return {
|
|
1201
|
+
addListener: vitest.vi.fn((event, handler) => {
|
|
1202
|
+
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1203
|
+
listeners.get(event).add(handler);
|
|
1204
|
+
return { remove: vitest.vi.fn(() => listeners.get(event)?.delete(handler)) };
|
|
1205
|
+
}),
|
|
1206
|
+
removeListener: vitest.vi.fn((event, handler) => {
|
|
1207
|
+
listeners.get(event)?.delete(handler);
|
|
1208
|
+
}),
|
|
1209
|
+
removeAllListeners: vitest.vi.fn((event) => {
|
|
1210
|
+
if (event) listeners.delete(event);
|
|
1211
|
+
else listeners.clear();
|
|
1212
|
+
}),
|
|
1213
|
+
removeSubscription: vitest.vi.fn(),
|
|
1214
|
+
emit: vitest.vi.fn((event, ...args) => {
|
|
1215
|
+
listeners.get(event)?.forEach((fn) => fn(...args));
|
|
1216
|
+
}),
|
|
1217
|
+
listenerCount: vitest.vi.fn((event) => listeners.get(event)?.size ?? 0),
|
|
1218
|
+
_reset: () => {
|
|
1219
|
+
listeners.clear();
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
//#endregion
|
|
1224
|
+
//#region src/mocks/apis/useColorScheme.ts
|
|
1225
|
+
function createUseColorSchemeMock() {
|
|
1226
|
+
let scheme = "light";
|
|
1227
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1228
|
+
const hook = () => {
|
|
1229
|
+
try {
|
|
1230
|
+
const [currentScheme, setCurrentScheme] = react.default.useState(scheme);
|
|
1231
|
+
react.default.useEffect(() => {
|
|
1232
|
+
listeners.add(setCurrentScheme);
|
|
1233
|
+
return () => {
|
|
1234
|
+
listeners.delete(setCurrentScheme);
|
|
1235
|
+
};
|
|
1236
|
+
}, []);
|
|
1237
|
+
return currentScheme;
|
|
1238
|
+
} catch {
|
|
1239
|
+
return scheme;
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
hook._setScheme = (s) => {
|
|
1243
|
+
scheme = s;
|
|
1244
|
+
listeners.forEach((fn) => fn(s));
|
|
1245
|
+
};
|
|
1246
|
+
hook._resetScheme = (s) => {
|
|
1247
|
+
scheme = s;
|
|
1248
|
+
listeners.clear();
|
|
1249
|
+
};
|
|
1250
|
+
return hook;
|
|
1251
|
+
}
|
|
1252
|
+
//#endregion
|
|
1253
|
+
//#region src/mocks/apis/useWindowDimensions.ts
|
|
1254
|
+
function createUseWindowDimensionsMock() {
|
|
1255
|
+
let dims = {
|
|
1256
|
+
width: 390,
|
|
1257
|
+
height: 844,
|
|
1258
|
+
scale: 3,
|
|
1259
|
+
fontScale: 1
|
|
1260
|
+
};
|
|
1261
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1262
|
+
const hook = () => {
|
|
1263
|
+
try {
|
|
1264
|
+
const [currentDims, setCurrentDims] = react.default.useState({ ...dims });
|
|
1265
|
+
react.default.useEffect(() => {
|
|
1266
|
+
listeners.add(setCurrentDims);
|
|
1267
|
+
return () => {
|
|
1268
|
+
listeners.delete(setCurrentDims);
|
|
1269
|
+
};
|
|
1270
|
+
}, []);
|
|
1271
|
+
return currentDims;
|
|
1272
|
+
} catch {
|
|
1273
|
+
return { ...dims };
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
hook._setDimensions = (d) => {
|
|
1277
|
+
dims = {
|
|
1278
|
+
...dims,
|
|
1279
|
+
...d
|
|
1280
|
+
};
|
|
1281
|
+
listeners.forEach((fn) => fn({ ...dims }));
|
|
1282
|
+
};
|
|
1283
|
+
hook._resetDimensions = (d) => {
|
|
1284
|
+
dims = { ...d };
|
|
1285
|
+
listeners.clear();
|
|
1286
|
+
};
|
|
1287
|
+
return hook;
|
|
1288
|
+
}
|
|
1289
|
+
//#endregion
|
|
1290
|
+
//#region src/mocks/native/NativeModules.ts
|
|
1291
|
+
/**
|
|
1292
|
+
* Creates a recursive proxy that returns no-op functions for any property access.
|
|
1293
|
+
* This ensures NativeModules.Foo.bar() works without throwing TypeError,
|
|
1294
|
+
* and NativeModules.Foo.bar.baz() also works (arbitrary depth).
|
|
1295
|
+
*
|
|
1296
|
+
* Property accesses are cached so that NativeModules.Foo === NativeModules.Foo
|
|
1297
|
+
* holds true, matching real React Native identity semantics.
|
|
1298
|
+
*/
|
|
1299
|
+
function createModuleProxy$1() {
|
|
1300
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1301
|
+
const noop = () => {};
|
|
1302
|
+
return new Proxy(noop, {
|
|
1303
|
+
get(_target, prop) {
|
|
1304
|
+
if (typeof prop === "symbol") return void 0;
|
|
1305
|
+
if (cache.has(prop)) return cache.get(prop);
|
|
1306
|
+
const child = createModuleProxy$1();
|
|
1307
|
+
cache.set(prop, child);
|
|
1308
|
+
return child;
|
|
1309
|
+
},
|
|
1310
|
+
apply() {}
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
function createNativeModulesMock() {
|
|
1314
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1315
|
+
return new Proxy({}, { get(_target, prop) {
|
|
1316
|
+
if (typeof prop === "symbol") return void 0;
|
|
1317
|
+
if (cache.has(prop)) return cache.get(prop);
|
|
1318
|
+
const child = createModuleProxy$1();
|
|
1319
|
+
cache.set(prop, child);
|
|
1320
|
+
return child;
|
|
1321
|
+
} });
|
|
1322
|
+
}
|
|
1323
|
+
//#endregion
|
|
1324
|
+
//#region src/mocks/native/TurboModuleRegistry.ts
|
|
1325
|
+
function createModuleProxy() {
|
|
1326
|
+
return new Proxy({}, { get(_target, prop) {
|
|
1327
|
+
if (typeof prop === "symbol") return void 0;
|
|
1328
|
+
if (prop === "then") return void 0;
|
|
1329
|
+
return () => {};
|
|
1330
|
+
} });
|
|
1331
|
+
}
|
|
1332
|
+
function createTurboModuleRegistryMock() {
|
|
1333
|
+
return {
|
|
1334
|
+
getEnforcing(_name) {
|
|
1335
|
+
return createModuleProxy();
|
|
1336
|
+
},
|
|
1337
|
+
get(_name) {
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
//#endregion
|
|
1343
|
+
//#region src/mocks/native/UIManager.ts
|
|
1344
|
+
function createUIManagerMock() {
|
|
1345
|
+
return {
|
|
1346
|
+
measure: vitest.vi.fn((_node, callback) => {
|
|
1347
|
+
callback(0, 0, 0, 0, 0, 0);
|
|
1348
|
+
}),
|
|
1349
|
+
measureInWindow: vitest.vi.fn((_node, callback) => {
|
|
1350
|
+
callback(0, 0, 0, 0);
|
|
1351
|
+
}),
|
|
1352
|
+
measureLayout: vitest.vi.fn((_node, _relativeNode, _onFail, onSuccess) => {
|
|
1353
|
+
onSuccess(0, 0, 0, 0);
|
|
1354
|
+
}),
|
|
1355
|
+
setChildren: vitest.vi.fn(),
|
|
1356
|
+
manageChildren: vitest.vi.fn(),
|
|
1357
|
+
createView: vitest.vi.fn(),
|
|
1358
|
+
updateView: vitest.vi.fn(),
|
|
1359
|
+
removeSubviewsFromContainerWithID: vitest.vi.fn(),
|
|
1360
|
+
replaceExistingNonRootView: vitest.vi.fn(),
|
|
1361
|
+
setLayoutAnimationEnabledExperimental: vitest.vi.fn(),
|
|
1362
|
+
configureNextLayoutAnimation: vitest.vi.fn(),
|
|
1363
|
+
getViewManagerConfig: vitest.vi.fn((_name) => ({})),
|
|
1364
|
+
hasViewManagerConfig: vitest.vi.fn((_name) => false),
|
|
1365
|
+
dispatchViewManagerCommand: vitest.vi.fn(),
|
|
1366
|
+
findSubviewIn: vitest.vi.fn(),
|
|
1367
|
+
viewIsDescendantOf: vitest.vi.fn()
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
//#endregion
|
|
1371
|
+
//#region src/mocks/native/NativeEventEmitter.ts
|
|
1372
|
+
function createNativeEventEmitterMock() {
|
|
1373
|
+
return class NativeEventEmitter {
|
|
1374
|
+
listeners = /* @__PURE__ */ new Map();
|
|
1375
|
+
addListener(event, handler) {
|
|
1376
|
+
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
1377
|
+
this.listeners.get(event).add(handler);
|
|
1378
|
+
return { remove: () => {
|
|
1379
|
+
this.listeners.get(event)?.delete(handler);
|
|
1380
|
+
} };
|
|
1381
|
+
}
|
|
1382
|
+
removeAllListeners(event) {
|
|
1383
|
+
if (event) this.listeners.delete(event);
|
|
1384
|
+
else this.listeners.clear();
|
|
1385
|
+
}
|
|
1386
|
+
emit(event, ...args) {
|
|
1387
|
+
this.listeners.get(event)?.forEach((handler) => handler(...args));
|
|
1388
|
+
}
|
|
1389
|
+
listenerCount(event) {
|
|
1390
|
+
return this.listeners.get(event)?.size ?? 0;
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
//#endregion
|
|
1395
|
+
//#region src/mocks/native/NativeComponentRegistry.ts
|
|
1396
|
+
function createNativeComponentRegistryMock() {
|
|
1397
|
+
return {
|
|
1398
|
+
get(name) {
|
|
1399
|
+
const Component = react.default.forwardRef((props, ref) => {
|
|
1400
|
+
return react.default.createElement(name, {
|
|
1401
|
+
...props,
|
|
1402
|
+
ref
|
|
1403
|
+
});
|
|
1404
|
+
});
|
|
1405
|
+
Component.displayName = name;
|
|
1406
|
+
return Component;
|
|
1407
|
+
},
|
|
1408
|
+
getWithFallback(name) {
|
|
1409
|
+
return this.get(name);
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1413
|
+
//#endregion
|
|
1414
|
+
//#region src/mocks/native/requireNativeComponent.ts
|
|
1415
|
+
function createRequireNativeComponentMock() {
|
|
1416
|
+
return function requireNativeComponent(viewName) {
|
|
1417
|
+
const Component = react.default.forwardRef((props, ref) => {
|
|
1418
|
+
return react.default.createElement(viewName, {
|
|
1419
|
+
...props,
|
|
1420
|
+
ref
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
Component.displayName = viewName;
|
|
1424
|
+
return Component;
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
//#endregion
|
|
1428
|
+
//#region src/mocks/registry.ts
|
|
1429
|
+
function createAppRegistryMock() {
|
|
1430
|
+
return {
|
|
1431
|
+
registerComponent: vitest.vi.fn(),
|
|
1432
|
+
registerRunnable: vitest.vi.fn(),
|
|
1433
|
+
registerSection: vitest.vi.fn(),
|
|
1434
|
+
getAppKeys: vitest.vi.fn(() => []),
|
|
1435
|
+
unmountApplicationComponentAtRootTag: vitest.vi.fn(),
|
|
1436
|
+
runApplication: vitest.vi.fn(),
|
|
1437
|
+
setSurfaceProps: vitest.vi.fn(),
|
|
1438
|
+
registerHeadlessTask: vitest.vi.fn(),
|
|
1439
|
+
registerCancellableHeadlessTask: vitest.vi.fn(),
|
|
1440
|
+
startHeadlessTask: vitest.vi.fn(),
|
|
1441
|
+
cancelHeadlessTask: vitest.vi.fn()
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
function createProcessColorMock() {
|
|
1445
|
+
return vitest.vi.fn((color) => {
|
|
1446
|
+
if (color == null) return null;
|
|
1447
|
+
if (typeof color === "number") return color;
|
|
1448
|
+
return 4278190080;
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
function createFindNodeHandleMock() {
|
|
1452
|
+
return vitest.vi.fn((_componentOrHandle) => null);
|
|
1453
|
+
}
|
|
1454
|
+
function createPlatformColorMock() {
|
|
1455
|
+
return vitest.vi.fn((..._names) => "PlatformColor");
|
|
1456
|
+
}
|
|
1457
|
+
function createDynamicColorIOSMock() {
|
|
1458
|
+
return vitest.vi.fn((_config) => "DynamicColorIOS");
|
|
1459
|
+
}
|
|
1460
|
+
function createSettingsMock() {
|
|
1461
|
+
const settings = {};
|
|
1462
|
+
return {
|
|
1463
|
+
get: vitest.vi.fn((key) => settings[key]),
|
|
1464
|
+
set: vitest.vi.fn((obj) => Object.assign(settings, obj)),
|
|
1465
|
+
watchKeys: vitest.vi.fn(() => 0),
|
|
1466
|
+
clearWatch: vitest.vi.fn()
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
function createDeviceInfoMock() {
|
|
1470
|
+
return { getConstants: vitest.vi.fn(() => ({ Dimensions: {
|
|
1471
|
+
window: {
|
|
1472
|
+
width: 390,
|
|
1473
|
+
height: 844,
|
|
1474
|
+
scale: 3,
|
|
1475
|
+
fontScale: 1
|
|
1476
|
+
},
|
|
1477
|
+
screen: {
|
|
1478
|
+
width: 390,
|
|
1479
|
+
height: 844,
|
|
1480
|
+
scale: 3,
|
|
1481
|
+
fontScale: 1
|
|
1482
|
+
}
|
|
1483
|
+
} })) };
|
|
1484
|
+
}
|
|
1485
|
+
function createVirtualizedSectionListMock() {
|
|
1486
|
+
const VirtualizedSectionList = react.default.forwardRef((props, ref) => {
|
|
1487
|
+
const { sections, renderItem, renderSectionHeader, keyExtractor, ...rest } = props;
|
|
1488
|
+
const children = [];
|
|
1489
|
+
if (sections) sections.forEach((section, sectionIndex) => {
|
|
1490
|
+
if (renderSectionHeader) children.push(react.default.createElement(react.default.Fragment, { key: `h-${sectionIndex}` }, renderSectionHeader({ section })));
|
|
1491
|
+
if (section.data) section.data.forEach((item, index) => {
|
|
1492
|
+
const key = keyExtractor ? keyExtractor(item, index) : `${sectionIndex}-${index}`;
|
|
1493
|
+
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
1494
|
+
item,
|
|
1495
|
+
index,
|
|
1496
|
+
section,
|
|
1497
|
+
separators: {}
|
|
1498
|
+
})));
|
|
1499
|
+
});
|
|
1500
|
+
});
|
|
1501
|
+
return react.default.createElement("VirtualizedSectionList", {
|
|
1502
|
+
...rest,
|
|
1503
|
+
ref
|
|
1504
|
+
}, ...children);
|
|
1505
|
+
});
|
|
1506
|
+
VirtualizedSectionList.displayName = "VirtualizedSectionList";
|
|
1507
|
+
return VirtualizedSectionList;
|
|
1508
|
+
}
|
|
1509
|
+
function createTouchableMock() {
|
|
1510
|
+
return {
|
|
1511
|
+
Mixin: {},
|
|
1512
|
+
TOUCH_TARGET_DEBUG: false,
|
|
1513
|
+
renderDebugView: vitest.vi.fn(() => null)
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
function createUseAnimatedValueMock() {
|
|
1517
|
+
return vitest.vi.fn((initialValue) => {
|
|
1518
|
+
return new (createAnimatedMock()).Value(initialValue);
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
function buildReactNativeMock(platform = "ios") {
|
|
1522
|
+
const mock = {
|
|
1523
|
+
View: createViewMock(),
|
|
1524
|
+
Text: createTextMock(),
|
|
1525
|
+
Image: createImageMock(),
|
|
1526
|
+
TextInput: createTextInputMock(),
|
|
1527
|
+
ScrollView: createScrollViewMock(),
|
|
1528
|
+
FlatList: createFlatListMock(),
|
|
1529
|
+
SectionList: createSectionListMock(),
|
|
1530
|
+
Modal: createModalMock(),
|
|
1531
|
+
Pressable: createPressableMock(),
|
|
1532
|
+
TouchableOpacity: createTouchableOpacityMock(),
|
|
1533
|
+
TouchableHighlight: createTouchableHighlightMock(),
|
|
1534
|
+
TouchableWithoutFeedback: createTouchableWithoutFeedbackMock(),
|
|
1535
|
+
TouchableNativeFeedback: createTouchableNativeFeedbackMock(),
|
|
1536
|
+
ActivityIndicator: createActivityIndicatorMock(),
|
|
1537
|
+
Button: createButtonMock(),
|
|
1538
|
+
Switch: createSwitchMock(),
|
|
1539
|
+
RefreshControl: createRefreshControlMock(),
|
|
1540
|
+
StatusBar: createStatusBarMock(),
|
|
1541
|
+
SafeAreaView: createSafeAreaViewMock(),
|
|
1542
|
+
KeyboardAvoidingView: createKeyboardAvoidingViewMock(),
|
|
1543
|
+
ImageBackground: createImageBackgroundMock(),
|
|
1544
|
+
VirtualizedList: createVirtualizedListMock(),
|
|
1545
|
+
InputAccessoryView: createInputAccessoryViewMock(),
|
|
1546
|
+
DrawerLayoutAndroid: createDrawerLayoutAndroidMock(),
|
|
1547
|
+
Platform: createPlatformMock(platform),
|
|
1548
|
+
Dimensions: createDimensionsMock(),
|
|
1549
|
+
StyleSheet: createStyleSheetMock(),
|
|
1550
|
+
Animated: createAnimatedMock(),
|
|
1551
|
+
Alert: createAlertMock(),
|
|
1552
|
+
Linking: createLinkingMock(),
|
|
1553
|
+
AppState: createAppStateMock(),
|
|
1554
|
+
Keyboard: createKeyboardMock(),
|
|
1555
|
+
BackHandler: createBackHandlerMock(),
|
|
1556
|
+
Vibration: createVibrationMock(),
|
|
1557
|
+
PermissionsAndroid: createPermissionsAndroidMock(),
|
|
1558
|
+
Appearance: createAppearanceMock(),
|
|
1559
|
+
PixelRatio: createPixelRatioMock(),
|
|
1560
|
+
LayoutAnimation: createLayoutAnimationMock(),
|
|
1561
|
+
Clipboard: createClipboardMock(),
|
|
1562
|
+
Share: createShareMock(),
|
|
1563
|
+
AccessibilityInfo: createAccessibilityInfoMock(),
|
|
1564
|
+
InteractionManager: createInteractionManagerMock(),
|
|
1565
|
+
PanResponder: createPanResponderMock(),
|
|
1566
|
+
ToastAndroid: createToastAndroidMock(),
|
|
1567
|
+
ActionSheetIOS: createActionSheetIOSMock(),
|
|
1568
|
+
LogBox: createLogBoxMock(),
|
|
1569
|
+
Easing: createEasingMock(),
|
|
1570
|
+
I18nManager: createI18nManagerMock(),
|
|
1571
|
+
DeviceEventEmitter: createDeviceEventEmitterMock(),
|
|
1572
|
+
useColorScheme: createUseColorSchemeMock(),
|
|
1573
|
+
useWindowDimensions: createUseWindowDimensionsMock(),
|
|
1574
|
+
NativeModules: createNativeModulesMock(),
|
|
1575
|
+
TurboModuleRegistry: createTurboModuleRegistryMock(),
|
|
1576
|
+
UIManager: createUIManagerMock(),
|
|
1577
|
+
NativeEventEmitter: createNativeEventEmitterMock(),
|
|
1578
|
+
NativeAppEventEmitter: createDeviceEventEmitterMock(),
|
|
1579
|
+
NativeComponentRegistry: createNativeComponentRegistryMock(),
|
|
1580
|
+
requireNativeComponent: createRequireNativeComponentMock(),
|
|
1581
|
+
AppRegistry: createAppRegistryMock(),
|
|
1582
|
+
VirtualizedSectionList: createVirtualizedSectionListMock(),
|
|
1583
|
+
Touchable: createTouchableMock(),
|
|
1584
|
+
processColor: createProcessColorMock(),
|
|
1585
|
+
findNodeHandle: createFindNodeHandleMock(),
|
|
1586
|
+
PlatformColor: createPlatformColorMock(),
|
|
1587
|
+
DynamicColorIOS: createDynamicColorIOSMock(),
|
|
1588
|
+
Settings: createSettingsMock(),
|
|
1589
|
+
DeviceInfo: createDeviceInfoMock(),
|
|
1590
|
+
useAnimatedValue: createUseAnimatedValueMock(),
|
|
1591
|
+
RootTagContext: react.default.createContext(null),
|
|
1592
|
+
ReactNativeVersion: {
|
|
1593
|
+
major: 0,
|
|
1594
|
+
minor: 76,
|
|
1595
|
+
patch: 0
|
|
1596
|
+
},
|
|
1597
|
+
Systrace: {
|
|
1598
|
+
beginEvent: vitest.vi.fn(),
|
|
1599
|
+
endEvent: vitest.vi.fn(),
|
|
1600
|
+
beginAsyncEvent: vitest.vi.fn(() => 0),
|
|
1601
|
+
endAsyncEvent: vitest.vi.fn(),
|
|
1602
|
+
counterEvent: vitest.vi.fn(),
|
|
1603
|
+
isEnabled: vitest.vi.fn(() => false)
|
|
1604
|
+
},
|
|
1605
|
+
DevSettings: {
|
|
1606
|
+
addMenuItem: vitest.vi.fn(),
|
|
1607
|
+
reload: vitest.vi.fn()
|
|
1608
|
+
},
|
|
1609
|
+
Networking: {
|
|
1610
|
+
addListener: vitest.vi.fn(),
|
|
1611
|
+
removeListeners: vitest.vi.fn()
|
|
1612
|
+
},
|
|
1613
|
+
unstable_batchedUpdates: vitest.vi.fn((fn) => fn()),
|
|
1614
|
+
registerCallableModule: vitest.vi.fn(),
|
|
1615
|
+
codegenNativeCommands: vitest.vi.fn(() => ({})),
|
|
1616
|
+
codegenNativeComponent: vitest.vi.fn((name) => name),
|
|
1617
|
+
UTFSequence: {
|
|
1618
|
+
BOM: "",
|
|
1619
|
+
BULLET: "•",
|
|
1620
|
+
MIDDOT: "·",
|
|
1621
|
+
NBSP: "\xA0"
|
|
1622
|
+
},
|
|
1623
|
+
ProgressBarAndroid: (() => {
|
|
1624
|
+
const C = react.default.forwardRef((props, ref) => react.default.createElement("ProgressBarAndroid", {
|
|
1625
|
+
...props,
|
|
1626
|
+
ref
|
|
1627
|
+
}));
|
|
1628
|
+
C.displayName = "ProgressBarAndroid";
|
|
1629
|
+
return C;
|
|
1630
|
+
})(),
|
|
1631
|
+
PushNotificationIOS: {
|
|
1632
|
+
presentLocalNotification: vitest.vi.fn(),
|
|
1633
|
+
scheduleLocalNotification: vitest.vi.fn(),
|
|
1634
|
+
cancelAllLocalNotifications: vitest.vi.fn(),
|
|
1635
|
+
removeAllDeliveredNotifications: vitest.vi.fn(),
|
|
1636
|
+
getDeliveredNotifications: vitest.vi.fn(async () => []),
|
|
1637
|
+
addEventListener: vitest.vi.fn(() => ({ remove: vitest.vi.fn() })),
|
|
1638
|
+
requestPermissions: vitest.vi.fn(async () => ({
|
|
1639
|
+
alert: true,
|
|
1640
|
+
badge: true,
|
|
1641
|
+
sound: true
|
|
1642
|
+
})),
|
|
1643
|
+
getInitialNotification: vitest.vi.fn(async () => null)
|
|
1644
|
+
},
|
|
1645
|
+
NativeDialogManagerAndroid: { showAlert: vitest.vi.fn() },
|
|
1646
|
+
usePressability: vitest.vi.fn(() => ({})),
|
|
1647
|
+
default: void 0
|
|
1648
|
+
};
|
|
1649
|
+
mock.default = mock;
|
|
1650
|
+
return mock;
|
|
1651
|
+
}
|
|
1652
|
+
//#endregion
|
|
1653
|
+
//#region src/cjs-bridge.ts
|
|
1654
|
+
/**
|
|
1655
|
+
* CJS Bridge — intercepts Node's require('react-native') so CJS consumers
|
|
1656
|
+
* (like @testing-library/react-native) resolve to our mocks instead of
|
|
1657
|
+
* the real Flow-typed source.
|
|
1658
|
+
*
|
|
1659
|
+
* Unlike v1, this uses Module._cache injection (no /tmp files) and stores
|
|
1660
|
+
* the original _resolveFilename for clean teardown.
|
|
1661
|
+
*
|
|
1662
|
+
* Safety: This mutates global Module state (Module._resolveFilename and
|
|
1663
|
+
* Module._cache). This is necessary because CJS require() has no plugin
|
|
1664
|
+
* system — interception is the only option. All mutations are tracked and
|
|
1665
|
+
* fully reversed by uninstallCjsBridge() which runs in afterAll().
|
|
1666
|
+
* Each vitest worker process gets its own Module state, so there's no
|
|
1667
|
+
* cross-test contamination in parallel runs.
|
|
1668
|
+
*/
|
|
1669
|
+
const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
|
|
1670
|
+
let originalResolveFilename = null;
|
|
1671
|
+
let installed = false;
|
|
1672
|
+
function installCjsBridge(mockObject) {
|
|
1673
|
+
if (installed) return;
|
|
1674
|
+
try {
|
|
1675
|
+
const Module = require("node:module");
|
|
1676
|
+
const syntheticModule = new Module(VIRTUAL_RN_PATH);
|
|
1677
|
+
syntheticModule.id = VIRTUAL_RN_PATH;
|
|
1678
|
+
syntheticModule.filename = VIRTUAL_RN_PATH;
|
|
1679
|
+
syntheticModule.loaded = true;
|
|
1680
|
+
syntheticModule.exports = mockObject;
|
|
1681
|
+
Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
|
|
1682
|
+
originalResolveFilename = Module._resolveFilename;
|
|
1683
|
+
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
1684
|
+
if (request === "react-native") return VIRTUAL_RN_PATH;
|
|
1685
|
+
if (request.startsWith("react-native/")) return VIRTUAL_RN_PATH;
|
|
1686
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
1687
|
+
};
|
|
1688
|
+
installed = true;
|
|
1689
|
+
} catch (e) {
|
|
1690
|
+
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge install failed: ${e?.message}`);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
function uninstallCjsBridge() {
|
|
1694
|
+
if (!installed) return;
|
|
1695
|
+
try {
|
|
1696
|
+
const Module = require("node:module");
|
|
1697
|
+
if (originalResolveFilename) {
|
|
1698
|
+
Module._resolveFilename = originalResolveFilename;
|
|
1699
|
+
originalResolveFilename = null;
|
|
1700
|
+
}
|
|
1701
|
+
delete Module._cache[VIRTUAL_RN_PATH];
|
|
1702
|
+
installed = false;
|
|
1703
|
+
} catch (e) {
|
|
1704
|
+
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
function installPresetCjsBridge(moduleName, mockObject) {
|
|
1708
|
+
try {
|
|
1709
|
+
const Module = require("node:module");
|
|
1710
|
+
const virtualPath = `\0vitest-native:preset:${moduleName}`;
|
|
1711
|
+
const syntheticModule = new Module(virtualPath);
|
|
1712
|
+
syntheticModule.id = virtualPath;
|
|
1713
|
+
syntheticModule.filename = virtualPath;
|
|
1714
|
+
syntheticModule.loaded = true;
|
|
1715
|
+
syntheticModule.exports = mockObject;
|
|
1716
|
+
Module._cache[virtualPath] = syntheticModule;
|
|
1717
|
+
const currentResolve = Module._resolveFilename;
|
|
1718
|
+
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
1719
|
+
if (request === moduleName || request.startsWith(`${moduleName}/`)) return virtualPath;
|
|
1720
|
+
return currentResolve.call(this, request, parent, isMain, options);
|
|
1721
|
+
};
|
|
1722
|
+
} catch (e) {
|
|
1723
|
+
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
//#endregion
|
|
1727
|
+
//#region src/setup.ts
|
|
1728
|
+
/**
|
|
1729
|
+
* Auto-injected setup file for vitest-native.
|
|
1730
|
+
*
|
|
1731
|
+
* This file is added to `test.setupFiles` by the Vite plugin. It:
|
|
1732
|
+
* 1. Sets React Native globals (__DEV__, requestAnimationFrame, etc.)
|
|
1733
|
+
* 2. Installs the CJS bridge so require('react-native') resolves to mocks
|
|
1734
|
+
* 3. Registers vi.mock('react-native') with the full mock object
|
|
1735
|
+
* 4. Auto-detects and installs preset mocks
|
|
1736
|
+
* 5. Configures @testing-library/react-native host component names
|
|
1737
|
+
* 6. Auto-registers RNTL matchers
|
|
1738
|
+
* 7. Registers snapshot serializer
|
|
1739
|
+
*
|
|
1740
|
+
* Options are received via process.env (set by the plugin's config() hook
|
|
1741
|
+
* via test.env). This is necessary because the plugin runs in Vite's main
|
|
1742
|
+
* process while this setup file runs in Vitest worker processes — globalThis
|
|
1743
|
+
* does NOT survive that boundary.
|
|
1744
|
+
*/
|
|
1745
|
+
const platform = process.env.VITEST_NATIVE_PLATFORM || "ios";
|
|
1746
|
+
const diagnostics = process.env.VITEST_NATIVE_DIAGNOSTICS === "true";
|
|
1747
|
+
let customMocks = {};
|
|
1748
|
+
if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
1749
|
+
customMocks = JSON.parse(process.env.VITEST_NATIVE_MOCKS);
|
|
1750
|
+
} catch (e) {
|
|
1751
|
+
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_MOCKS: ${e?.message}`);
|
|
1752
|
+
}
|
|
1753
|
+
let explicitPresetNames = null;
|
|
1754
|
+
if (process.env.VITEST_NATIVE_PRESET_NAMES) try {
|
|
1755
|
+
explicitPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_NAMES);
|
|
1756
|
+
} catch (e) {
|
|
1757
|
+
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_PRESET_NAMES: ${e?.message}`);
|
|
1758
|
+
explicitPresetNames = null;
|
|
1759
|
+
}
|
|
1760
|
+
const g = globalThis;
|
|
1761
|
+
Object.defineProperties(g, {
|
|
1762
|
+
__DEV__: {
|
|
1763
|
+
configurable: true,
|
|
1764
|
+
enumerable: true,
|
|
1765
|
+
value: true,
|
|
1766
|
+
writable: true
|
|
1767
|
+
},
|
|
1768
|
+
requestAnimationFrame: {
|
|
1769
|
+
configurable: true,
|
|
1770
|
+
enumerable: true,
|
|
1771
|
+
value: (callback) => setTimeout(() => callback(Date.now()), 0),
|
|
1772
|
+
writable: true
|
|
1773
|
+
},
|
|
1774
|
+
cancelAnimationFrame: {
|
|
1775
|
+
configurable: true,
|
|
1776
|
+
enumerable: true,
|
|
1777
|
+
value: (id) => clearTimeout(id),
|
|
1778
|
+
writable: true
|
|
1779
|
+
},
|
|
1780
|
+
...typeof g.window === "undefined" ? { window: {
|
|
1781
|
+
configurable: true,
|
|
1782
|
+
enumerable: true,
|
|
1783
|
+
value: g,
|
|
1784
|
+
writable: true
|
|
1785
|
+
} } : {},
|
|
1786
|
+
nativeFabricUIManager: {
|
|
1787
|
+
configurable: true,
|
|
1788
|
+
enumerable: true,
|
|
1789
|
+
value: {},
|
|
1790
|
+
writable: true
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
g.IS_REACT_ACT_ENVIRONMENT = true;
|
|
1794
|
+
g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
|
|
1795
|
+
const rnMock = buildReactNativeMock(platform);
|
|
1796
|
+
if (Object.keys(customMocks).length > 0) Object.assign(rnMock, customMocks);
|
|
1797
|
+
g.__vitest_native_mock = rnMock;
|
|
1798
|
+
installCjsBridge(rnMock);
|
|
1799
|
+
vitest.vi.mock("react-native", () => rnMock);
|
|
1800
|
+
/** Load a preset factory by its export name. */
|
|
1801
|
+
function loadPresetFactory(exportName) {
|
|
1802
|
+
const factory = require_presets.presets_exports[exportName];
|
|
1803
|
+
return typeof factory === "function" ? factory : null;
|
|
1804
|
+
}
|
|
1805
|
+
function autoDetectPresets() {
|
|
1806
|
+
const detected = [];
|
|
1807
|
+
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
1808
|
+
const projectReq = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
1809
|
+
for (const [pkgName, exportName] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) try {
|
|
1810
|
+
projectReq.resolve(pkgName);
|
|
1811
|
+
const factory = loadPresetFactory(exportName);
|
|
1812
|
+
if (factory) {
|
|
1813
|
+
detected.push(factory());
|
|
1814
|
+
if (diagnostics) console.log(`[vitest-native] Auto-detected ${pkgName} → enabled ${exportName} preset`);
|
|
1815
|
+
}
|
|
1816
|
+
} catch {}
|
|
1817
|
+
return detected;
|
|
1818
|
+
}
|
|
1819
|
+
function loadExplicitPresets(names) {
|
|
1820
|
+
const loaded = [];
|
|
1821
|
+
for (const name of names) {
|
|
1822
|
+
const factory = loadPresetFactory(name);
|
|
1823
|
+
if (factory) loaded.push(factory());
|
|
1824
|
+
}
|
|
1825
|
+
return loaded;
|
|
1826
|
+
}
|
|
1827
|
+
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets();
|
|
1828
|
+
g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
|
|
1829
|
+
for (const preset of presets) for (const [modName, presetModule] of Object.entries(preset.modules)) {
|
|
1830
|
+
const presetMock = presetModule.factory();
|
|
1831
|
+
installPresetCjsBridge(modName, presetMock);
|
|
1832
|
+
g.__vitest_native_preset_mocks[modName] = presetMock;
|
|
1833
|
+
if (diagnostics) console.log(`[vitest-native] Registered preset mock: ${modName} (${preset.name})`);
|
|
1834
|
+
}
|
|
1835
|
+
try {
|
|
1836
|
+
const rntl = require("@testing-library/react-native");
|
|
1837
|
+
if (rntl?.configure) rntl.configure({ hostComponentNames: {
|
|
1838
|
+
text: "Text",
|
|
1839
|
+
textInput: "TextInput",
|
|
1840
|
+
switch: "Switch",
|
|
1841
|
+
scrollView: "ScrollView",
|
|
1842
|
+
modal: "Modal",
|
|
1843
|
+
image: "Image",
|
|
1844
|
+
button: "Button",
|
|
1845
|
+
pressable: "Pressable",
|
|
1846
|
+
view: "View",
|
|
1847
|
+
activityIndicator: "ActivityIndicator"
|
|
1848
|
+
} });
|
|
1849
|
+
} catch (e) {
|
|
1850
|
+
if (diagnostics) console.log(`[vitest-native] @testing-library/react-native not available: ${e?.message}`);
|
|
1851
|
+
}
|
|
1852
|
+
try {
|
|
1853
|
+
const matchers = require("@testing-library/react-native/build/matchers");
|
|
1854
|
+
if (matchers && Object.keys(matchers).length > 0) {
|
|
1855
|
+
const matcherFns = {};
|
|
1856
|
+
for (const [key, val] of Object.entries(matchers)) if (typeof val === "function" && key !== "__esModule") matcherFns[key] = val;
|
|
1857
|
+
if (Object.keys(matcherFns).length > 0) {
|
|
1858
|
+
vitest.expect.extend(matcherFns);
|
|
1859
|
+
if (diagnostics) console.log(`[vitest-native] Registered ${Object.keys(matcherFns).length} RNTL matchers: ${Object.keys(matcherFns).join(", ")}`);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
} catch (e) {
|
|
1863
|
+
if (diagnostics) console.log(`[vitest-native] Could not load RNTL matchers: ${e?.message}`);
|
|
1864
|
+
}
|
|
1865
|
+
vitest.expect.addSnapshotSerializer(require_serializer.serializer);
|
|
1866
|
+
(0, vitest.afterAll)(() => {
|
|
1867
|
+
uninstallCjsBridge();
|
|
1868
|
+
});
|
|
1869
|
+
//#endregion
|