vitest-native 0.8.0 → 0.10.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/CHANGELOG.md +1063 -0
- package/README.md +47 -2
- package/dist/cli.cjs +642 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +638 -0
- package/dist/ecosystem-CO5vqExO.mjs +318 -0
- package/dist/ecosystem-IuZ-Gv0R.cjs +356 -0
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-vlK4zxuK.d.mts → index-BJL4cQ-l.d.cts} +22 -7
- package/dist/{index-YjjYELG7.d.cts → index-CvCU0cLl.d.mts} +20 -9
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +563 -232
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +164 -5
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/boundary.mjs +108 -30
- package/dist/native/compile-cache.mjs +10 -5
- package/dist/native/explain.mjs +69 -0
- package/dist/native/hooks.mjs +151 -4
- package/dist/native/loader.mjs +61 -12
- package/dist/native/match.mjs +107 -8
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +540 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +34 -7
- package/dist/native/setup.mjs +19 -3
- package/dist/native/transform.mjs +195 -21
- package/dist/native/worker.mjs +69 -17
- package/dist/pool-Bcxp4Qrg.mjs +118 -0
- package/dist/pool-CFND7plG.cjs +122 -0
- package/dist/{preset-map-DCWaM08s.mjs → preset-map-BpDG_D5m.mjs} +1 -1
- package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-DxilQ4pI.cjs} +1 -1
- package/dist/{presets-7eMfp7o2.cjs → presets-BGTqVH6C.cjs} +227 -52
- package/dist/{presets-23FJ76O4.mjs → presets-CK85x8ey.mjs} +222 -53
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +544 -193
- package/docs/hot-default-design.md +129 -0
- package/docs/migrating-from-jest.md +43 -7
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +24 -6
- package/docs/versioning.md +133 -0
- package/package.json +40 -38
- package/dist/index.cjs +0 -643
- package/dist/index.d.cts +0 -14
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
- package/dist/presets.cjs +0 -17
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2514
- package/dist/setup.d.cts +0 -1
package/dist/setup.cjs
DELETED
|
@@ -1,2514 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
-
const require_preset_map = require("./preset-map-BY9zk9Pj.cjs");
|
|
3
|
-
const require_presets = require("./presets-7eMfp7o2.cjs");
|
|
4
|
-
const require_serializer = require("./serializer.cjs");
|
|
5
|
-
const require_matchers = require("./matchers.cjs");
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
|
-
let node_module = require("node:module");
|
|
9
|
-
let vitest = require("vitest");
|
|
10
|
-
let react = require("react");
|
|
11
|
-
react = require_chunk.__toESM(react, 1);
|
|
12
|
-
//#region src/mocks/components/Text.ts
|
|
13
|
-
function createTextMock() {
|
|
14
|
-
const Text = react.default.forwardRef((props, ref) => {
|
|
15
|
-
const { onPress, onLongPress, disabled, accessibilityRole, ...rest } = props;
|
|
16
|
-
const resolvedRole = accessibilityRole ?? (!disabled && (onPress || onLongPress) ? "link" : void 0);
|
|
17
|
-
return react.default.createElement("Text", {
|
|
18
|
-
accessible: true,
|
|
19
|
-
...rest,
|
|
20
|
-
...onPress ? { onPress } : {},
|
|
21
|
-
...onLongPress ? { onLongPress } : {},
|
|
22
|
-
...disabled ? { disabled } : {},
|
|
23
|
-
...resolvedRole ? { accessibilityRole: resolvedRole } : {},
|
|
24
|
-
ref
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
Text.displayName = "Text";
|
|
28
|
-
return Text;
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/mocks/components/Image.ts
|
|
32
|
-
function createImageMock() {
|
|
33
|
-
const Image = react.default.forwardRef((props, ref) => {
|
|
34
|
-
return react.default.createElement("Image", {
|
|
35
|
-
...props,
|
|
36
|
-
ref
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
Image.displayName = "Image";
|
|
40
|
-
Image.getSize = vitest.vi.fn((_uri, success, _failure) => {
|
|
41
|
-
Promise.resolve().then(() => success(100, 100));
|
|
42
|
-
});
|
|
43
|
-
Image.getSizeWithHeaders = vitest.vi.fn((_uri, _headers, success, _failure) => {
|
|
44
|
-
Promise.resolve().then(() => success(100, 100));
|
|
45
|
-
});
|
|
46
|
-
Image.prefetch = vitest.vi.fn(() => Promise.resolve(true));
|
|
47
|
-
Image.queryCache = vitest.vi.fn(() => Promise.resolve({}));
|
|
48
|
-
Image.resolveAssetSource = vitest.vi.fn((source) => {
|
|
49
|
-
if (typeof source === "number") return {
|
|
50
|
-
uri: `asset://${source}`,
|
|
51
|
-
width: 100,
|
|
52
|
-
height: 100
|
|
53
|
-
};
|
|
54
|
-
return source;
|
|
55
|
-
});
|
|
56
|
-
return Image;
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/mocks/components/Modal.ts
|
|
60
|
-
function createModalMock() {
|
|
61
|
-
const Modal = react.default.forwardRef((props, ref) => {
|
|
62
|
-
const { visible = true, children, ...rest } = props;
|
|
63
|
-
if (!visible) return null;
|
|
64
|
-
return react.default.createElement("Modal", {
|
|
65
|
-
...rest,
|
|
66
|
-
visible,
|
|
67
|
-
ref
|
|
68
|
-
}, children);
|
|
69
|
-
});
|
|
70
|
-
Modal.displayName = "Modal";
|
|
71
|
-
return Modal;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/mocks/components/TouchableNativeFeedback.ts
|
|
75
|
-
function createTouchableNativeFeedbackMock() {
|
|
76
|
-
const TouchableNativeFeedback = react.default.forwardRef((props, ref) => {
|
|
77
|
-
const { disabled, accessibilityState, ...rest } = props;
|
|
78
|
-
const mergedA11yState = disabled || accessibilityState ? {
|
|
79
|
-
...accessibilityState,
|
|
80
|
-
...disabled ? { disabled: true } : {}
|
|
81
|
-
} : void 0;
|
|
82
|
-
if (disabled) {
|
|
83
|
-
delete rest.onPress;
|
|
84
|
-
delete rest.onPressIn;
|
|
85
|
-
delete rest.onPressOut;
|
|
86
|
-
delete rest.onLongPress;
|
|
87
|
-
}
|
|
88
|
-
return react.default.createElement("TouchableNativeFeedback", {
|
|
89
|
-
accessible: true,
|
|
90
|
-
...disabled ? { pointerEvents: "none" } : {},
|
|
91
|
-
...rest,
|
|
92
|
-
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
93
|
-
ref
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
TouchableNativeFeedback.displayName = "TouchableNativeFeedback";
|
|
97
|
-
return TouchableNativeFeedback;
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/mocks/components/ActivityIndicator.ts
|
|
101
|
-
function createActivityIndicatorMock() {
|
|
102
|
-
const ActivityIndicator = react.default.forwardRef((props, ref) => {
|
|
103
|
-
return react.default.createElement("ActivityIndicator", {
|
|
104
|
-
...props,
|
|
105
|
-
ref
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
ActivityIndicator.displayName = "ActivityIndicator";
|
|
109
|
-
return ActivityIndicator;
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/mocks/components/Button.ts
|
|
113
|
-
function createButtonMock() {
|
|
114
|
-
function Button(props) {
|
|
115
|
-
const { title, onPress, disabled, color, accessibilityLabel, accessibilityState, ...rest } = props;
|
|
116
|
-
const hostProps = require_presets.buildPressableHostProps({
|
|
117
|
-
...rest,
|
|
118
|
-
onPress,
|
|
119
|
-
disabled,
|
|
120
|
-
accessibilityState,
|
|
121
|
-
accessibilityLabel: accessibilityLabel || title,
|
|
122
|
-
accessibilityRole: "button"
|
|
123
|
-
}, void 0);
|
|
124
|
-
return react.default.createElement("View", hostProps, react.default.createElement("Text", {
|
|
125
|
-
style: color ? { color } : void 0,
|
|
126
|
-
disabled
|
|
127
|
-
}, title));
|
|
128
|
-
}
|
|
129
|
-
Button.displayName = "Button";
|
|
130
|
-
return Button;
|
|
131
|
-
}
|
|
132
|
-
//#endregion
|
|
133
|
-
//#region src/mocks/components/Switch.ts
|
|
134
|
-
function createSwitchMock() {
|
|
135
|
-
const Switch = react.default.forwardRef((props, ref) => {
|
|
136
|
-
return react.default.createElement("RCTSwitch", {
|
|
137
|
-
accessibilityRole: "switch",
|
|
138
|
-
...props,
|
|
139
|
-
ref
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
Switch.displayName = "Switch";
|
|
143
|
-
return Switch;
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/mocks/components/RefreshControl.ts
|
|
147
|
-
function createRefreshControlMock() {
|
|
148
|
-
const RefreshControl = react.default.forwardRef((props, ref) => {
|
|
149
|
-
return react.default.createElement("RefreshControl", {
|
|
150
|
-
...props,
|
|
151
|
-
ref
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
RefreshControl.displayName = "RefreshControl";
|
|
155
|
-
return RefreshControl;
|
|
156
|
-
}
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/mocks/components/StatusBar.ts
|
|
159
|
-
function createStatusBarMock() {
|
|
160
|
-
function StatusBar(props) {
|
|
161
|
-
return react.default.createElement("StatusBar", props);
|
|
162
|
-
}
|
|
163
|
-
StatusBar.displayName = "StatusBar";
|
|
164
|
-
StatusBar.setBarStyle = vitest.vi.fn();
|
|
165
|
-
StatusBar.setBackgroundColor = vitest.vi.fn();
|
|
166
|
-
StatusBar.setHidden = vitest.vi.fn();
|
|
167
|
-
StatusBar.setNetworkActivityIndicatorVisible = vitest.vi.fn();
|
|
168
|
-
StatusBar.setTranslucent = vitest.vi.fn();
|
|
169
|
-
StatusBar.pushStackEntry = vitest.vi.fn(() => ({}));
|
|
170
|
-
StatusBar.popStackEntry = vitest.vi.fn();
|
|
171
|
-
StatusBar.replaceStackEntry = vitest.vi.fn(() => ({}));
|
|
172
|
-
StatusBar.currentHeight = 44;
|
|
173
|
-
return StatusBar;
|
|
174
|
-
}
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region src/mocks/components/SafeAreaView.ts
|
|
177
|
-
function createSafeAreaViewMock() {
|
|
178
|
-
const SafeAreaView = react.default.forwardRef((props, ref) => {
|
|
179
|
-
return react.default.createElement("SafeAreaView", {
|
|
180
|
-
...props,
|
|
181
|
-
ref
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
SafeAreaView.displayName = "SafeAreaView";
|
|
185
|
-
return SafeAreaView;
|
|
186
|
-
}
|
|
187
|
-
//#endregion
|
|
188
|
-
//#region src/mocks/components/KeyboardAvoidingView.ts
|
|
189
|
-
function createKeyboardAvoidingViewMock() {
|
|
190
|
-
const KeyboardAvoidingView = react.default.forwardRef((props, ref) => {
|
|
191
|
-
return react.default.createElement("KeyboardAvoidingView", {
|
|
192
|
-
...props,
|
|
193
|
-
ref
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
KeyboardAvoidingView.displayName = "KeyboardAvoidingView";
|
|
197
|
-
return KeyboardAvoidingView;
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
|
-
//#region src/mocks/components/ImageBackground.ts
|
|
201
|
-
function createImageBackgroundMock() {
|
|
202
|
-
const ImageBackground = react.default.forwardRef((props, ref) => {
|
|
203
|
-
const { children, style, imageStyle, source, ...rest } = props;
|
|
204
|
-
return react.default.createElement("ImageBackground", {
|
|
205
|
-
...rest,
|
|
206
|
-
ref,
|
|
207
|
-
style
|
|
208
|
-
}, react.default.createElement("Image", {
|
|
209
|
-
source,
|
|
210
|
-
style: imageStyle
|
|
211
|
-
}), children);
|
|
212
|
-
});
|
|
213
|
-
ImageBackground.displayName = "ImageBackground";
|
|
214
|
-
return ImageBackground;
|
|
215
|
-
}
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/mocks/components/InputAccessoryView.ts
|
|
218
|
-
function createInputAccessoryViewMock() {
|
|
219
|
-
const InputAccessoryView = react.default.forwardRef((props, ref) => {
|
|
220
|
-
return react.default.createElement("InputAccessoryView", {
|
|
221
|
-
...props,
|
|
222
|
-
ref
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
InputAccessoryView.displayName = "InputAccessoryView";
|
|
226
|
-
return InputAccessoryView;
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/mocks/components/DrawerLayoutAndroid.ts
|
|
230
|
-
function createDrawerLayoutAndroidMock() {
|
|
231
|
-
const DrawerLayoutAndroid = react.default.forwardRef((props, ref) => {
|
|
232
|
-
const { children, ...rest } = props;
|
|
233
|
-
return react.default.createElement("DrawerLayoutAndroid", {
|
|
234
|
-
...rest,
|
|
235
|
-
ref
|
|
236
|
-
}, children);
|
|
237
|
-
});
|
|
238
|
-
DrawerLayoutAndroid.displayName = "DrawerLayoutAndroid";
|
|
239
|
-
return DrawerLayoutAndroid;
|
|
240
|
-
}
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/mocks/apis/Platform.ts
|
|
243
|
-
function createPlatformMock(os = "ios") {
|
|
244
|
-
return {
|
|
245
|
-
OS: os,
|
|
246
|
-
Version: os === "ios" ? "17.0" : 34,
|
|
247
|
-
isPad: false,
|
|
248
|
-
isTVOS: false,
|
|
249
|
-
isTV: false,
|
|
250
|
-
isVision: false,
|
|
251
|
-
isTesting: true,
|
|
252
|
-
select: vitest.vi.fn((specifics) => {
|
|
253
|
-
return specifics[os] ?? specifics.native ?? specifics.default;
|
|
254
|
-
}),
|
|
255
|
-
constants: {
|
|
256
|
-
reactNativeVersion: {
|
|
257
|
-
major: 0,
|
|
258
|
-
minor: 76,
|
|
259
|
-
patch: 0
|
|
260
|
-
},
|
|
261
|
-
osVersion: os === "ios" ? 17 : 34,
|
|
262
|
-
systemName: os === "ios" ? "iOS" : "Android",
|
|
263
|
-
isTesting: true
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
//#endregion
|
|
268
|
-
//#region src/mocks/apis/Dimensions.ts
|
|
269
|
-
function createDimensionsMock() {
|
|
270
|
-
const defaults = {
|
|
271
|
-
window: {
|
|
272
|
-
width: 390,
|
|
273
|
-
height: 844,
|
|
274
|
-
scale: 3,
|
|
275
|
-
fontScale: 1
|
|
276
|
-
},
|
|
277
|
-
screen: {
|
|
278
|
-
width: 390,
|
|
279
|
-
height: 844,
|
|
280
|
-
scale: 3,
|
|
281
|
-
fontScale: 1
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const state = {
|
|
285
|
-
window: { ...defaults.window },
|
|
286
|
-
screen: { ...defaults.screen }
|
|
287
|
-
};
|
|
288
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
289
|
-
return {
|
|
290
|
-
get: vitest.vi.fn((dim) => ({ ...state[dim] })),
|
|
291
|
-
set: vitest.vi.fn((dims) => {
|
|
292
|
-
for (const [key, value] of Object.entries(dims)) if (key in state && value) Object.assign(state[key], value);
|
|
293
|
-
listeners.forEach((fn) => fn({
|
|
294
|
-
window: { ...state.window },
|
|
295
|
-
screen: { ...state.screen }
|
|
296
|
-
}));
|
|
297
|
-
}),
|
|
298
|
-
addEventListener: vitest.vi.fn((_type, handler) => {
|
|
299
|
-
listeners.add(handler);
|
|
300
|
-
return { remove: () => listeners.delete(handler) };
|
|
301
|
-
}),
|
|
302
|
-
_reset: () => {
|
|
303
|
-
Object.assign(state.window, defaults.window);
|
|
304
|
-
Object.assign(state.screen, defaults.screen);
|
|
305
|
-
listeners.clear();
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
//#endregion
|
|
310
|
-
//#region src/mocks/apis/StyleSheet.ts
|
|
311
|
-
function flattenImpl(style) {
|
|
312
|
-
if (style == null || style === false) return void 0;
|
|
313
|
-
if (!Array.isArray(style)) return style;
|
|
314
|
-
const result = {};
|
|
315
|
-
let hasAny = false;
|
|
316
|
-
for (const item of style) {
|
|
317
|
-
const flattened = flattenImpl(item);
|
|
318
|
-
if (flattened != null) {
|
|
319
|
-
hasAny = true;
|
|
320
|
-
Object.assign(result, flattened);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return hasAny ? result : void 0;
|
|
324
|
-
}
|
|
325
|
-
function createStyleSheetMock(getScale = () => 3) {
|
|
326
|
-
const sheet = {
|
|
327
|
-
create: vitest.vi.fn((styles) => {
|
|
328
|
-
return styles;
|
|
329
|
-
}),
|
|
330
|
-
flatten: vitest.vi.fn((style) => flattenImpl(style)),
|
|
331
|
-
compose: vitest.vi.fn((a, b) => [a, b]),
|
|
332
|
-
absoluteFill: {
|
|
333
|
-
position: "absolute",
|
|
334
|
-
left: 0,
|
|
335
|
-
right: 0,
|
|
336
|
-
top: 0,
|
|
337
|
-
bottom: 0
|
|
338
|
-
},
|
|
339
|
-
absoluteFillObject: {
|
|
340
|
-
position: "absolute",
|
|
341
|
-
left: 0,
|
|
342
|
-
right: 0,
|
|
343
|
-
top: 0,
|
|
344
|
-
bottom: 0
|
|
345
|
-
},
|
|
346
|
-
setStyleAttributePreprocessor: vitest.vi.fn()
|
|
347
|
-
};
|
|
348
|
-
Object.defineProperty(sheet, "hairlineWidth", {
|
|
349
|
-
enumerable: true,
|
|
350
|
-
configurable: true,
|
|
351
|
-
get() {
|
|
352
|
-
const ratio = getScale();
|
|
353
|
-
const width = Math.round(.4 * ratio) / ratio;
|
|
354
|
-
return width === 0 ? 1 / ratio : width;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
return sheet;
|
|
358
|
-
}
|
|
359
|
-
//#endregion
|
|
360
|
-
//#region src/mocks/apis/Animated.ts
|
|
361
|
-
const IDENTITY_EASING = (t) => t;
|
|
362
|
-
function interpolateSegment(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight) {
|
|
363
|
-
let result = input;
|
|
364
|
-
if (result < inputMin) {
|
|
365
|
-
if (extrapolateLeft === "identity") return result;
|
|
366
|
-
else if (extrapolateLeft === "clamp") result = inputMin;
|
|
367
|
-
}
|
|
368
|
-
if (result > inputMax) {
|
|
369
|
-
if (extrapolateRight === "identity") return result;
|
|
370
|
-
else if (extrapolateRight === "clamp") result = inputMax;
|
|
371
|
-
}
|
|
372
|
-
if (outputMin === outputMax) return outputMin;
|
|
373
|
-
if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax;
|
|
374
|
-
if (inputMin === -Infinity) result = -result;
|
|
375
|
-
else if (inputMax === Infinity) result = result - inputMin;
|
|
376
|
-
else result = (result - inputMin) / (inputMax - inputMin);
|
|
377
|
-
result = easing(result);
|
|
378
|
-
if (outputMin === -Infinity) result = -result;
|
|
379
|
-
else if (outputMax === Infinity) result = result + outputMin;
|
|
380
|
-
else result = result * (outputMax - outputMin) + outputMin;
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
function findRangeIndex(input, inputRange) {
|
|
384
|
-
let i;
|
|
385
|
-
for (i = 1; i < inputRange.length - 1; ++i) if (inputRange[i] >= input) break;
|
|
386
|
-
return i - 1;
|
|
387
|
-
}
|
|
388
|
-
function interpolateNumeric(value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
|
|
389
|
-
const i = findRangeIndex(value, inputRange);
|
|
390
|
-
return interpolateSegment(value, inputRange[i], inputRange[i + 1], outputRange[i], outputRange[i + 1], easing, extrapolateLeft ?? extrapolate, extrapolateRight ?? extrapolate);
|
|
391
|
-
}
|
|
392
|
-
const NAMED_COLORS = {
|
|
393
|
-
red: [
|
|
394
|
-
255,
|
|
395
|
-
0,
|
|
396
|
-
0,
|
|
397
|
-
1
|
|
398
|
-
],
|
|
399
|
-
green: [
|
|
400
|
-
0,
|
|
401
|
-
128,
|
|
402
|
-
0,
|
|
403
|
-
1
|
|
404
|
-
],
|
|
405
|
-
blue: [
|
|
406
|
-
0,
|
|
407
|
-
0,
|
|
408
|
-
255,
|
|
409
|
-
1
|
|
410
|
-
],
|
|
411
|
-
white: [
|
|
412
|
-
255,
|
|
413
|
-
255,
|
|
414
|
-
255,
|
|
415
|
-
1
|
|
416
|
-
],
|
|
417
|
-
black: [
|
|
418
|
-
0,
|
|
419
|
-
0,
|
|
420
|
-
0,
|
|
421
|
-
1
|
|
422
|
-
],
|
|
423
|
-
transparent: [
|
|
424
|
-
0,
|
|
425
|
-
0,
|
|
426
|
-
0,
|
|
427
|
-
0
|
|
428
|
-
],
|
|
429
|
-
yellow: [
|
|
430
|
-
255,
|
|
431
|
-
255,
|
|
432
|
-
0,
|
|
433
|
-
1
|
|
434
|
-
],
|
|
435
|
-
cyan: [
|
|
436
|
-
0,
|
|
437
|
-
255,
|
|
438
|
-
255,
|
|
439
|
-
1
|
|
440
|
-
],
|
|
441
|
-
magenta: [
|
|
442
|
-
255,
|
|
443
|
-
0,
|
|
444
|
-
255,
|
|
445
|
-
1
|
|
446
|
-
],
|
|
447
|
-
orange: [
|
|
448
|
-
255,
|
|
449
|
-
165,
|
|
450
|
-
0,
|
|
451
|
-
1
|
|
452
|
-
],
|
|
453
|
-
purple: [
|
|
454
|
-
128,
|
|
455
|
-
0,
|
|
456
|
-
128,
|
|
457
|
-
1
|
|
458
|
-
],
|
|
459
|
-
gray: [
|
|
460
|
-
128,
|
|
461
|
-
128,
|
|
462
|
-
128,
|
|
463
|
-
1
|
|
464
|
-
],
|
|
465
|
-
grey: [
|
|
466
|
-
128,
|
|
467
|
-
128,
|
|
468
|
-
128,
|
|
469
|
-
1
|
|
470
|
-
]
|
|
471
|
-
};
|
|
472
|
-
function colorToRgba(input) {
|
|
473
|
-
const s = input.toLowerCase().trim();
|
|
474
|
-
if (NAMED_COLORS[s]) return [...NAMED_COLORS[s]];
|
|
475
|
-
let m;
|
|
476
|
-
if (m = s.match(/^#([0-9a-f]{3})$/)) {
|
|
477
|
-
const [r, g, b] = m[1].split("");
|
|
478
|
-
return [
|
|
479
|
-
parseInt(r + r, 16),
|
|
480
|
-
parseInt(g + g, 16),
|
|
481
|
-
parseInt(b + b, 16),
|
|
482
|
-
1
|
|
483
|
-
];
|
|
484
|
-
}
|
|
485
|
-
if (m = s.match(/^#([0-9a-f]{6})$/)) {
|
|
486
|
-
const n = m[1];
|
|
487
|
-
return [
|
|
488
|
-
parseInt(n.slice(0, 2), 16),
|
|
489
|
-
parseInt(n.slice(2, 4), 16),
|
|
490
|
-
parseInt(n.slice(4, 6), 16),
|
|
491
|
-
1
|
|
492
|
-
];
|
|
493
|
-
}
|
|
494
|
-
if (m = s.match(/^#([0-9a-f]{8})$/)) {
|
|
495
|
-
const n = m[1];
|
|
496
|
-
return [
|
|
497
|
-
parseInt(n.slice(0, 2), 16),
|
|
498
|
-
parseInt(n.slice(2, 4), 16),
|
|
499
|
-
parseInt(n.slice(4, 6), 16),
|
|
500
|
-
parseInt(n.slice(6, 8), 16) / 255
|
|
501
|
-
];
|
|
502
|
-
}
|
|
503
|
-
const compact = s.replace(/\s+/g, "");
|
|
504
|
-
if (m = compact.match(/^rgb\(([\d.]+),([\d.]+),([\d.]+)\)$/)) return [
|
|
505
|
-
+m[1],
|
|
506
|
-
+m[2],
|
|
507
|
-
+m[3],
|
|
508
|
-
1
|
|
509
|
-
];
|
|
510
|
-
if (m = compact.match(/^rgba\(([\d.]+),([\d.]+),([\d.]+),([\d.]+)\)$/)) return [
|
|
511
|
-
+m[1],
|
|
512
|
-
+m[2],
|
|
513
|
-
+m[3],
|
|
514
|
-
+m[4]
|
|
515
|
-
];
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
const NUMERIC_COMPONENT_RE = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
|
|
519
|
-
function mapStringToComponents(input) {
|
|
520
|
-
const rgba = colorToRgba(input);
|
|
521
|
-
if (rgba) return {
|
|
522
|
-
isColor: true,
|
|
523
|
-
components: rgba
|
|
524
|
-
};
|
|
525
|
-
const components = [];
|
|
526
|
-
let lastMatchEnd = 0;
|
|
527
|
-
let match;
|
|
528
|
-
NUMERIC_COMPONENT_RE.lastIndex = 0;
|
|
529
|
-
while ((match = NUMERIC_COMPONENT_RE.exec(input)) != null) {
|
|
530
|
-
if (match.index > lastMatchEnd) components.push(input.substring(lastMatchEnd, match.index));
|
|
531
|
-
components.push(parseFloat(match[0]));
|
|
532
|
-
lastMatchEnd = match.index + match[0].length;
|
|
533
|
-
}
|
|
534
|
-
if (components.length === 0) throw new Error("outputRange must contain color or value with numeric component");
|
|
535
|
-
if (lastMatchEnd < input.length) components.push(input.substring(lastMatchEnd, input.length));
|
|
536
|
-
return {
|
|
537
|
-
isColor: false,
|
|
538
|
-
components
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function prepareStringInterpolation(outputRange) {
|
|
542
|
-
const mapped = outputRange.map(mapStringToComponents);
|
|
543
|
-
const isColor = mapped[0].isColor;
|
|
544
|
-
if (!mapped.every((o) => o.isColor === isColor)) throw new Error("All elements of output range should either be a color or a string with numeric components");
|
|
545
|
-
const first = mapped[0].components;
|
|
546
|
-
if (!mapped.every((o) => o.components.length === first.length)) throw new Error("All elements of output range should have the same number of components");
|
|
547
|
-
if (!mapped.every((o) => o.components.every((c, i) => typeof c === "number" || c === first[i]))) throw new Error("All elements of output range should have the same non-numeric components");
|
|
548
|
-
const numericComponents = mapped.map((o) => isColor ? o.components : o.components.filter((c) => typeof c === "number"));
|
|
549
|
-
return {
|
|
550
|
-
isColor,
|
|
551
|
-
template: first,
|
|
552
|
-
perSlotRanges: numericComponents[0].map((_, i) => numericComponents.map((c) => c[i]))
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
function interpolateString(prepared, value, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
|
|
556
|
-
const slots = prepared.perSlotRanges.map((range) => interpolateNumeric(value, inputRange, range, extrapolate, extrapolateLeft, extrapolateRight, easing));
|
|
557
|
-
if (prepared.isColor) {
|
|
558
|
-
const r = slots.map((v, i) => i < 3 ? Math.round(v) : Math.round(v * 1e3) / 1e3);
|
|
559
|
-
return `rgba(${r[0]}, ${r[1]}, ${r[2]}, ${r[3]})`;
|
|
560
|
-
}
|
|
561
|
-
let i = 0;
|
|
562
|
-
return prepared.template.map((c) => typeof c === "number" ? slots[i++] : c).join("");
|
|
563
|
-
}
|
|
564
|
-
function checkValidRanges(inputRange, outputRange) {
|
|
565
|
-
if (inputRange.length === 2 && inputRange[0] === -Infinity && inputRange[1] === Infinity) throw new Error("inputRange cannot be [-Infinity, Infinity]");
|
|
566
|
-
if (inputRange.length < 2) throw new Error("inputRange must have at least 2 elements");
|
|
567
|
-
for (let i = 1; i < inputRange.length; ++i) if (!(inputRange[i] >= inputRange[i - 1])) throw new Error("inputRange must be monotonically non-decreasing " + String(inputRange));
|
|
568
|
-
if (inputRange.length !== outputRange.length) throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
|
569
|
-
}
|
|
570
|
-
var AnimatedValue = class AnimatedValue {
|
|
571
|
-
_value;
|
|
572
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
573
|
-
_listenerIdCounter = 0;
|
|
574
|
-
_tracking = null;
|
|
575
|
-
constructor(value = 0) {
|
|
576
|
-
this._value = value;
|
|
577
|
-
}
|
|
578
|
-
setValue(value) {
|
|
579
|
-
this._value = value;
|
|
580
|
-
this._listeners.forEach((fn) => fn({ value }));
|
|
581
|
-
}
|
|
582
|
-
getValue() {
|
|
583
|
-
return this._value;
|
|
584
|
-
}
|
|
585
|
-
addListener(callback) {
|
|
586
|
-
const id = String(++this._listenerIdCounter);
|
|
587
|
-
this._listeners.set(id, callback);
|
|
588
|
-
return id;
|
|
589
|
-
}
|
|
590
|
-
removeListener(id) {
|
|
591
|
-
this._listeners.delete(id);
|
|
592
|
-
}
|
|
593
|
-
removeAllListeners() {
|
|
594
|
-
this._listeners.clear();
|
|
595
|
-
}
|
|
596
|
-
interpolate(config) {
|
|
597
|
-
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing = IDENTITY_EASING } = config || {};
|
|
598
|
-
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(this._value);
|
|
599
|
-
checkValidRanges(inputRange, outputRange);
|
|
600
|
-
if (typeof outputRange[0] === "string") {
|
|
601
|
-
const prepared = prepareStringInterpolation(outputRange);
|
|
602
|
-
const compute = () => interpolateString(prepared, this._value, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
603
|
-
return {
|
|
604
|
-
getValue: compute,
|
|
605
|
-
__getValue: compute,
|
|
606
|
-
toJSON: compute,
|
|
607
|
-
interpolate: () => {
|
|
608
|
-
throw new Error("Cannot chain an interpolation off a string-valued interpolation");
|
|
609
|
-
},
|
|
610
|
-
addListener: () => "0",
|
|
611
|
-
removeListener: () => {},
|
|
612
|
-
removeAllListeners: () => {},
|
|
613
|
-
stopAnimation: (cb) => cb?.(compute()),
|
|
614
|
-
resetAnimation: (cb) => cb?.(compute())
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
return new AnimatedValue(interpolateNumeric(this._value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing));
|
|
618
|
-
}
|
|
619
|
-
stopAnimation(callback) {
|
|
620
|
-
callback?.(this._value);
|
|
621
|
-
}
|
|
622
|
-
resetAnimation(callback) {
|
|
623
|
-
callback?.(this._value);
|
|
624
|
-
}
|
|
625
|
-
toJSON() {
|
|
626
|
-
return this._value;
|
|
627
|
-
}
|
|
628
|
-
setOffset(_offset) {}
|
|
629
|
-
flattenOffset() {}
|
|
630
|
-
extractOffset() {}
|
|
631
|
-
};
|
|
632
|
-
var AnimatedValueXY = class {
|
|
633
|
-
x;
|
|
634
|
-
y;
|
|
635
|
-
constructor(value) {
|
|
636
|
-
this.x = new AnimatedValue(value?.x ?? 0);
|
|
637
|
-
this.y = new AnimatedValue(value?.y ?? 0);
|
|
638
|
-
}
|
|
639
|
-
setValue(value) {
|
|
640
|
-
this.x.setValue(value.x);
|
|
641
|
-
this.y.setValue(value.y);
|
|
642
|
-
}
|
|
643
|
-
setOffset(_offset) {}
|
|
644
|
-
flattenOffset() {}
|
|
645
|
-
extractOffset() {}
|
|
646
|
-
stopAnimation(callback) {
|
|
647
|
-
callback?.({
|
|
648
|
-
x: this.x.getValue(),
|
|
649
|
-
y: this.y.getValue()
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
resetAnimation(callback) {
|
|
653
|
-
callback?.({
|
|
654
|
-
x: this.x.getValue(),
|
|
655
|
-
y: this.y.getValue()
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
addListener(_callback) {
|
|
659
|
-
return {
|
|
660
|
-
x: this.x.addListener(() => {}),
|
|
661
|
-
y: this.y.addListener(() => {})
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
removeListener(id) {
|
|
665
|
-
this.x.removeListener(id.x);
|
|
666
|
-
this.y.removeListener(id.y);
|
|
667
|
-
}
|
|
668
|
-
getLayout() {
|
|
669
|
-
return {
|
|
670
|
-
left: this.x,
|
|
671
|
-
top: this.y
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
getTranslateTransform() {
|
|
675
|
-
return [{ translateX: this.x }, { translateY: this.y }];
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
const namedColorMap = {
|
|
679
|
-
red: [
|
|
680
|
-
255,
|
|
681
|
-
0,
|
|
682
|
-
0,
|
|
683
|
-
1
|
|
684
|
-
],
|
|
685
|
-
green: [
|
|
686
|
-
0,
|
|
687
|
-
128,
|
|
688
|
-
0,
|
|
689
|
-
1
|
|
690
|
-
],
|
|
691
|
-
blue: [
|
|
692
|
-
0,
|
|
693
|
-
0,
|
|
694
|
-
255,
|
|
695
|
-
1
|
|
696
|
-
],
|
|
697
|
-
white: [
|
|
698
|
-
255,
|
|
699
|
-
255,
|
|
700
|
-
255,
|
|
701
|
-
1
|
|
702
|
-
],
|
|
703
|
-
black: [
|
|
704
|
-
0,
|
|
705
|
-
0,
|
|
706
|
-
0,
|
|
707
|
-
1
|
|
708
|
-
],
|
|
709
|
-
transparent: [
|
|
710
|
-
0,
|
|
711
|
-
0,
|
|
712
|
-
0,
|
|
713
|
-
0
|
|
714
|
-
],
|
|
715
|
-
yellow: [
|
|
716
|
-
255,
|
|
717
|
-
255,
|
|
718
|
-
0,
|
|
719
|
-
1
|
|
720
|
-
],
|
|
721
|
-
cyan: [
|
|
722
|
-
0,
|
|
723
|
-
255,
|
|
724
|
-
255,
|
|
725
|
-
1
|
|
726
|
-
],
|
|
727
|
-
magenta: [
|
|
728
|
-
255,
|
|
729
|
-
0,
|
|
730
|
-
255,
|
|
731
|
-
1
|
|
732
|
-
]
|
|
733
|
-
};
|
|
734
|
-
function parseColorString(color) {
|
|
735
|
-
const rgba = color.replace(/\s+/g, "").match(/^rgba?\((\d+),(\d+),(\d+)(?:,([\d.]+))?\)$/);
|
|
736
|
-
if (rgba) return [
|
|
737
|
-
parseInt(rgba[1]),
|
|
738
|
-
parseInt(rgba[2]),
|
|
739
|
-
parseInt(rgba[3]),
|
|
740
|
-
rgba[4] != null ? parseFloat(rgba[4]) : 1
|
|
741
|
-
];
|
|
742
|
-
const hex8 = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
|
|
743
|
-
if (hex8) return [
|
|
744
|
-
parseInt(hex8[1], 16),
|
|
745
|
-
parseInt(hex8[2], 16),
|
|
746
|
-
parseInt(hex8[3], 16),
|
|
747
|
-
parseInt(hex8[4], 16) / 255
|
|
748
|
-
];
|
|
749
|
-
const hex6 = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
|
|
750
|
-
if (hex6) return [
|
|
751
|
-
parseInt(hex6[1], 16),
|
|
752
|
-
parseInt(hex6[2], 16),
|
|
753
|
-
parseInt(hex6[3], 16),
|
|
754
|
-
1
|
|
755
|
-
];
|
|
756
|
-
const named = namedColorMap[color.toLowerCase()];
|
|
757
|
-
if (named) return named;
|
|
758
|
-
return [
|
|
759
|
-
0,
|
|
760
|
-
0,
|
|
761
|
-
0,
|
|
762
|
-
1
|
|
763
|
-
];
|
|
764
|
-
}
|
|
765
|
-
var AnimatedColor = class {
|
|
766
|
-
r;
|
|
767
|
-
g;
|
|
768
|
-
b;
|
|
769
|
-
a;
|
|
770
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
771
|
-
_listenerIdCounter = 0;
|
|
772
|
-
constructor(color) {
|
|
773
|
-
if (typeof color === "string") {
|
|
774
|
-
const [r, g, b, a] = parseColorString(color);
|
|
775
|
-
this.r = new AnimatedValue(r);
|
|
776
|
-
this.g = new AnimatedValue(g);
|
|
777
|
-
this.b = new AnimatedValue(b);
|
|
778
|
-
this.a = new AnimatedValue(a);
|
|
779
|
-
} else if (color && typeof color === "object") if (color.r instanceof AnimatedValue) {
|
|
780
|
-
this.r = color.r;
|
|
781
|
-
this.g = color.g;
|
|
782
|
-
this.b = color.b;
|
|
783
|
-
this.a = color.a;
|
|
784
|
-
} else if (typeof color.r === "number") {
|
|
785
|
-
this.r = new AnimatedValue(color.r);
|
|
786
|
-
this.g = new AnimatedValue(color.g ?? 0);
|
|
787
|
-
this.b = new AnimatedValue(color.b ?? 0);
|
|
788
|
-
this.a = new AnimatedValue(color.a ?? 1);
|
|
789
|
-
} else {
|
|
790
|
-
this.r = new AnimatedValue(0);
|
|
791
|
-
this.g = new AnimatedValue(0);
|
|
792
|
-
this.b = new AnimatedValue(0);
|
|
793
|
-
this.a = new AnimatedValue(1);
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
this.r = new AnimatedValue(0);
|
|
797
|
-
this.g = new AnimatedValue(0);
|
|
798
|
-
this.b = new AnimatedValue(0);
|
|
799
|
-
this.a = new AnimatedValue(1);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
setValue(value) {
|
|
803
|
-
if (typeof value === "string") {
|
|
804
|
-
const [r, g, b, a] = parseColorString(value);
|
|
805
|
-
this.r.setValue(r);
|
|
806
|
-
this.g.setValue(g);
|
|
807
|
-
this.b.setValue(b);
|
|
808
|
-
this.a.setValue(a);
|
|
809
|
-
} else if (value && typeof value === "object" && typeof value.r === "number") {
|
|
810
|
-
this.r.setValue(value.r);
|
|
811
|
-
this.g.setValue(value.g ?? 0);
|
|
812
|
-
this.b.setValue(value.b ?? 0);
|
|
813
|
-
this.a.setValue(value.a ?? 1);
|
|
814
|
-
}
|
|
815
|
-
const colorStr = this.__getValue();
|
|
816
|
-
this._listeners.forEach((fn) => fn({ value: colorStr }));
|
|
817
|
-
}
|
|
818
|
-
__getValue() {
|
|
819
|
-
return `rgba(${Math.round(this.r.getValue())}, ${Math.round(this.g.getValue())}, ${Math.round(this.b.getValue())}, ${this.a.getValue()})`;
|
|
820
|
-
}
|
|
821
|
-
addListener(callback) {
|
|
822
|
-
const id = String(++this._listenerIdCounter);
|
|
823
|
-
this._listeners.set(id, callback);
|
|
824
|
-
return id;
|
|
825
|
-
}
|
|
826
|
-
removeListener(id) {
|
|
827
|
-
this._listeners.delete(id);
|
|
828
|
-
}
|
|
829
|
-
removeAllListeners() {
|
|
830
|
-
this._listeners.clear();
|
|
831
|
-
}
|
|
832
|
-
setOffset(_offset) {}
|
|
833
|
-
flattenOffset() {}
|
|
834
|
-
stopAnimation(callback) {
|
|
835
|
-
callback?.(this.__getValue());
|
|
836
|
-
}
|
|
837
|
-
resetAnimation(callback) {
|
|
838
|
-
callback?.(this.__getValue());
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
function createAnimation(onStart) {
|
|
842
|
-
return {
|
|
843
|
-
start: vitest.vi.fn((callback) => {
|
|
844
|
-
onStart?.();
|
|
845
|
-
callback?.({ finished: true });
|
|
846
|
-
}),
|
|
847
|
-
stop: vitest.vi.fn((callback) => {
|
|
848
|
-
callback?.({ finished: false });
|
|
849
|
-
}),
|
|
850
|
-
reset: vitest.vi.fn()
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
function resolveAnimatedLeaf(v) {
|
|
854
|
-
if (v instanceof AnimatedValue) return v.getValue();
|
|
855
|
-
if (v && typeof v === "object" && typeof v.__getValue === "function") return v.__getValue();
|
|
856
|
-
if (v && typeof v === "object" && typeof v.getValue === "function") return v.getValue();
|
|
857
|
-
return v;
|
|
858
|
-
}
|
|
859
|
-
function resolveAnimatedStyle(style) {
|
|
860
|
-
if (Array.isArray(style)) return style.map(resolveAnimatedStyle);
|
|
861
|
-
const asLeaf = resolveAnimatedLeaf(style);
|
|
862
|
-
if (asLeaf !== style) return asLeaf;
|
|
863
|
-
if (style && typeof style === "object") {
|
|
864
|
-
const out = {};
|
|
865
|
-
for (const key of Object.keys(style)) {
|
|
866
|
-
const val = style[key];
|
|
867
|
-
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof AnimatedValue) ? Object.fromEntries(Object.keys(t).map((tk) => [tk, resolveAnimatedLeaf(t[tk])])) : resolveAnimatedLeaf(t));
|
|
868
|
-
else out[key] = resolveAnimatedLeaf(val);
|
|
869
|
-
}
|
|
870
|
-
return out;
|
|
871
|
-
}
|
|
872
|
-
return style;
|
|
873
|
-
}
|
|
874
|
-
function createAnimatedWrapper(displayName) {
|
|
875
|
-
const hostName = displayName.replace(/^Animated\./, "");
|
|
876
|
-
const Component = react.default.forwardRef((props, ref) => {
|
|
877
|
-
if (props && props.style !== void 0) {
|
|
878
|
-
const { style, ...rest } = props;
|
|
879
|
-
return react.default.createElement(hostName, {
|
|
880
|
-
...rest,
|
|
881
|
-
style: resolveAnimatedStyle(style),
|
|
882
|
-
ref
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
return react.default.createElement(hostName, {
|
|
886
|
-
...props,
|
|
887
|
-
ref
|
|
888
|
-
});
|
|
889
|
-
});
|
|
890
|
-
Component.displayName = displayName;
|
|
891
|
-
return Component;
|
|
892
|
-
}
|
|
893
|
-
function stopTracking(value) {
|
|
894
|
-
if (value._tracking) {
|
|
895
|
-
value._tracking.source.removeListener(value._tracking.listenerId);
|
|
896
|
-
value._tracking = null;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
function startTracking(value, toValue) {
|
|
900
|
-
stopTracking(value);
|
|
901
|
-
if (toValue instanceof AnimatedValue) {
|
|
902
|
-
value.setValue(toValue.getValue());
|
|
903
|
-
value._tracking = {
|
|
904
|
-
source: toValue,
|
|
905
|
-
listenerId: toValue.addListener(({ value: v }) => {
|
|
906
|
-
value.setValue(v);
|
|
907
|
-
})
|
|
908
|
-
};
|
|
909
|
-
} else value.setValue(toValue);
|
|
910
|
-
}
|
|
911
|
-
function createAnimatedMock() {
|
|
912
|
-
return {
|
|
913
|
-
Value: AnimatedValue,
|
|
914
|
-
ValueXY: AnimatedValueXY,
|
|
915
|
-
Color: AnimatedColor,
|
|
916
|
-
timing: vitest.vi.fn((value, config) => {
|
|
917
|
-
return createAnimation(() => {
|
|
918
|
-
if (value instanceof AnimatedValue && config?.toValue != null) startTracking(value, config.toValue);
|
|
919
|
-
});
|
|
920
|
-
}),
|
|
921
|
-
spring: vitest.vi.fn((value, config) => {
|
|
922
|
-
return createAnimation(() => {
|
|
923
|
-
if (value instanceof AnimatedValue && config?.toValue != null) startTracking(value, config.toValue);
|
|
924
|
-
});
|
|
925
|
-
}),
|
|
926
|
-
decay: vitest.vi.fn((_value, _config) => createAnimation()),
|
|
927
|
-
sequence: vitest.vi.fn((animations) => {
|
|
928
|
-
let current = 0;
|
|
929
|
-
let cb;
|
|
930
|
-
return {
|
|
931
|
-
start: vitest.vi.fn((endCallback) => {
|
|
932
|
-
cb = endCallback;
|
|
933
|
-
if (animations.length === 0) {
|
|
934
|
-
cb?.({ finished: true });
|
|
935
|
-
return;
|
|
936
|
-
}
|
|
937
|
-
if (current >= animations.length) current = 0;
|
|
938
|
-
const runNext = (result) => {
|
|
939
|
-
if (!result.finished) {
|
|
940
|
-
cb?.({ finished: false });
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
|
-
current++;
|
|
944
|
-
if (current >= animations.length) {
|
|
945
|
-
cb?.({ finished: true });
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
animations[current]?.start(runNext);
|
|
949
|
-
};
|
|
950
|
-
animations[current]?.start(runNext);
|
|
951
|
-
}),
|
|
952
|
-
stop: vitest.vi.fn(() => {
|
|
953
|
-
if (current < animations.length) animations[current]?.stop?.();
|
|
954
|
-
}),
|
|
955
|
-
reset: vitest.vi.fn(() => {
|
|
956
|
-
current = 0;
|
|
957
|
-
for (const anim of animations) anim?.reset?.();
|
|
958
|
-
})
|
|
959
|
-
};
|
|
960
|
-
}),
|
|
961
|
-
parallel: vitest.vi.fn((animations) => {
|
|
962
|
-
let doneCount = 0;
|
|
963
|
-
let hasBeenStopped = false;
|
|
964
|
-
let cb;
|
|
965
|
-
const validAnims = animations.filter(Boolean);
|
|
966
|
-
return {
|
|
967
|
-
start: vitest.vi.fn((endCallback) => {
|
|
968
|
-
cb = endCallback;
|
|
969
|
-
doneCount = 0;
|
|
970
|
-
hasBeenStopped = false;
|
|
971
|
-
if (validAnims.length === 0) {
|
|
972
|
-
cb?.({ finished: true });
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
validAnims.forEach((anim) => {
|
|
976
|
-
anim.start((result) => {
|
|
977
|
-
doneCount++;
|
|
978
|
-
if (!result.finished && !hasBeenStopped) {
|
|
979
|
-
hasBeenStopped = true;
|
|
980
|
-
validAnims.forEach((other) => {
|
|
981
|
-
if (other !== anim) other.stop?.();
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
|
-
if (doneCount >= validAnims.length) cb?.(result);
|
|
985
|
-
});
|
|
986
|
-
});
|
|
987
|
-
}),
|
|
988
|
-
stop: vitest.vi.fn(() => {
|
|
989
|
-
hasBeenStopped = true;
|
|
990
|
-
validAnims.forEach((anim) => {
|
|
991
|
-
anim.stop?.();
|
|
992
|
-
});
|
|
993
|
-
}),
|
|
994
|
-
reset: vitest.vi.fn(() => {
|
|
995
|
-
for (const anim of validAnims) anim?.reset?.();
|
|
996
|
-
})
|
|
997
|
-
};
|
|
998
|
-
}),
|
|
999
|
-
stagger: vitest.vi.fn((_time, animations) => {
|
|
1000
|
-
const validAnims = animations.filter(Boolean);
|
|
1001
|
-
let doneCount = 0;
|
|
1002
|
-
let hasBeenStopped = false;
|
|
1003
|
-
return {
|
|
1004
|
-
start: vitest.vi.fn((endCallback) => {
|
|
1005
|
-
doneCount = 0;
|
|
1006
|
-
hasBeenStopped = false;
|
|
1007
|
-
if (validAnims.length === 0) {
|
|
1008
|
-
endCallback?.({ finished: true });
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
validAnims.forEach((anim) => {
|
|
1012
|
-
anim.start?.((result) => {
|
|
1013
|
-
doneCount++;
|
|
1014
|
-
if (!result.finished && !hasBeenStopped) {
|
|
1015
|
-
hasBeenStopped = true;
|
|
1016
|
-
validAnims.forEach((other) => {
|
|
1017
|
-
if (other !== anim) other.stop?.();
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
if (doneCount >= validAnims.length) endCallback?.(result);
|
|
1021
|
-
});
|
|
1022
|
-
});
|
|
1023
|
-
}),
|
|
1024
|
-
stop: vitest.vi.fn(() => {
|
|
1025
|
-
hasBeenStopped = true;
|
|
1026
|
-
validAnims.forEach((anim) => anim.stop?.());
|
|
1027
|
-
}),
|
|
1028
|
-
reset: vitest.vi.fn(() => {
|
|
1029
|
-
validAnims.forEach((anim) => anim.reset?.());
|
|
1030
|
-
})
|
|
1031
|
-
};
|
|
1032
|
-
}),
|
|
1033
|
-
loop: vitest.vi.fn((animation, config) => {
|
|
1034
|
-
const iterations = config?.iterations;
|
|
1035
|
-
const resetBeforeIteration = config?.resetBeforeIteration !== false;
|
|
1036
|
-
let stopped = false;
|
|
1037
|
-
let startCallback;
|
|
1038
|
-
return {
|
|
1039
|
-
start: vitest.vi.fn((endCallback) => {
|
|
1040
|
-
stopped = false;
|
|
1041
|
-
startCallback = endCallback;
|
|
1042
|
-
if (iterations === 0) {
|
|
1043
|
-
endCallback?.({ finished: true });
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
let iterationCount = 0;
|
|
1047
|
-
const onIteration = (result) => {
|
|
1048
|
-
if (stopped || !result.finished) {
|
|
1049
|
-
startCallback?.(result);
|
|
1050
|
-
return;
|
|
1051
|
-
}
|
|
1052
|
-
iterationCount++;
|
|
1053
|
-
if (iterations != null && iterations > 0 && iterationCount >= iterations) {
|
|
1054
|
-
startCallback?.({ finished: true });
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
if (resetBeforeIteration) animation.reset?.();
|
|
1058
|
-
animation.start(onIteration);
|
|
1059
|
-
};
|
|
1060
|
-
if (resetBeforeIteration) animation.reset?.();
|
|
1061
|
-
animation.start(onIteration);
|
|
1062
|
-
}),
|
|
1063
|
-
stop: vitest.vi.fn(() => {
|
|
1064
|
-
stopped = true;
|
|
1065
|
-
animation.stop?.();
|
|
1066
|
-
}),
|
|
1067
|
-
reset: vitest.vi.fn(() => {
|
|
1068
|
-
animation.reset?.();
|
|
1069
|
-
})
|
|
1070
|
-
};
|
|
1071
|
-
}),
|
|
1072
|
-
delay: vitest.vi.fn((_time) => {
|
|
1073
|
-
return createAnimation();
|
|
1074
|
-
}),
|
|
1075
|
-
add: vitest.vi.fn((a, b) => {
|
|
1076
|
-
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) + (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
1077
|
-
}),
|
|
1078
|
-
subtract: vitest.vi.fn((a, b) => {
|
|
1079
|
-
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) - (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
1080
|
-
}),
|
|
1081
|
-
multiply: vitest.vi.fn((a, b) => {
|
|
1082
|
-
return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) * (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
|
|
1083
|
-
}),
|
|
1084
|
-
divide: vitest.vi.fn((a, b) => {
|
|
1085
|
-
const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
|
|
1086
|
-
const bVal = b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0;
|
|
1087
|
-
return new AnimatedValue(bVal === 0 ? 0 : aVal / bVal);
|
|
1088
|
-
}),
|
|
1089
|
-
modulo: vitest.vi.fn((a, modulus) => {
|
|
1090
|
-
return new AnimatedValue(((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) % modulus + modulus) % modulus);
|
|
1091
|
-
}),
|
|
1092
|
-
diffClamp: vitest.vi.fn((a, min, max) => {
|
|
1093
|
-
const result = new AnimatedValue(Math.min(Math.max(a instanceof AnimatedValue ? a.getValue() : 0, min), max));
|
|
1094
|
-
if (a instanceof AnimatedValue) {
|
|
1095
|
-
let lastInput = a.getValue();
|
|
1096
|
-
let current = result.getValue();
|
|
1097
|
-
a.addListener(({ value }) => {
|
|
1098
|
-
const diff = value - lastInput;
|
|
1099
|
-
lastInput = value;
|
|
1100
|
-
current = Math.min(Math.max(current + diff, min), max);
|
|
1101
|
-
result.setValue(current);
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
return result;
|
|
1105
|
-
}),
|
|
1106
|
-
event: vitest.vi.fn((argMapping, config) => {
|
|
1107
|
-
const handler = vitest.vi.fn((...args) => {
|
|
1108
|
-
argMapping.forEach((mapping, index) => {
|
|
1109
|
-
if (mapping && args[index]) traverseMapping(mapping, args[index]);
|
|
1110
|
-
});
|
|
1111
|
-
config?.listener?.(...args);
|
|
1112
|
-
});
|
|
1113
|
-
function traverseMapping(mapping, value) {
|
|
1114
|
-
if (mapping instanceof AnimatedValue && typeof value === "number") {
|
|
1115
|
-
mapping.setValue(value);
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
if (typeof mapping === "object" && mapping !== null && typeof value === "object" && value !== null) {
|
|
1119
|
-
for (const key of Object.keys(mapping)) if (key in value) traverseMapping(mapping[key], value[key]);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return handler;
|
|
1123
|
-
}),
|
|
1124
|
-
forkEvent: vitest.vi.fn((handler, listener) => {
|
|
1125
|
-
return (...args) => {
|
|
1126
|
-
if (typeof handler === "function") handler(...args);
|
|
1127
|
-
else if (handler && handler.__isNative) {}
|
|
1128
|
-
listener(...args);
|
|
1129
|
-
};
|
|
1130
|
-
}),
|
|
1131
|
-
unforkEvent: vitest.vi.fn(),
|
|
1132
|
-
createAnimatedComponent: vitest.vi.fn((component) => {
|
|
1133
|
-
const Wrapper = react.default.forwardRef((props, ref) => {
|
|
1134
|
-
return react.default.createElement(component, {
|
|
1135
|
-
...props,
|
|
1136
|
-
ref
|
|
1137
|
-
});
|
|
1138
|
-
});
|
|
1139
|
-
Wrapper.displayName = `Animated(${component.displayName || component.name || "Component"})`;
|
|
1140
|
-
return Wrapper;
|
|
1141
|
-
}),
|
|
1142
|
-
View: createAnimatedWrapper("Animated.View"),
|
|
1143
|
-
Text: createAnimatedWrapper("Animated.Text"),
|
|
1144
|
-
Image: createAnimatedWrapper("Animated.Image"),
|
|
1145
|
-
ScrollView: createAnimatedWrapper("Animated.ScrollView"),
|
|
1146
|
-
FlatList: createAnimatedWrapper("Animated.FlatList"),
|
|
1147
|
-
SectionList: createAnimatedWrapper("Animated.SectionList")
|
|
1148
|
-
};
|
|
1149
|
-
}
|
|
1150
|
-
//#endregion
|
|
1151
|
-
//#region src/mocks/apis/Alert.ts
|
|
1152
|
-
function createAlertMock() {
|
|
1153
|
-
return {
|
|
1154
|
-
alert: vitest.vi.fn(),
|
|
1155
|
-
prompt: vitest.vi.fn()
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
//#endregion
|
|
1159
|
-
//#region src/mocks/apis/Linking.ts
|
|
1160
|
-
function createLinkingMock() {
|
|
1161
|
-
return {
|
|
1162
|
-
openURL: vitest.vi.fn(() => Promise.resolve()),
|
|
1163
|
-
canOpenURL: vitest.vi.fn(() => Promise.resolve(true)),
|
|
1164
|
-
getInitialURL: vitest.vi.fn(() => Promise.resolve(null)),
|
|
1165
|
-
openSettings: vitest.vi.fn(() => Promise.resolve()),
|
|
1166
|
-
sendIntent: vitest.vi.fn(() => Promise.resolve()),
|
|
1167
|
-
addEventListener: vitest.vi.fn(() => ({ remove: vitest.vi.fn() }))
|
|
1168
|
-
};
|
|
1169
|
-
}
|
|
1170
|
-
//#endregion
|
|
1171
|
-
//#region src/mocks/apis/AppState.ts
|
|
1172
|
-
function createAppStateMock() {
|
|
1173
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
1174
|
-
const mock = {
|
|
1175
|
-
currentState: "active",
|
|
1176
|
-
isAvailable: true,
|
|
1177
|
-
addEventListener: vitest.vi.fn((type, handler) => {
|
|
1178
|
-
if (!listeners.has(type)) listeners.set(type, /* @__PURE__ */ new Set());
|
|
1179
|
-
listeners.get(type).add(handler);
|
|
1180
|
-
return { remove: vitest.vi.fn(() => listeners.get(type)?.delete(handler)) };
|
|
1181
|
-
}),
|
|
1182
|
-
_setState: (state) => {
|
|
1183
|
-
mock.currentState = state;
|
|
1184
|
-
listeners.get("change")?.forEach((fn) => fn(state));
|
|
1185
|
-
},
|
|
1186
|
-
_reset: () => {
|
|
1187
|
-
mock.currentState = "active";
|
|
1188
|
-
listeners.clear();
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
return mock;
|
|
1192
|
-
}
|
|
1193
|
-
//#endregion
|
|
1194
|
-
//#region src/mocks/apis/Keyboard.ts
|
|
1195
|
-
function createKeyboardMock() {
|
|
1196
|
-
let visible = false;
|
|
1197
|
-
let keyboardHeight = 0;
|
|
1198
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
1199
|
-
return {
|
|
1200
|
-
dismiss: vitest.vi.fn(() => {
|
|
1201
|
-
visible = false;
|
|
1202
|
-
keyboardHeight = 0;
|
|
1203
|
-
}),
|
|
1204
|
-
addListener: vitest.vi.fn((event, handler) => {
|
|
1205
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1206
|
-
listeners.get(event).add(handler);
|
|
1207
|
-
return { remove: vitest.vi.fn(() => listeners.get(event)?.delete(handler)) };
|
|
1208
|
-
}),
|
|
1209
|
-
removeListener: vitest.vi.fn((event, handler) => {
|
|
1210
|
-
listeners.get(event)?.delete(handler);
|
|
1211
|
-
}),
|
|
1212
|
-
removeAllListeners: vitest.vi.fn((event) => {
|
|
1213
|
-
if (event) listeners.delete(event);
|
|
1214
|
-
else listeners.clear();
|
|
1215
|
-
}),
|
|
1216
|
-
isVisible: vitest.vi.fn(() => visible),
|
|
1217
|
-
metrics: vitest.vi.fn(() => visible ? {
|
|
1218
|
-
screenX: 0,
|
|
1219
|
-
screenY: 844 - keyboardHeight,
|
|
1220
|
-
width: 390,
|
|
1221
|
-
height: keyboardHeight
|
|
1222
|
-
} : void 0),
|
|
1223
|
-
scheduleLayoutAnimation: vitest.vi.fn(),
|
|
1224
|
-
_show: (height = 336) => {
|
|
1225
|
-
visible = true;
|
|
1226
|
-
keyboardHeight = height;
|
|
1227
|
-
listeners.get("keyboardDidShow")?.forEach((fn) => fn({ endCoordinates: {
|
|
1228
|
-
screenX: 0,
|
|
1229
|
-
screenY: 844 - height,
|
|
1230
|
-
width: 390,
|
|
1231
|
-
height
|
|
1232
|
-
} }));
|
|
1233
|
-
},
|
|
1234
|
-
_hide: () => {
|
|
1235
|
-
visible = false;
|
|
1236
|
-
keyboardHeight = 0;
|
|
1237
|
-
listeners.get("keyboardDidHide")?.forEach((fn) => fn({}));
|
|
1238
|
-
},
|
|
1239
|
-
_reset: () => {
|
|
1240
|
-
visible = false;
|
|
1241
|
-
keyboardHeight = 0;
|
|
1242
|
-
listeners.clear();
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1246
|
-
//#endregion
|
|
1247
|
-
//#region src/mocks/apis/BackHandler.ts
|
|
1248
|
-
function createBackHandlerMock() {
|
|
1249
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1250
|
-
return {
|
|
1251
|
-
exitApp: vitest.vi.fn(),
|
|
1252
|
-
addEventListener: vitest.vi.fn((event, handler) => {
|
|
1253
|
-
if (event === "hardwareBackPress") listeners.add(handler);
|
|
1254
|
-
return { remove: vitest.vi.fn(() => listeners.delete(handler)) };
|
|
1255
|
-
}),
|
|
1256
|
-
_simulateBackPress: () => {
|
|
1257
|
-
const handlers = [...listeners].reverse();
|
|
1258
|
-
for (const handler of handlers) if (handler() === true) return;
|
|
1259
|
-
},
|
|
1260
|
-
_reset: () => {
|
|
1261
|
-
listeners.clear();
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
//#endregion
|
|
1266
|
-
//#region src/mocks/apis/Vibration.ts
|
|
1267
|
-
function createVibrationMock() {
|
|
1268
|
-
return {
|
|
1269
|
-
vibrate: vitest.vi.fn(),
|
|
1270
|
-
cancel: vitest.vi.fn()
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
//#endregion
|
|
1274
|
-
//#region src/mocks/apis/PermissionsAndroid.ts
|
|
1275
|
-
function createPermissionsAndroidMock() {
|
|
1276
|
-
return {
|
|
1277
|
-
PERMISSIONS: {
|
|
1278
|
-
ACCEPT_HANDOVER: "android.permission.ACCEPT_HANDOVER",
|
|
1279
|
-
ACCESS_BACKGROUND_LOCATION: "android.permission.ACCESS_BACKGROUND_LOCATION",
|
|
1280
|
-
ACCESS_COARSE_LOCATION: "android.permission.ACCESS_COARSE_LOCATION",
|
|
1281
|
-
ACCESS_FINE_LOCATION: "android.permission.ACCESS_FINE_LOCATION",
|
|
1282
|
-
ACCESS_MEDIA_LOCATION: "android.permission.ACCESS_MEDIA_LOCATION",
|
|
1283
|
-
ACTIVITY_RECOGNITION: "android.permission.ACTIVITY_RECOGNITION",
|
|
1284
|
-
BLUETOOTH_ADVERTISE: "android.permission.BLUETOOTH_ADVERTISE",
|
|
1285
|
-
BLUETOOTH_CONNECT: "android.permission.BLUETOOTH_CONNECT",
|
|
1286
|
-
BLUETOOTH_SCAN: "android.permission.BLUETOOTH_SCAN",
|
|
1287
|
-
BODY_SENSORS: "android.permission.BODY_SENSORS",
|
|
1288
|
-
BODY_SENSORS_BACKGROUND: "android.permission.BODY_SENSORS_BACKGROUND",
|
|
1289
|
-
CALL_PHONE: "android.permission.CALL_PHONE",
|
|
1290
|
-
CAMERA: "android.permission.CAMERA",
|
|
1291
|
-
GET_ACCOUNTS: "android.permission.GET_ACCOUNTS",
|
|
1292
|
-
NEARBY_WIFI_DEVICES: "android.permission.NEARBY_WIFI_DEVICES",
|
|
1293
|
-
POST_NOTIFICATIONS: "android.permission.POST_NOTIFICATIONS",
|
|
1294
|
-
PROCESS_OUTGOING_CALLS: "android.permission.PROCESS_OUTGOING_CALLS",
|
|
1295
|
-
READ_CALENDAR: "android.permission.READ_CALENDAR",
|
|
1296
|
-
READ_CALL_LOG: "android.permission.READ_CALL_LOG",
|
|
1297
|
-
READ_CONTACTS: "android.permission.READ_CONTACTS",
|
|
1298
|
-
READ_EXTERNAL_STORAGE: "android.permission.READ_EXTERNAL_STORAGE",
|
|
1299
|
-
READ_MEDIA_AUDIO: "android.permission.READ_MEDIA_AUDIO",
|
|
1300
|
-
READ_MEDIA_IMAGES: "android.permission.READ_MEDIA_IMAGES",
|
|
1301
|
-
READ_MEDIA_VIDEO: "android.permission.READ_MEDIA_VIDEO",
|
|
1302
|
-
READ_PHONE_NUMBERS: "android.permission.READ_PHONE_NUMBERS",
|
|
1303
|
-
READ_PHONE_STATE: "android.permission.READ_PHONE_STATE",
|
|
1304
|
-
READ_SMS: "android.permission.READ_SMS",
|
|
1305
|
-
RECEIVE_MMS: "android.permission.RECEIVE_MMS",
|
|
1306
|
-
RECEIVE_SMS: "android.permission.RECEIVE_SMS",
|
|
1307
|
-
RECEIVE_WAP_PUSH: "android.permission.RECEIVE_WAP_PUSH",
|
|
1308
|
-
RECORD_AUDIO: "android.permission.RECORD_AUDIO",
|
|
1309
|
-
SEND_SMS: "android.permission.SEND_SMS",
|
|
1310
|
-
USE_SIP: "android.permission.USE_SIP",
|
|
1311
|
-
WRITE_CALENDAR: "android.permission.WRITE_CALENDAR",
|
|
1312
|
-
WRITE_CALL_LOG: "android.permission.WRITE_CALL_LOG",
|
|
1313
|
-
WRITE_CONTACTS: "android.permission.WRITE_CONTACTS",
|
|
1314
|
-
WRITE_EXTERNAL_STORAGE: "android.permission.WRITE_EXTERNAL_STORAGE"
|
|
1315
|
-
},
|
|
1316
|
-
RESULTS: {
|
|
1317
|
-
GRANTED: "granted",
|
|
1318
|
-
DENIED: "denied",
|
|
1319
|
-
NEVER_ASK_AGAIN: "never_ask_again"
|
|
1320
|
-
},
|
|
1321
|
-
check: vitest.vi.fn(() => Promise.resolve(true)),
|
|
1322
|
-
request: vitest.vi.fn(() => Promise.resolve("granted")),
|
|
1323
|
-
requestMultiple: vitest.vi.fn((permissions) => Promise.resolve(permissions.reduce((acc, p) => ({
|
|
1324
|
-
...acc,
|
|
1325
|
-
[p]: "granted"
|
|
1326
|
-
}), {})))
|
|
1327
|
-
};
|
|
1328
|
-
}
|
|
1329
|
-
//#endregion
|
|
1330
|
-
//#region src/mocks/apis/Appearance.ts
|
|
1331
|
-
function createAppearanceMock() {
|
|
1332
|
-
let colorScheme = "light";
|
|
1333
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1334
|
-
return {
|
|
1335
|
-
getColorScheme: vitest.vi.fn(() => colorScheme),
|
|
1336
|
-
setColorScheme: vitest.vi.fn((scheme) => {
|
|
1337
|
-
colorScheme = scheme;
|
|
1338
|
-
listeners.forEach((fn) => fn({ colorScheme: scheme }));
|
|
1339
|
-
}),
|
|
1340
|
-
addChangeListener: vitest.vi.fn((listener) => {
|
|
1341
|
-
listeners.add(listener);
|
|
1342
|
-
return { remove: () => {
|
|
1343
|
-
listeners.delete(listener);
|
|
1344
|
-
} };
|
|
1345
|
-
}),
|
|
1346
|
-
_reset: () => {
|
|
1347
|
-
colorScheme = "light";
|
|
1348
|
-
listeners.clear();
|
|
1349
|
-
}
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
//#endregion
|
|
1353
|
-
//#region src/mocks/apis/PixelRatio.ts
|
|
1354
|
-
function createPixelRatioMock(getDimensions) {
|
|
1355
|
-
const getScale = () => getDimensions ? getDimensions().scale : 3;
|
|
1356
|
-
const getFontScale = () => getDimensions ? getDimensions().fontScale : 1;
|
|
1357
|
-
return {
|
|
1358
|
-
get: vitest.vi.fn(() => getScale()),
|
|
1359
|
-
getFontScale: vitest.vi.fn(() => getFontScale()),
|
|
1360
|
-
getPixelSizeForLayoutSize: vitest.vi.fn((layoutSize) => Math.round(layoutSize * getScale())),
|
|
1361
|
-
roundToNearestPixel: vitest.vi.fn((layoutSize) => {
|
|
1362
|
-
const ratio = getScale();
|
|
1363
|
-
return Math.round(layoutSize * ratio) / ratio;
|
|
1364
|
-
})
|
|
1365
|
-
};
|
|
1366
|
-
}
|
|
1367
|
-
//#endregion
|
|
1368
|
-
//#region src/mocks/apis/LayoutAnimation.ts
|
|
1369
|
-
function createLayoutAnimationMock() {
|
|
1370
|
-
return {
|
|
1371
|
-
configureNext: vitest.vi.fn(),
|
|
1372
|
-
create: vitest.vi.fn(() => ({
|
|
1373
|
-
duration: 300,
|
|
1374
|
-
create: {
|
|
1375
|
-
type: "easeInEaseOut",
|
|
1376
|
-
property: "opacity"
|
|
1377
|
-
},
|
|
1378
|
-
update: { type: "easeInEaseOut" },
|
|
1379
|
-
delete: {
|
|
1380
|
-
type: "easeInEaseOut",
|
|
1381
|
-
property: "opacity"
|
|
1382
|
-
}
|
|
1383
|
-
})),
|
|
1384
|
-
Types: {
|
|
1385
|
-
spring: "spring",
|
|
1386
|
-
linear: "linear",
|
|
1387
|
-
easeInEaseOut: "easeInEaseOut",
|
|
1388
|
-
easeIn: "easeIn",
|
|
1389
|
-
easeOut: "easeOut"
|
|
1390
|
-
},
|
|
1391
|
-
Properties: {
|
|
1392
|
-
opacity: "opacity",
|
|
1393
|
-
scaleX: "scaleX",
|
|
1394
|
-
scaleY: "scaleY",
|
|
1395
|
-
scaleXY: "scaleXY"
|
|
1396
|
-
},
|
|
1397
|
-
Presets: {
|
|
1398
|
-
easeInEaseOut: {
|
|
1399
|
-
duration: 300,
|
|
1400
|
-
create: {
|
|
1401
|
-
type: "easeInEaseOut",
|
|
1402
|
-
property: "opacity"
|
|
1403
|
-
},
|
|
1404
|
-
update: { type: "easeInEaseOut" },
|
|
1405
|
-
delete: {
|
|
1406
|
-
type: "easeInEaseOut",
|
|
1407
|
-
property: "opacity"
|
|
1408
|
-
}
|
|
1409
|
-
},
|
|
1410
|
-
linear: {
|
|
1411
|
-
duration: 500,
|
|
1412
|
-
create: {
|
|
1413
|
-
type: "linear",
|
|
1414
|
-
property: "opacity"
|
|
1415
|
-
},
|
|
1416
|
-
update: { type: "linear" },
|
|
1417
|
-
delete: {
|
|
1418
|
-
type: "linear",
|
|
1419
|
-
property: "opacity"
|
|
1420
|
-
}
|
|
1421
|
-
},
|
|
1422
|
-
spring: {
|
|
1423
|
-
duration: 700,
|
|
1424
|
-
create: {
|
|
1425
|
-
type: "linear",
|
|
1426
|
-
property: "opacity"
|
|
1427
|
-
},
|
|
1428
|
-
update: {
|
|
1429
|
-
type: "spring",
|
|
1430
|
-
springDamping: .4
|
|
1431
|
-
},
|
|
1432
|
-
delete: {
|
|
1433
|
-
type: "linear",
|
|
1434
|
-
property: "opacity"
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
}
|
|
1440
|
-
//#endregion
|
|
1441
|
-
//#region src/mocks/apis/Clipboard.ts
|
|
1442
|
-
function createClipboardMock() {
|
|
1443
|
-
let content = "";
|
|
1444
|
-
return {
|
|
1445
|
-
getString: vitest.vi.fn(() => Promise.resolve(content)),
|
|
1446
|
-
setString: vitest.vi.fn((text) => {
|
|
1447
|
-
content = text;
|
|
1448
|
-
}),
|
|
1449
|
-
hasString: vitest.vi.fn(() => Promise.resolve(content.length > 0))
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
//#endregion
|
|
1453
|
-
//#region src/mocks/apis/Share.ts
|
|
1454
|
-
function createShareMock() {
|
|
1455
|
-
return {
|
|
1456
|
-
share: vitest.vi.fn(async () => ({ action: "sharedAction" })),
|
|
1457
|
-
sharedAction: "sharedAction",
|
|
1458
|
-
dismissedAction: "dismissedAction"
|
|
1459
|
-
};
|
|
1460
|
-
}
|
|
1461
|
-
//#endregion
|
|
1462
|
-
//#region src/mocks/apis/AccessibilityInfo.ts
|
|
1463
|
-
function createAccessibilityInfoMock() {
|
|
1464
|
-
return {
|
|
1465
|
-
isScreenReaderEnabled: vitest.vi.fn(async () => false),
|
|
1466
|
-
isBoldTextEnabled: vitest.vi.fn(async () => false),
|
|
1467
|
-
isGrayscaleEnabled: vitest.vi.fn(async () => false),
|
|
1468
|
-
isInvertColorsEnabled: vitest.vi.fn(async () => false),
|
|
1469
|
-
isReduceMotionEnabled: vitest.vi.fn(async () => false),
|
|
1470
|
-
isReduceTransparencyEnabled: vitest.vi.fn(async () => false),
|
|
1471
|
-
prefersCrossFadeTransitions: vitest.vi.fn(async () => false),
|
|
1472
|
-
addEventListener: vitest.vi.fn((_eventName, _handler) => ({ remove: vitest.vi.fn() })),
|
|
1473
|
-
announceForAccessibility: vitest.vi.fn(),
|
|
1474
|
-
announceForAccessibilityWithOptions: vitest.vi.fn(),
|
|
1475
|
-
setAccessibilityFocus: vitest.vi.fn(),
|
|
1476
|
-
sendAccessibilityEvent: vitest.vi.fn(),
|
|
1477
|
-
getRecommendedTimeoutMillis: vitest.vi.fn(async (originalTimeout) => originalTimeout)
|
|
1478
|
-
};
|
|
1479
|
-
}
|
|
1480
|
-
//#endregion
|
|
1481
|
-
//#region src/mocks/apis/InteractionManager.ts
|
|
1482
|
-
function createInteractionManagerMock() {
|
|
1483
|
-
return {
|
|
1484
|
-
runAfterInteractions: vitest.vi.fn((task) => {
|
|
1485
|
-
(typeof task === "function" ? task : task?.gen)?.();
|
|
1486
|
-
const promise = Promise.resolve();
|
|
1487
|
-
return {
|
|
1488
|
-
then: promise.then.bind(promise),
|
|
1489
|
-
done: promise.then.bind(promise),
|
|
1490
|
-
cancel: vitest.vi.fn()
|
|
1491
|
-
};
|
|
1492
|
-
}),
|
|
1493
|
-
createInteractionHandle: vitest.vi.fn(() => 1),
|
|
1494
|
-
clearInteractionHandle: vitest.vi.fn(),
|
|
1495
|
-
setDeadline: vitest.vi.fn()
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
//#endregion
|
|
1499
|
-
//#region src/mocks/apis/PanResponder.ts
|
|
1500
|
-
function createPanResponderMock() {
|
|
1501
|
-
return { create: vitest.vi.fn((config = {}) => ({ panHandlers: {
|
|
1502
|
-
onStartShouldSetResponder: config.onStartShouldSetPanResponder ? vitest.vi.fn((...args) => config.onStartShouldSetPanResponder(...args)) : vitest.vi.fn(() => false),
|
|
1503
|
-
onMoveShouldSetResponder: config.onMoveShouldSetPanResponder ? vitest.vi.fn((...args) => config.onMoveShouldSetPanResponder(...args)) : vitest.vi.fn(() => false),
|
|
1504
|
-
onStartShouldSetResponderCapture: config.onStartShouldSetPanResponderCapture ? vitest.vi.fn((...args) => config.onStartShouldSetPanResponderCapture(...args)) : vitest.vi.fn(() => false),
|
|
1505
|
-
onMoveShouldSetResponderCapture: config.onMoveShouldSetPanResponderCapture ? vitest.vi.fn((...args) => config.onMoveShouldSetPanResponderCapture(...args)) : vitest.vi.fn(() => false),
|
|
1506
|
-
onResponderGrant: config.onPanResponderGrant ?? vitest.vi.fn(),
|
|
1507
|
-
onResponderReject: config.onPanResponderReject ?? vitest.vi.fn(),
|
|
1508
|
-
onResponderStart: config.onPanResponderStart ?? vitest.vi.fn(),
|
|
1509
|
-
onResponderMove: config.onPanResponderMove ?? vitest.vi.fn(),
|
|
1510
|
-
onResponderEnd: config.onPanResponderEnd ?? vitest.vi.fn(),
|
|
1511
|
-
onResponderRelease: config.onPanResponderRelease ?? vitest.vi.fn(),
|
|
1512
|
-
onResponderTerminate: config.onPanResponderTerminate ?? vitest.vi.fn(),
|
|
1513
|
-
onResponderTerminationRequest: config.onPanResponderTerminationRequest ?? vitest.vi.fn(() => true)
|
|
1514
|
-
} })) };
|
|
1515
|
-
}
|
|
1516
|
-
//#endregion
|
|
1517
|
-
//#region src/mocks/apis/ToastAndroid.ts
|
|
1518
|
-
function createToastAndroidMock() {
|
|
1519
|
-
return {
|
|
1520
|
-
show: vitest.vi.fn(),
|
|
1521
|
-
showWithGravity: vitest.vi.fn(),
|
|
1522
|
-
showWithGravityAndOffset: vitest.vi.fn(),
|
|
1523
|
-
SHORT: 0,
|
|
1524
|
-
LONG: 1,
|
|
1525
|
-
TOP: 0,
|
|
1526
|
-
BOTTOM: 1,
|
|
1527
|
-
CENTER: 2
|
|
1528
|
-
};
|
|
1529
|
-
}
|
|
1530
|
-
//#endregion
|
|
1531
|
-
//#region src/mocks/apis/ActionSheetIOS.ts
|
|
1532
|
-
function createActionSheetIOSMock() {
|
|
1533
|
-
return {
|
|
1534
|
-
showActionSheetWithOptions: vitest.vi.fn(),
|
|
1535
|
-
showShareActionSheetWithOptions: vitest.vi.fn()
|
|
1536
|
-
};
|
|
1537
|
-
}
|
|
1538
|
-
//#endregion
|
|
1539
|
-
//#region src/mocks/apis/LogBox.ts
|
|
1540
|
-
function createLogBoxMock() {
|
|
1541
|
-
return {
|
|
1542
|
-
ignoreLogs: vitest.vi.fn(),
|
|
1543
|
-
ignoreAllLogs: vitest.vi.fn(),
|
|
1544
|
-
uninstall: vitest.vi.fn(),
|
|
1545
|
-
install: vitest.vi.fn()
|
|
1546
|
-
};
|
|
1547
|
-
}
|
|
1548
|
-
//#endregion
|
|
1549
|
-
//#region src/mocks/apis/Easing.ts
|
|
1550
|
-
const NEWTON_ITERATIONS = 4;
|
|
1551
|
-
const NEWTON_MIN_SLOPE = .001;
|
|
1552
|
-
const SUBDIVISION_PRECISION = 1e-7;
|
|
1553
|
-
const SUBDIVISION_MAX_ITERATIONS = 10;
|
|
1554
|
-
const kSplineTableSize = 11;
|
|
1555
|
-
const kSampleStepSize = 1 / (kSplineTableSize - 1);
|
|
1556
|
-
function A(aA1, aA2) {
|
|
1557
|
-
return 1 - 3 * aA2 + 3 * aA1;
|
|
1558
|
-
}
|
|
1559
|
-
function B(aA1, aA2) {
|
|
1560
|
-
return 3 * aA2 - 6 * aA1;
|
|
1561
|
-
}
|
|
1562
|
-
function C(aA1) {
|
|
1563
|
-
return 3 * aA1;
|
|
1564
|
-
}
|
|
1565
|
-
function calcBezier(aT, aA1, aA2) {
|
|
1566
|
-
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
|
|
1567
|
-
}
|
|
1568
|
-
function getSlope(aT, aA1, aA2) {
|
|
1569
|
-
return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
|
|
1570
|
-
}
|
|
1571
|
-
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
|
1572
|
-
let currentX;
|
|
1573
|
-
let currentT;
|
|
1574
|
-
let i = 0;
|
|
1575
|
-
let low = aA;
|
|
1576
|
-
let high = aB;
|
|
1577
|
-
do {
|
|
1578
|
-
currentT = low + (high - low) / 2;
|
|
1579
|
-
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
|
1580
|
-
if (currentX > 0) high = currentT;
|
|
1581
|
-
else low = currentT;
|
|
1582
|
-
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
|
|
1583
|
-
return currentT;
|
|
1584
|
-
}
|
|
1585
|
-
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
|
1586
|
-
let guessT = aGuessT;
|
|
1587
|
-
for (let i = 0; i < NEWTON_ITERATIONS; ++i) {
|
|
1588
|
-
const currentSlope = getSlope(guessT, mX1, mX2);
|
|
1589
|
-
if (currentSlope === 0) return guessT;
|
|
1590
|
-
const currentX = calcBezier(guessT, mX1, mX2) - aX;
|
|
1591
|
-
guessT -= currentX / currentSlope;
|
|
1592
|
-
}
|
|
1593
|
-
return guessT;
|
|
1594
|
-
}
|
|
1595
|
-
function bezier(mX1, mY1, mX2, mY2) {
|
|
1596
|
-
if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
|
|
1597
|
-
if (mX1 === mY1 && mX2 === mY2) return (x) => x;
|
|
1598
|
-
const sampleValues = new Float32Array(kSplineTableSize);
|
|
1599
|
-
for (let i = 0; i < kSplineTableSize; ++i) sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
|
1600
|
-
function getTForX(aX) {
|
|
1601
|
-
let intervalStart = 0;
|
|
1602
|
-
let currentSample = 1;
|
|
1603
|
-
const lastSample = kSplineTableSize - 1;
|
|
1604
|
-
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
|
|
1605
|
-
--currentSample;
|
|
1606
|
-
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
|
1607
|
-
const guessForT = intervalStart + dist * kSampleStepSize;
|
|
1608
|
-
const initialSlope = getSlope(guessForT, mX1, mX2);
|
|
1609
|
-
if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
|
1610
|
-
else if (initialSlope === 0) return guessForT;
|
|
1611
|
-
else return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
|
1612
|
-
}
|
|
1613
|
-
return function(x) {
|
|
1614
|
-
if (x === 0 || x === 1) return x;
|
|
1615
|
-
return calcBezier(getTForX(x), mY1, mY2);
|
|
1616
|
-
};
|
|
1617
|
-
}
|
|
1618
|
-
function createEasingMock() {
|
|
1619
|
-
const easeFn = bezier(.42, 0, 1, 1);
|
|
1620
|
-
return {
|
|
1621
|
-
linear: vitest.vi.fn((t) => t),
|
|
1622
|
-
ease: vitest.vi.fn((t) => easeFn(t)),
|
|
1623
|
-
quad: vitest.vi.fn((t) => t * t),
|
|
1624
|
-
cubic: vitest.vi.fn((t) => t * t * t),
|
|
1625
|
-
poly: vitest.vi.fn((n) => (t) => Math.pow(t, n)),
|
|
1626
|
-
sin: vitest.vi.fn((t) => 1 - Math.cos(t * Math.PI / 2)),
|
|
1627
|
-
circle: vitest.vi.fn((t) => 1 - Math.sqrt(1 - t * t)),
|
|
1628
|
-
exp: vitest.vi.fn((t) => Math.pow(2, 10 * (t - 1))),
|
|
1629
|
-
elastic: vitest.vi.fn((bounciness = 1) => (t) => {
|
|
1630
|
-
const p = bounciness * Math.PI;
|
|
1631
|
-
return 1 - Math.pow(Math.cos(t * Math.PI / 2), 3) * Math.cos(t * p);
|
|
1632
|
-
}),
|
|
1633
|
-
back: vitest.vi.fn((s = 1.70158) => (t) => t * t * ((s + 1) * t - s)),
|
|
1634
|
-
bounce: vitest.vi.fn((t) => {
|
|
1635
|
-
if (t < 1 / 2.75) return 7.5625 * t * t;
|
|
1636
|
-
if (t < 2 / 2.75) {
|
|
1637
|
-
const t2 = t - 1.5 / 2.75;
|
|
1638
|
-
return 7.5625 * t2 * t2 + .75;
|
|
1639
|
-
}
|
|
1640
|
-
if (t < 2.5 / 2.75) {
|
|
1641
|
-
const t2 = t - 2.25 / 2.75;
|
|
1642
|
-
return 7.5625 * t2 * t2 + .9375;
|
|
1643
|
-
}
|
|
1644
|
-
const t2 = t - 2.625 / 2.75;
|
|
1645
|
-
return 7.5625 * t2 * t2 + .984375;
|
|
1646
|
-
}),
|
|
1647
|
-
bezier: vitest.vi.fn((x1, y1, x2, y2) => bezier(x1, y1, x2, y2)),
|
|
1648
|
-
in: vitest.vi.fn((easing) => easing),
|
|
1649
|
-
out: vitest.vi.fn((easing) => (t) => 1 - easing(1 - t)),
|
|
1650
|
-
inOut: vitest.vi.fn((easing) => (t) => {
|
|
1651
|
-
if (t < .5) return easing(t * 2) / 2;
|
|
1652
|
-
return 1 - easing((1 - t) * 2) / 2;
|
|
1653
|
-
}),
|
|
1654
|
-
step0: vitest.vi.fn((t) => t > 0 ? 1 : 0),
|
|
1655
|
-
step1: vitest.vi.fn((t) => t >= 1 ? 1 : 0)
|
|
1656
|
-
};
|
|
1657
|
-
}
|
|
1658
|
-
//#endregion
|
|
1659
|
-
//#region src/mocks/apis/I18nManager.ts
|
|
1660
|
-
function createI18nManagerMock() {
|
|
1661
|
-
const mock = {
|
|
1662
|
-
isRTL: false,
|
|
1663
|
-
doLeftAndRightSwapInRTL: true,
|
|
1664
|
-
allowRTL: vitest.vi.fn((_allow) => {}),
|
|
1665
|
-
forceRTL: vitest.vi.fn((force) => {
|
|
1666
|
-
mock.isRTL = force;
|
|
1667
|
-
}),
|
|
1668
|
-
swapLeftAndRightInRTL: vitest.vi.fn((swap) => {
|
|
1669
|
-
mock.doLeftAndRightSwapInRTL = swap;
|
|
1670
|
-
}),
|
|
1671
|
-
getConstants: vitest.vi.fn(() => ({
|
|
1672
|
-
isRTL: mock.isRTL,
|
|
1673
|
-
doLeftAndRightSwapInRTL: mock.doLeftAndRightSwapInRTL
|
|
1674
|
-
})),
|
|
1675
|
-
_reset: () => {
|
|
1676
|
-
mock.isRTL = false;
|
|
1677
|
-
mock.doLeftAndRightSwapInRTL = true;
|
|
1678
|
-
}
|
|
1679
|
-
};
|
|
1680
|
-
return mock;
|
|
1681
|
-
}
|
|
1682
|
-
//#endregion
|
|
1683
|
-
//#region src/mocks/apis/DeviceEventEmitter.ts
|
|
1684
|
-
function createDeviceEventEmitterMock() {
|
|
1685
|
-
const listeners = /* @__PURE__ */ new Map();
|
|
1686
|
-
return {
|
|
1687
|
-
addListener: vitest.vi.fn((event, handler) => {
|
|
1688
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1689
|
-
listeners.get(event).add(handler);
|
|
1690
|
-
return { remove: vitest.vi.fn(() => listeners.get(event)?.delete(handler)) };
|
|
1691
|
-
}),
|
|
1692
|
-
removeListener: vitest.vi.fn((event, handler) => {
|
|
1693
|
-
listeners.get(event)?.delete(handler);
|
|
1694
|
-
}),
|
|
1695
|
-
removeAllListeners: vitest.vi.fn((event) => {
|
|
1696
|
-
if (event) listeners.delete(event);
|
|
1697
|
-
else listeners.clear();
|
|
1698
|
-
}),
|
|
1699
|
-
removeSubscription: vitest.vi.fn(),
|
|
1700
|
-
emit: vitest.vi.fn((event, ...args) => {
|
|
1701
|
-
listeners.get(event)?.forEach((fn) => fn(...args));
|
|
1702
|
-
}),
|
|
1703
|
-
listenerCount: vitest.vi.fn((event) => listeners.get(event)?.size ?? 0),
|
|
1704
|
-
_reset: () => {
|
|
1705
|
-
listeners.clear();
|
|
1706
|
-
}
|
|
1707
|
-
};
|
|
1708
|
-
}
|
|
1709
|
-
//#endregion
|
|
1710
|
-
//#region src/mocks/apis/useColorScheme.ts
|
|
1711
|
-
function createUseColorSchemeMock() {
|
|
1712
|
-
let scheme = "light";
|
|
1713
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1714
|
-
const hook = () => {
|
|
1715
|
-
try {
|
|
1716
|
-
const [currentScheme, setCurrentScheme] = react.default.useState(scheme);
|
|
1717
|
-
react.default.useEffect(() => {
|
|
1718
|
-
listeners.add(setCurrentScheme);
|
|
1719
|
-
return () => {
|
|
1720
|
-
listeners.delete(setCurrentScheme);
|
|
1721
|
-
};
|
|
1722
|
-
}, []);
|
|
1723
|
-
return currentScheme;
|
|
1724
|
-
} catch {
|
|
1725
|
-
return scheme;
|
|
1726
|
-
}
|
|
1727
|
-
};
|
|
1728
|
-
hook._setScheme = (s) => {
|
|
1729
|
-
scheme = s;
|
|
1730
|
-
listeners.forEach((fn) => fn(s));
|
|
1731
|
-
};
|
|
1732
|
-
hook._resetScheme = (s) => {
|
|
1733
|
-
scheme = s;
|
|
1734
|
-
listeners.clear();
|
|
1735
|
-
};
|
|
1736
|
-
return hook;
|
|
1737
|
-
}
|
|
1738
|
-
//#endregion
|
|
1739
|
-
//#region src/mocks/apis/useWindowDimensions.ts
|
|
1740
|
-
function createUseWindowDimensionsMock() {
|
|
1741
|
-
let dims = {
|
|
1742
|
-
width: 390,
|
|
1743
|
-
height: 844,
|
|
1744
|
-
scale: 3,
|
|
1745
|
-
fontScale: 1
|
|
1746
|
-
};
|
|
1747
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1748
|
-
const hook = () => {
|
|
1749
|
-
try {
|
|
1750
|
-
const [currentDims, setCurrentDims] = react.default.useState({ ...dims });
|
|
1751
|
-
react.default.useEffect(() => {
|
|
1752
|
-
listeners.add(setCurrentDims);
|
|
1753
|
-
return () => {
|
|
1754
|
-
listeners.delete(setCurrentDims);
|
|
1755
|
-
};
|
|
1756
|
-
}, []);
|
|
1757
|
-
return currentDims;
|
|
1758
|
-
} catch {
|
|
1759
|
-
return { ...dims };
|
|
1760
|
-
}
|
|
1761
|
-
};
|
|
1762
|
-
hook._setDimensions = (d) => {
|
|
1763
|
-
dims = {
|
|
1764
|
-
...dims,
|
|
1765
|
-
...d
|
|
1766
|
-
};
|
|
1767
|
-
listeners.forEach((fn) => fn({ ...dims }));
|
|
1768
|
-
};
|
|
1769
|
-
hook._resetDimensions = (d) => {
|
|
1770
|
-
dims = { ...d };
|
|
1771
|
-
listeners.clear();
|
|
1772
|
-
};
|
|
1773
|
-
return hook;
|
|
1774
|
-
}
|
|
1775
|
-
//#endregion
|
|
1776
|
-
//#region src/mocks/native/NativeModules.ts
|
|
1777
|
-
/**
|
|
1778
|
-
* Creates a callable proxy — used for module methods.
|
|
1779
|
-
* Calling it returns undefined; accessing properties returns another
|
|
1780
|
-
* callable proxy (supporting arbitrary depth like Foo.bar.baz()).
|
|
1781
|
-
*/
|
|
1782
|
-
function createCallableProxy() {
|
|
1783
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1784
|
-
const noop = () => {};
|
|
1785
|
-
return new Proxy(noop, {
|
|
1786
|
-
get(_target, prop) {
|
|
1787
|
-
if (typeof prop === "symbol") return void 0;
|
|
1788
|
-
if (cache.has(prop)) return cache.get(prop);
|
|
1789
|
-
const child = createCallableProxy();
|
|
1790
|
-
cache.set(prop, child);
|
|
1791
|
-
return child;
|
|
1792
|
-
},
|
|
1793
|
-
apply() {}
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
/**
|
|
1797
|
-
* Creates an object proxy for a native module.
|
|
1798
|
-
* typeof returns "object" (matching real RN), property access returns
|
|
1799
|
-
* callable proxies so NativeModules.Foo.bar() works without throwing.
|
|
1800
|
-
*
|
|
1801
|
-
* Property accesses are cached so that NativeModules.Foo === NativeModules.Foo
|
|
1802
|
-
* holds true, matching real React Native identity semantics.
|
|
1803
|
-
*/
|
|
1804
|
-
function createModuleProxy$1() {
|
|
1805
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1806
|
-
return new Proxy({}, { get(_target, prop) {
|
|
1807
|
-
if (typeof prop === "symbol") return void 0;
|
|
1808
|
-
if (cache.has(prop)) return cache.get(prop);
|
|
1809
|
-
const child = createCallableProxy();
|
|
1810
|
-
cache.set(prop, child);
|
|
1811
|
-
return child;
|
|
1812
|
-
} });
|
|
1813
|
-
}
|
|
1814
|
-
function createNativeModulesMock() {
|
|
1815
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1816
|
-
return new Proxy({}, { get(_target, prop) {
|
|
1817
|
-
if (typeof prop === "symbol") return void 0;
|
|
1818
|
-
if (cache.has(prop)) return cache.get(prop);
|
|
1819
|
-
const child = createModuleProxy$1();
|
|
1820
|
-
cache.set(prop, child);
|
|
1821
|
-
return child;
|
|
1822
|
-
} });
|
|
1823
|
-
}
|
|
1824
|
-
//#endregion
|
|
1825
|
-
//#region src/mocks/native/TurboModuleRegistry.ts
|
|
1826
|
-
function createModuleProxy() {
|
|
1827
|
-
return new Proxy({}, { get(_target, prop) {
|
|
1828
|
-
if (typeof prop === "symbol") return void 0;
|
|
1829
|
-
if (prop === "then") return void 0;
|
|
1830
|
-
return () => {};
|
|
1831
|
-
} });
|
|
1832
|
-
}
|
|
1833
|
-
function createTurboModuleRegistryMock() {
|
|
1834
|
-
return {
|
|
1835
|
-
getEnforcing(_name) {
|
|
1836
|
-
return createModuleProxy();
|
|
1837
|
-
},
|
|
1838
|
-
get(_name) {
|
|
1839
|
-
return null;
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
}
|
|
1843
|
-
//#endregion
|
|
1844
|
-
//#region src/mocks/native/UIManager.ts
|
|
1845
|
-
function createUIManagerMock() {
|
|
1846
|
-
return {
|
|
1847
|
-
measure: vitest.vi.fn((_node, callback) => {
|
|
1848
|
-
callback(0, 0, 0, 0, 0, 0);
|
|
1849
|
-
}),
|
|
1850
|
-
measureInWindow: vitest.vi.fn((_node, callback) => {
|
|
1851
|
-
callback(0, 0, 0, 0);
|
|
1852
|
-
}),
|
|
1853
|
-
measureLayout: vitest.vi.fn((_node, _relativeNode, _onFail, onSuccess) => {
|
|
1854
|
-
onSuccess(0, 0, 0, 0);
|
|
1855
|
-
}),
|
|
1856
|
-
setChildren: vitest.vi.fn(),
|
|
1857
|
-
manageChildren: vitest.vi.fn(),
|
|
1858
|
-
createView: vitest.vi.fn(),
|
|
1859
|
-
updateView: vitest.vi.fn(),
|
|
1860
|
-
removeSubviewsFromContainerWithID: vitest.vi.fn(),
|
|
1861
|
-
replaceExistingNonRootView: vitest.vi.fn(),
|
|
1862
|
-
setLayoutAnimationEnabledExperimental: vitest.vi.fn(),
|
|
1863
|
-
configureNextLayoutAnimation: vitest.vi.fn(),
|
|
1864
|
-
getViewManagerConfig: vitest.vi.fn((_name) => ({})),
|
|
1865
|
-
hasViewManagerConfig: vitest.vi.fn((_name) => false),
|
|
1866
|
-
dispatchViewManagerCommand: vitest.vi.fn(),
|
|
1867
|
-
findSubviewIn: vitest.vi.fn(),
|
|
1868
|
-
viewIsDescendantOf: vitest.vi.fn()
|
|
1869
|
-
};
|
|
1870
|
-
}
|
|
1871
|
-
//#endregion
|
|
1872
|
-
//#region src/mocks/native/NativeEventEmitter.ts
|
|
1873
|
-
function createNativeEventEmitterMock() {
|
|
1874
|
-
return class NativeEventEmitter {
|
|
1875
|
-
listeners = /* @__PURE__ */ new Map();
|
|
1876
|
-
addListener(event, handler) {
|
|
1877
|
-
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
1878
|
-
this.listeners.get(event).add(handler);
|
|
1879
|
-
return { remove: () => {
|
|
1880
|
-
this.listeners.get(event)?.delete(handler);
|
|
1881
|
-
} };
|
|
1882
|
-
}
|
|
1883
|
-
removeAllListeners(event) {
|
|
1884
|
-
if (event) this.listeners.delete(event);
|
|
1885
|
-
else this.listeners.clear();
|
|
1886
|
-
}
|
|
1887
|
-
emit(event, ...args) {
|
|
1888
|
-
this.listeners.get(event)?.forEach((handler) => handler(...args));
|
|
1889
|
-
}
|
|
1890
|
-
listenerCount(event) {
|
|
1891
|
-
return this.listeners.get(event)?.size ?? 0;
|
|
1892
|
-
}
|
|
1893
|
-
};
|
|
1894
|
-
}
|
|
1895
|
-
//#endregion
|
|
1896
|
-
//#region src/mocks/native/NativeComponentRegistry.ts
|
|
1897
|
-
function createNativeComponentRegistryMock() {
|
|
1898
|
-
return {
|
|
1899
|
-
get(name) {
|
|
1900
|
-
const Component = react.default.forwardRef((props, ref) => {
|
|
1901
|
-
return react.default.createElement(name, {
|
|
1902
|
-
...props,
|
|
1903
|
-
ref
|
|
1904
|
-
});
|
|
1905
|
-
});
|
|
1906
|
-
Component.displayName = name;
|
|
1907
|
-
return Component;
|
|
1908
|
-
},
|
|
1909
|
-
getWithFallback(name) {
|
|
1910
|
-
return this.get(name);
|
|
1911
|
-
}
|
|
1912
|
-
};
|
|
1913
|
-
}
|
|
1914
|
-
//#endregion
|
|
1915
|
-
//#region src/mocks/native/requireNativeComponent.ts
|
|
1916
|
-
function createRequireNativeComponentMock() {
|
|
1917
|
-
return function requireNativeComponent(viewName) {
|
|
1918
|
-
const Component = react.default.forwardRef((props, ref) => {
|
|
1919
|
-
return react.default.createElement(viewName, {
|
|
1920
|
-
...props,
|
|
1921
|
-
ref
|
|
1922
|
-
});
|
|
1923
|
-
});
|
|
1924
|
-
Component.displayName = viewName;
|
|
1925
|
-
return Component;
|
|
1926
|
-
};
|
|
1927
|
-
}
|
|
1928
|
-
//#endregion
|
|
1929
|
-
//#region src/mocks/registry.ts
|
|
1930
|
-
function createAppRegistryMock() {
|
|
1931
|
-
return {
|
|
1932
|
-
registerComponent: vitest.vi.fn(),
|
|
1933
|
-
registerRunnable: vitest.vi.fn(),
|
|
1934
|
-
registerSection: vitest.vi.fn(),
|
|
1935
|
-
getAppKeys: vitest.vi.fn(() => []),
|
|
1936
|
-
unmountApplicationComponentAtRootTag: vitest.vi.fn(),
|
|
1937
|
-
runApplication: vitest.vi.fn(),
|
|
1938
|
-
setSurfaceProps: vitest.vi.fn(),
|
|
1939
|
-
registerHeadlessTask: vitest.vi.fn(),
|
|
1940
|
-
registerCancellableHeadlessTask: vitest.vi.fn(),
|
|
1941
|
-
startHeadlessTask: vitest.vi.fn(),
|
|
1942
|
-
cancelHeadlessTask: vitest.vi.fn()
|
|
1943
|
-
};
|
|
1944
|
-
}
|
|
1945
|
-
function hslToRgb(h, s, l) {
|
|
1946
|
-
const sNorm = s / 100;
|
|
1947
|
-
const lNorm = l / 100;
|
|
1948
|
-
const c = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
|
|
1949
|
-
const hPrime = h / 60;
|
|
1950
|
-
const x = c * (1 - Math.abs(hPrime % 2 - 1));
|
|
1951
|
-
let r1 = 0, g1 = 0, b1 = 0;
|
|
1952
|
-
if (hPrime < 1) {
|
|
1953
|
-
r1 = c;
|
|
1954
|
-
g1 = x;
|
|
1955
|
-
} else if (hPrime < 2) {
|
|
1956
|
-
r1 = x;
|
|
1957
|
-
g1 = c;
|
|
1958
|
-
} else if (hPrime < 3) {
|
|
1959
|
-
g1 = c;
|
|
1960
|
-
b1 = x;
|
|
1961
|
-
} else if (hPrime < 4) {
|
|
1962
|
-
g1 = x;
|
|
1963
|
-
b1 = c;
|
|
1964
|
-
} else if (hPrime < 5) {
|
|
1965
|
-
r1 = x;
|
|
1966
|
-
b1 = c;
|
|
1967
|
-
} else {
|
|
1968
|
-
r1 = c;
|
|
1969
|
-
b1 = x;
|
|
1970
|
-
}
|
|
1971
|
-
const m = lNorm - c / 2;
|
|
1972
|
-
return [
|
|
1973
|
-
Math.round((r1 + m) * 255),
|
|
1974
|
-
Math.round((g1 + m) * 255),
|
|
1975
|
-
Math.round((b1 + m) * 255)
|
|
1976
|
-
];
|
|
1977
|
-
}
|
|
1978
|
-
function createProcessColorMock() {
|
|
1979
|
-
const namedColors = {
|
|
1980
|
-
red: 4294901760,
|
|
1981
|
-
green: 4278222848,
|
|
1982
|
-
blue: 4278190335,
|
|
1983
|
-
white: 4294967295,
|
|
1984
|
-
black: 4278190080,
|
|
1985
|
-
transparent: 0,
|
|
1986
|
-
yellow: 4294967040,
|
|
1987
|
-
cyan: 4278255615,
|
|
1988
|
-
magenta: 4294902015,
|
|
1989
|
-
orange: 4294944e3,
|
|
1990
|
-
purple: 4286578816,
|
|
1991
|
-
gray: 4286611584,
|
|
1992
|
-
grey: 4286611584
|
|
1993
|
-
};
|
|
1994
|
-
return vitest.vi.fn((color) => {
|
|
1995
|
-
if (color == null) return null;
|
|
1996
|
-
if (typeof color === "number") return color;
|
|
1997
|
-
if (typeof color === "string") {
|
|
1998
|
-
const lower = color.toLowerCase().trim();
|
|
1999
|
-
if (namedColors[lower] != null) return namedColors[lower];
|
|
2000
|
-
const hex6 = lower.match(/^#([0-9a-f]{6})$/);
|
|
2001
|
-
if (hex6) return 4278190080 + parseInt(hex6[1], 16) >>> 0;
|
|
2002
|
-
const hex3 = lower.match(/^#([0-9a-f]{3})$/);
|
|
2003
|
-
if (hex3) {
|
|
2004
|
-
const [r, g, b] = hex3[1].split("");
|
|
2005
|
-
return 4278190080 + parseInt(`${r}${r}${g}${g}${b}${b}`, 16) >>> 0;
|
|
2006
|
-
}
|
|
2007
|
-
const hex8 = lower.match(/^#([0-9a-f]{8})$/);
|
|
2008
|
-
if (hex8) {
|
|
2009
|
-
const rgb = parseInt(hex8[1].slice(0, 6), 16);
|
|
2010
|
-
return (parseInt(hex8[1].slice(6, 8), 16) << 24) + rgb >>> 0;
|
|
2011
|
-
}
|
|
2012
|
-
const rgbMatch = lower.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
|
|
2013
|
-
if (rgbMatch) {
|
|
2014
|
-
const [, r, g, b] = rgbMatch;
|
|
2015
|
-
return (255 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b) >>> 0;
|
|
2016
|
-
}
|
|
2017
|
-
const rgbaMatch = lower.match(/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)$/);
|
|
2018
|
-
if (rgbaMatch) {
|
|
2019
|
-
const [, r, g, b, a] = rgbaMatch;
|
|
2020
|
-
return (Math.round(parseFloat(a) * 255) << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b) >>> 0;
|
|
2021
|
-
}
|
|
2022
|
-
const hslMatch = lower.match(/^hsl\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*\)$/);
|
|
2023
|
-
if (hslMatch) {
|
|
2024
|
-
const [, h, s, l] = hslMatch;
|
|
2025
|
-
const [r, g, b] = hslToRgb(parseFloat(h), parseFloat(s), parseFloat(l));
|
|
2026
|
-
return (255 << 24) + (r << 16) + (g << 8) + b >>> 0;
|
|
2027
|
-
}
|
|
2028
|
-
const hslaMatch = lower.match(/^hsla\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*,\s*([\d.]+)\s*\)$/);
|
|
2029
|
-
if (hslaMatch) {
|
|
2030
|
-
const [, h, s, l, a] = hslaMatch;
|
|
2031
|
-
const [r, g, b] = hslToRgb(parseFloat(h), parseFloat(s), parseFloat(l));
|
|
2032
|
-
return (Math.round(parseFloat(a) * 255) << 24) + (r << 16) + (g << 8) + b >>> 0;
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
return 4278190080;
|
|
2036
|
-
});
|
|
2037
|
-
}
|
|
2038
|
-
function createFindNodeHandleMock() {
|
|
2039
|
-
return vitest.vi.fn((_componentOrHandle) => null);
|
|
2040
|
-
}
|
|
2041
|
-
function createPlatformColorMock() {
|
|
2042
|
-
return vitest.vi.fn((..._names) => "PlatformColor");
|
|
2043
|
-
}
|
|
2044
|
-
function createDynamicColorIOSMock() {
|
|
2045
|
-
return vitest.vi.fn((_config) => "DynamicColorIOS");
|
|
2046
|
-
}
|
|
2047
|
-
function createSettingsMock() {
|
|
2048
|
-
const settings = {};
|
|
2049
|
-
return {
|
|
2050
|
-
get: vitest.vi.fn((key) => settings[key]),
|
|
2051
|
-
set: vitest.vi.fn((obj) => Object.assign(settings, obj)),
|
|
2052
|
-
watchKeys: vitest.vi.fn(() => 0),
|
|
2053
|
-
clearWatch: vitest.vi.fn()
|
|
2054
|
-
};
|
|
2055
|
-
}
|
|
2056
|
-
function createDeviceInfoMock() {
|
|
2057
|
-
return { getConstants: vitest.vi.fn(() => ({ Dimensions: {
|
|
2058
|
-
window: {
|
|
2059
|
-
width: 390,
|
|
2060
|
-
height: 844,
|
|
2061
|
-
scale: 3,
|
|
2062
|
-
fontScale: 1
|
|
2063
|
-
},
|
|
2064
|
-
screen: {
|
|
2065
|
-
width: 390,
|
|
2066
|
-
height: 844,
|
|
2067
|
-
scale: 3,
|
|
2068
|
-
fontScale: 1
|
|
2069
|
-
}
|
|
2070
|
-
} })) };
|
|
2071
|
-
}
|
|
2072
|
-
function createVirtualizedSectionListMock() {
|
|
2073
|
-
const VirtualizedSectionList = react.default.forwardRef((props, ref) => {
|
|
2074
|
-
const { sections, renderItem, renderSectionHeader, keyExtractor, ...rest } = props;
|
|
2075
|
-
const children = [];
|
|
2076
|
-
if (sections) sections.forEach((section, sectionIndex) => {
|
|
2077
|
-
if (renderSectionHeader) children.push(react.default.createElement(react.default.Fragment, { key: `h-${sectionIndex}` }, renderSectionHeader({ section })));
|
|
2078
|
-
if (section.data) section.data.forEach((item, index) => {
|
|
2079
|
-
const key = keyExtractor ? keyExtractor(item, index) : `${sectionIndex}-${index}`;
|
|
2080
|
-
children.push(react.default.createElement(react.default.Fragment, { key }, renderItem({
|
|
2081
|
-
item,
|
|
2082
|
-
index,
|
|
2083
|
-
section,
|
|
2084
|
-
separators: {}
|
|
2085
|
-
})));
|
|
2086
|
-
});
|
|
2087
|
-
});
|
|
2088
|
-
return react.default.createElement("VirtualizedSectionList", {
|
|
2089
|
-
...rest,
|
|
2090
|
-
ref
|
|
2091
|
-
}, ...children);
|
|
2092
|
-
});
|
|
2093
|
-
VirtualizedSectionList.displayName = "VirtualizedSectionList";
|
|
2094
|
-
return VirtualizedSectionList;
|
|
2095
|
-
}
|
|
2096
|
-
function createTouchableMock() {
|
|
2097
|
-
return {
|
|
2098
|
-
Mixin: {},
|
|
2099
|
-
TOUCH_TARGET_DEBUG: false,
|
|
2100
|
-
renderDebugView: vitest.vi.fn(() => null)
|
|
2101
|
-
};
|
|
2102
|
-
}
|
|
2103
|
-
function createUseAnimatedValueMock() {
|
|
2104
|
-
return vitest.vi.fn((initialValue) => {
|
|
2105
|
-
return new (createAnimatedMock()).Value(initialValue);
|
|
2106
|
-
});
|
|
2107
|
-
}
|
|
2108
|
-
function createUseAnimatedValueXYMock() {
|
|
2109
|
-
return vitest.vi.fn((initialValue) => {
|
|
2110
|
-
return new (createAnimatedMock()).ValueXY(initialValue);
|
|
2111
|
-
});
|
|
2112
|
-
}
|
|
2113
|
-
function createUseAnimatedColorMock() {
|
|
2114
|
-
return vitest.vi.fn((initialValue) => {
|
|
2115
|
-
return new (createAnimatedMock()).Color(initialValue);
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
function buildReactNativeMock(platform = "ios") {
|
|
2119
|
-
const mock = {
|
|
2120
|
-
View: require_presets.createViewMock(),
|
|
2121
|
-
Text: createTextMock(),
|
|
2122
|
-
Image: createImageMock(),
|
|
2123
|
-
TextInput: require_presets.createTextInputMock(),
|
|
2124
|
-
ScrollView: require_presets.createScrollViewMock(),
|
|
2125
|
-
FlatList: require_presets.createFlatListMock(),
|
|
2126
|
-
SectionList: require_presets.createSectionListMock(),
|
|
2127
|
-
Modal: createModalMock(),
|
|
2128
|
-
Pressable: require_presets.createPressableMock(),
|
|
2129
|
-
TouchableOpacity: require_presets.createTouchableOpacityMock(),
|
|
2130
|
-
TouchableHighlight: require_presets.createTouchableHighlightMock(),
|
|
2131
|
-
TouchableWithoutFeedback: require_presets.createTouchableWithoutFeedbackMock(),
|
|
2132
|
-
TouchableNativeFeedback: createTouchableNativeFeedbackMock(),
|
|
2133
|
-
ActivityIndicator: createActivityIndicatorMock(),
|
|
2134
|
-
Button: createButtonMock(),
|
|
2135
|
-
Switch: createSwitchMock(),
|
|
2136
|
-
RefreshControl: createRefreshControlMock(),
|
|
2137
|
-
StatusBar: createStatusBarMock(),
|
|
2138
|
-
SafeAreaView: createSafeAreaViewMock(),
|
|
2139
|
-
KeyboardAvoidingView: createKeyboardAvoidingViewMock(),
|
|
2140
|
-
ImageBackground: createImageBackgroundMock(),
|
|
2141
|
-
VirtualizedList: require_presets.createVirtualizedListMock(),
|
|
2142
|
-
InputAccessoryView: createInputAccessoryViewMock(),
|
|
2143
|
-
DrawerLayoutAndroid: createDrawerLayoutAndroidMock(),
|
|
2144
|
-
Platform: createPlatformMock(platform),
|
|
2145
|
-
Dimensions: createDimensionsMock(),
|
|
2146
|
-
StyleSheet: createStyleSheetMock(() => mock.Dimensions.get("window").scale),
|
|
2147
|
-
Animated: createAnimatedMock(),
|
|
2148
|
-
Alert: createAlertMock(),
|
|
2149
|
-
Linking: createLinkingMock(),
|
|
2150
|
-
AppState: createAppStateMock(),
|
|
2151
|
-
Keyboard: createKeyboardMock(),
|
|
2152
|
-
BackHandler: createBackHandlerMock(),
|
|
2153
|
-
Vibration: createVibrationMock(),
|
|
2154
|
-
PermissionsAndroid: createPermissionsAndroidMock(),
|
|
2155
|
-
Appearance: createAppearanceMock(),
|
|
2156
|
-
PixelRatio: void 0,
|
|
2157
|
-
LayoutAnimation: createLayoutAnimationMock(),
|
|
2158
|
-
Clipboard: createClipboardMock(),
|
|
2159
|
-
Share: createShareMock(),
|
|
2160
|
-
AccessibilityInfo: createAccessibilityInfoMock(),
|
|
2161
|
-
InteractionManager: createInteractionManagerMock(),
|
|
2162
|
-
PanResponder: createPanResponderMock(),
|
|
2163
|
-
ToastAndroid: createToastAndroidMock(),
|
|
2164
|
-
ActionSheetIOS: createActionSheetIOSMock(),
|
|
2165
|
-
LogBox: createLogBoxMock(),
|
|
2166
|
-
Easing: createEasingMock(),
|
|
2167
|
-
I18nManager: createI18nManagerMock(),
|
|
2168
|
-
DeviceEventEmitter: createDeviceEventEmitterMock(),
|
|
2169
|
-
useColorScheme: createUseColorSchemeMock(),
|
|
2170
|
-
useWindowDimensions: createUseWindowDimensionsMock(),
|
|
2171
|
-
NativeModules: createNativeModulesMock(),
|
|
2172
|
-
TurboModuleRegistry: createTurboModuleRegistryMock(),
|
|
2173
|
-
UIManager: createUIManagerMock(),
|
|
2174
|
-
NativeEventEmitter: createNativeEventEmitterMock(),
|
|
2175
|
-
NativeAppEventEmitter: createDeviceEventEmitterMock(),
|
|
2176
|
-
EventEmitter: createNativeEventEmitterMock(),
|
|
2177
|
-
NativeComponentRegistry: createNativeComponentRegistryMock(),
|
|
2178
|
-
requireNativeComponent: createRequireNativeComponentMock(),
|
|
2179
|
-
AppRegistry: createAppRegistryMock(),
|
|
2180
|
-
VirtualizedSectionList: createVirtualizedSectionListMock(),
|
|
2181
|
-
Touchable: createTouchableMock(),
|
|
2182
|
-
processColor: createProcessColorMock(),
|
|
2183
|
-
findNodeHandle: createFindNodeHandleMock(),
|
|
2184
|
-
PlatformColor: createPlatformColorMock(),
|
|
2185
|
-
DynamicColorIOS: createDynamicColorIOSMock(),
|
|
2186
|
-
Settings: createSettingsMock(),
|
|
2187
|
-
DeviceInfo: createDeviceInfoMock(),
|
|
2188
|
-
useAnimatedValue: createUseAnimatedValueMock(),
|
|
2189
|
-
useAnimatedValueXY: createUseAnimatedValueXYMock(),
|
|
2190
|
-
useAnimatedColor: createUseAnimatedColorMock(),
|
|
2191
|
-
RootTagContext: react.default.createContext(null),
|
|
2192
|
-
ReactNativeVersion: {
|
|
2193
|
-
major: 0,
|
|
2194
|
-
minor: 76,
|
|
2195
|
-
patch: 0
|
|
2196
|
-
},
|
|
2197
|
-
Systrace: {
|
|
2198
|
-
beginEvent: vitest.vi.fn(),
|
|
2199
|
-
endEvent: vitest.vi.fn(),
|
|
2200
|
-
beginAsyncEvent: vitest.vi.fn(() => 0),
|
|
2201
|
-
endAsyncEvent: vitest.vi.fn(),
|
|
2202
|
-
counterEvent: vitest.vi.fn(),
|
|
2203
|
-
isEnabled: vitest.vi.fn(() => false)
|
|
2204
|
-
},
|
|
2205
|
-
DevSettings: {
|
|
2206
|
-
addMenuItem: vitest.vi.fn(),
|
|
2207
|
-
reload: vitest.vi.fn()
|
|
2208
|
-
},
|
|
2209
|
-
Networking: {
|
|
2210
|
-
addListener: vitest.vi.fn(),
|
|
2211
|
-
removeListeners: vitest.vi.fn()
|
|
2212
|
-
},
|
|
2213
|
-
unstable_batchedUpdates: vitest.vi.fn((fn) => fn()),
|
|
2214
|
-
registerCallableModule: vitest.vi.fn(),
|
|
2215
|
-
codegenNativeCommands: vitest.vi.fn(() => ({})),
|
|
2216
|
-
codegenNativeComponent: vitest.vi.fn((name) => name),
|
|
2217
|
-
UTFSequence: {
|
|
2218
|
-
BOM: "",
|
|
2219
|
-
BULLET: "•",
|
|
2220
|
-
MIDDOT: "·",
|
|
2221
|
-
NBSP: "\xA0"
|
|
2222
|
-
},
|
|
2223
|
-
ProgressBarAndroid: (() => {
|
|
2224
|
-
const C = react.default.forwardRef((props, ref) => react.default.createElement("ProgressBarAndroid", {
|
|
2225
|
-
...props,
|
|
2226
|
-
ref
|
|
2227
|
-
}));
|
|
2228
|
-
C.displayName = "ProgressBarAndroid";
|
|
2229
|
-
return C;
|
|
2230
|
-
})(),
|
|
2231
|
-
PushNotificationIOS: {
|
|
2232
|
-
presentLocalNotification: vitest.vi.fn(),
|
|
2233
|
-
scheduleLocalNotification: vitest.vi.fn(),
|
|
2234
|
-
cancelAllLocalNotifications: vitest.vi.fn(),
|
|
2235
|
-
removeAllDeliveredNotifications: vitest.vi.fn(),
|
|
2236
|
-
getDeliveredNotifications: vitest.vi.fn(async () => []),
|
|
2237
|
-
addEventListener: vitest.vi.fn(() => ({ remove: vitest.vi.fn() })),
|
|
2238
|
-
requestPermissions: vitest.vi.fn(async () => ({
|
|
2239
|
-
alert: true,
|
|
2240
|
-
badge: true,
|
|
2241
|
-
sound: true
|
|
2242
|
-
})),
|
|
2243
|
-
getInitialNotification: vitest.vi.fn(async () => null)
|
|
2244
|
-
},
|
|
2245
|
-
NativeDialogManagerAndroid: { showAlert: vitest.vi.fn() },
|
|
2246
|
-
usePressability: vitest.vi.fn(() => ({})),
|
|
2247
|
-
default: void 0
|
|
2248
|
-
};
|
|
2249
|
-
mock.PixelRatio = createPixelRatioMock(() => mock.Dimensions.get("window"));
|
|
2250
|
-
const origSetColorScheme = mock.Appearance.setColorScheme;
|
|
2251
|
-
mock.Appearance.setColorScheme = vitest.vi.fn((scheme) => {
|
|
2252
|
-
origSetColorScheme(scheme);
|
|
2253
|
-
mock.useColorScheme._setScheme(scheme);
|
|
2254
|
-
});
|
|
2255
|
-
const origDimensionsSet = mock.Dimensions.set;
|
|
2256
|
-
mock.Dimensions.set = vitest.vi.fn((dims) => {
|
|
2257
|
-
origDimensionsSet(dims);
|
|
2258
|
-
if (dims.window) mock.useWindowDimensions._setDimensions(dims.window);
|
|
2259
|
-
});
|
|
2260
|
-
mock.default = mock;
|
|
2261
|
-
return mock;
|
|
2262
|
-
}
|
|
2263
|
-
//#endregion
|
|
2264
|
-
//#region src/cjs-bridge.ts
|
|
2265
|
-
/**
|
|
2266
|
-
* CJS Bridge — intercepts Node's require('react-native') so CJS consumers
|
|
2267
|
-
* (like @testing-library/react-native) resolve to our mocks instead of
|
|
2268
|
-
* the real Flow-typed source.
|
|
2269
|
-
*
|
|
2270
|
-
* Unlike v1, this uses Module._cache injection (no /tmp files) and stores
|
|
2271
|
-
* the original _resolveFilename for clean teardown.
|
|
2272
|
-
*
|
|
2273
|
-
* Safety: This mutates global Module state (Module._resolveFilename and
|
|
2274
|
-
* Module._cache). This is necessary because CJS require() has no plugin
|
|
2275
|
-
* system — interception is the only option. All mutations are tracked and
|
|
2276
|
-
* fully reversed by uninstallCjsBridge() which runs in afterAll().
|
|
2277
|
-
* Each vitest worker process gets its own Module state, so there's no
|
|
2278
|
-
* cross-test contamination in parallel runs.
|
|
2279
|
-
*/
|
|
2280
|
-
const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
|
|
2281
|
-
let originalResolveFilename = null;
|
|
2282
|
-
let installed = false;
|
|
2283
|
-
const presetRedirects = /* @__PURE__ */ new Map();
|
|
2284
|
-
function installCjsBridge(mockObject) {
|
|
2285
|
-
if (installed) return;
|
|
2286
|
-
try {
|
|
2287
|
-
const Module = require("node:module");
|
|
2288
|
-
const syntheticModule = new Module(VIRTUAL_RN_PATH);
|
|
2289
|
-
syntheticModule.id = VIRTUAL_RN_PATH;
|
|
2290
|
-
syntheticModule.filename = VIRTUAL_RN_PATH;
|
|
2291
|
-
syntheticModule.loaded = true;
|
|
2292
|
-
syntheticModule.exports = mockObject;
|
|
2293
|
-
Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
|
|
2294
|
-
originalResolveFilename = Module._resolveFilename;
|
|
2295
|
-
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
2296
|
-
if (request === "react-native" || request.startsWith("react-native/")) return VIRTUAL_RN_PATH;
|
|
2297
|
-
const exactMatch = presetRedirects.get(request);
|
|
2298
|
-
if (exactMatch) return exactMatch;
|
|
2299
|
-
const slashIdx = request.indexOf("/", request.startsWith("@") ? request.indexOf("/") + 1 : 0);
|
|
2300
|
-
if (slashIdx !== -1) {
|
|
2301
|
-
const pkg = request.slice(0, slashIdx);
|
|
2302
|
-
const subpathMatch = presetRedirects.get(pkg);
|
|
2303
|
-
if (subpathMatch) return subpathMatch;
|
|
2304
|
-
}
|
|
2305
|
-
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2306
|
-
};
|
|
2307
|
-
installed = true;
|
|
2308
|
-
} catch (e) {
|
|
2309
|
-
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge install failed: ${e?.message}`);
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
function uninstallCjsBridge() {
|
|
2313
|
-
if (!installed) return;
|
|
2314
|
-
try {
|
|
2315
|
-
const Module = require("node:module");
|
|
2316
|
-
if (originalResolveFilename) {
|
|
2317
|
-
Module._resolveFilename = originalResolveFilename;
|
|
2318
|
-
originalResolveFilename = null;
|
|
2319
|
-
}
|
|
2320
|
-
delete Module._cache[VIRTUAL_RN_PATH];
|
|
2321
|
-
for (const virtualPath of presetRedirects.values()) delete Module._cache[virtualPath];
|
|
2322
|
-
presetRedirects.clear();
|
|
2323
|
-
installed = false;
|
|
2324
|
-
} catch (e) {
|
|
2325
|
-
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
function installPresetCjsBridge(moduleName, mockObject) {
|
|
2329
|
-
try {
|
|
2330
|
-
const Module = require("node:module");
|
|
2331
|
-
const virtualPath = `\0vitest-native:preset:${moduleName}`;
|
|
2332
|
-
const syntheticModule = new Module(virtualPath);
|
|
2333
|
-
syntheticModule.id = virtualPath;
|
|
2334
|
-
syntheticModule.filename = virtualPath;
|
|
2335
|
-
syntheticModule.loaded = true;
|
|
2336
|
-
syntheticModule.exports = mockObject;
|
|
2337
|
-
Module._cache[virtualPath] = syntheticModule;
|
|
2338
|
-
presetRedirects.set(moduleName, virtualPath);
|
|
2339
|
-
} catch (e) {
|
|
2340
|
-
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
|
|
2341
|
-
}
|
|
2342
|
-
}
|
|
2343
|
-
//#endregion
|
|
2344
|
-
//#region src/setup.ts
|
|
2345
|
-
/**
|
|
2346
|
-
* Auto-injected setup file for vitest-native.
|
|
2347
|
-
*
|
|
2348
|
-
* This file is added to `test.setupFiles` by the Vite plugin. It:
|
|
2349
|
-
* 1. Sets React Native globals (__DEV__, requestAnimationFrame, etc.)
|
|
2350
|
-
* 2. Installs the CJS bridge so require('react-native') resolves to mocks
|
|
2351
|
-
* 3. Registers vi.mock('react-native') with the full mock object
|
|
2352
|
-
* 4. Auto-detects and installs preset mocks
|
|
2353
|
-
* 5. Configures @testing-library/react-native host component names
|
|
2354
|
-
* 6. Auto-registers RNTL matchers
|
|
2355
|
-
* 7. Registers snapshot serializer
|
|
2356
|
-
*
|
|
2357
|
-
* Options are received via process.env (set by the plugin's config() hook
|
|
2358
|
-
* via test.env). This is necessary because the plugin runs in Vite's main
|
|
2359
|
-
* process while this setup file runs in Vitest worker processes — globalThis
|
|
2360
|
-
* does NOT survive that boundary.
|
|
2361
|
-
*/
|
|
2362
|
-
const platform = process.env.VITEST_NATIVE_PLATFORM || "ios";
|
|
2363
|
-
const diagnostics = process.env.VITEST_NATIVE_DIAGNOSTICS === "true";
|
|
2364
|
-
const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
|
|
2365
|
-
const projectReq = (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json"));
|
|
2366
|
-
let customMocks = {};
|
|
2367
|
-
if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
2368
|
-
customMocks = JSON.parse(process.env.VITEST_NATIVE_MOCKS);
|
|
2369
|
-
} catch (e) {
|
|
2370
|
-
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_MOCKS: ${e?.message}`);
|
|
2371
|
-
}
|
|
2372
|
-
let explicitPresetNames = null;
|
|
2373
|
-
if (process.env.VITEST_NATIVE_PRESET_NAMES) try {
|
|
2374
|
-
explicitPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_NAMES);
|
|
2375
|
-
} catch (e) {
|
|
2376
|
-
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_PRESET_NAMES: ${e?.message}`);
|
|
2377
|
-
explicitPresetNames = null;
|
|
2378
|
-
}
|
|
2379
|
-
const g = globalThis;
|
|
2380
|
-
Object.defineProperties(g, {
|
|
2381
|
-
__DEV__: {
|
|
2382
|
-
configurable: true,
|
|
2383
|
-
enumerable: true,
|
|
2384
|
-
value: true,
|
|
2385
|
-
writable: true
|
|
2386
|
-
},
|
|
2387
|
-
requestAnimationFrame: {
|
|
2388
|
-
configurable: true,
|
|
2389
|
-
enumerable: true,
|
|
2390
|
-
value: (callback) => setTimeout(() => callback(Date.now()), 0),
|
|
2391
|
-
writable: true
|
|
2392
|
-
},
|
|
2393
|
-
cancelAnimationFrame: {
|
|
2394
|
-
configurable: true,
|
|
2395
|
-
enumerable: true,
|
|
2396
|
-
value: (id) => clearTimeout(id),
|
|
2397
|
-
writable: true
|
|
2398
|
-
},
|
|
2399
|
-
...typeof g.window === "undefined" ? { window: {
|
|
2400
|
-
configurable: true,
|
|
2401
|
-
enumerable: true,
|
|
2402
|
-
value: g,
|
|
2403
|
-
writable: true
|
|
2404
|
-
} } : {},
|
|
2405
|
-
nativeFabricUIManager: {
|
|
2406
|
-
configurable: true,
|
|
2407
|
-
enumerable: true,
|
|
2408
|
-
value: {},
|
|
2409
|
-
writable: true
|
|
2410
|
-
}
|
|
2411
|
-
});
|
|
2412
|
-
if (typeof g.expect === "undefined") Object.defineProperty(g, "expect", {
|
|
2413
|
-
configurable: true,
|
|
2414
|
-
enumerable: false,
|
|
2415
|
-
value: vitest.expect,
|
|
2416
|
-
writable: true
|
|
2417
|
-
});
|
|
2418
|
-
g.IS_REACT_ACT_ENVIRONMENT = true;
|
|
2419
|
-
g.IS_REACT_NATIVE_TEST_ENVIRONMENT = true;
|
|
2420
|
-
const rnMock = buildReactNativeMock(platform);
|
|
2421
|
-
if (Object.keys(customMocks).length > 0) Object.assign(rnMock, customMocks);
|
|
2422
|
-
g.__vitest_native_mock = rnMock;
|
|
2423
|
-
installCjsBridge(rnMock);
|
|
2424
|
-
vitest.vi.mock("react-native", () => rnMock);
|
|
2425
|
-
/** Load a preset factory by its export name. */
|
|
2426
|
-
function loadPresetFactory(exportName) {
|
|
2427
|
-
const factory = require_presets.presets_exports[exportName];
|
|
2428
|
-
return typeof factory === "function" ? factory : null;
|
|
2429
|
-
}
|
|
2430
|
-
function autoDetectPresets() {
|
|
2431
|
-
const detected = [];
|
|
2432
|
-
const enabled = /* @__PURE__ */ new Set();
|
|
2433
|
-
for (const [pkgName, exportName] of Object.entries(require_preset_map.AUTO_DETECT_PRESETS)) try {
|
|
2434
|
-
projectReq.resolve(pkgName);
|
|
2435
|
-
if (enabled.has(exportName)) continue;
|
|
2436
|
-
const factory = loadPresetFactory(exportName);
|
|
2437
|
-
if (factory) {
|
|
2438
|
-
detected.push(factory());
|
|
2439
|
-
enabled.add(exportName);
|
|
2440
|
-
if (diagnostics) console.log(`[vitest-native] Auto-detected ${pkgName} → enabled ${exportName} preset`);
|
|
2441
|
-
}
|
|
2442
|
-
} catch {}
|
|
2443
|
-
return detected;
|
|
2444
|
-
}
|
|
2445
|
-
function loadExplicitPresets(names) {
|
|
2446
|
-
const loaded = [];
|
|
2447
|
-
for (const name of names) {
|
|
2448
|
-
const factory = loadPresetFactory(name);
|
|
2449
|
-
if (factory) loaded.push(factory());
|
|
2450
|
-
}
|
|
2451
|
-
return loaded;
|
|
2452
|
-
}
|
|
2453
|
-
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets();
|
|
2454
|
-
g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
|
|
2455
|
-
for (const preset of presets) for (const [modName, presetModule] of Object.entries(preset.modules)) {
|
|
2456
|
-
const presetMock = presetModule.factory();
|
|
2457
|
-
installPresetCjsBridge(modName, presetMock);
|
|
2458
|
-
g.__vitest_native_preset_mocks[modName] = presetMock;
|
|
2459
|
-
if (diagnostics) console.log(`[vitest-native] Registered preset mock: ${modName} (${preset.name})`);
|
|
2460
|
-
}
|
|
2461
|
-
try {
|
|
2462
|
-
const rntl = projectReq("@testing-library/react-native");
|
|
2463
|
-
let rntlMajor = 0;
|
|
2464
|
-
try {
|
|
2465
|
-
const { version } = projectReq("@testing-library/react-native/package.json");
|
|
2466
|
-
rntlMajor = Number(String(version).split(".")[0]) || 0;
|
|
2467
|
-
} catch {}
|
|
2468
|
-
if (rntl?.configure && rntlMajor < 14) rntl.configure({ hostComponentNames: {
|
|
2469
|
-
text: "Text",
|
|
2470
|
-
textInput: "TextInput",
|
|
2471
|
-
switch: "RCTSwitch",
|
|
2472
|
-
scrollView: "RCTScrollView",
|
|
2473
|
-
modal: "Modal",
|
|
2474
|
-
image: "Image",
|
|
2475
|
-
button: "Button",
|
|
2476
|
-
pressable: "Pressable",
|
|
2477
|
-
view: "View",
|
|
2478
|
-
activityIndicator: "ActivityIndicator"
|
|
2479
|
-
} });
|
|
2480
|
-
} catch (e) {
|
|
2481
|
-
if (diagnostics) console.log(`[vitest-native] @testing-library/react-native not available: ${e?.message}`);
|
|
2482
|
-
}
|
|
2483
|
-
try {
|
|
2484
|
-
let matchers = null;
|
|
2485
|
-
let lastError;
|
|
2486
|
-
for (const moduleId of [
|
|
2487
|
-
"@testing-library/react-native/matchers",
|
|
2488
|
-
"@testing-library/react-native/build/matchers",
|
|
2489
|
-
"@testing-library/react-native/dist/matchers"
|
|
2490
|
-
]) try {
|
|
2491
|
-
matchers = projectReq(moduleId);
|
|
2492
|
-
break;
|
|
2493
|
-
} catch (error) {
|
|
2494
|
-
lastError = error;
|
|
2495
|
-
}
|
|
2496
|
-
if (!matchers) throw lastError;
|
|
2497
|
-
if (matchers && Object.keys(matchers).length > 0) {
|
|
2498
|
-
const matcherFns = {};
|
|
2499
|
-
for (const [key, val] of Object.entries(matchers)) if (typeof val === "function" && key !== "__esModule") matcherFns[key] = val;
|
|
2500
|
-
if (Object.keys(matcherFns).length > 0) {
|
|
2501
|
-
vitest.expect.extend(matcherFns);
|
|
2502
|
-
if (diagnostics) console.log(`[vitest-native] Registered ${Object.keys(matcherFns).length} RNTL matchers: ${Object.keys(matcherFns).join(", ")}`);
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
} catch (e) {
|
|
2506
|
-
if (diagnostics) console.log(`[vitest-native] Could not load RNTL matchers: ${e?.message}`);
|
|
2507
|
-
}
|
|
2508
|
-
vitest.expect.extend(require_matchers.animatedMatchers);
|
|
2509
|
-
if (diagnostics) console.log(`[vitest-native] Registered ${Object.keys(require_matchers.animatedMatchers).length} animated matchers: ${Object.keys(require_matchers.animatedMatchers).join(", ")}`);
|
|
2510
|
-
vitest.expect.addSnapshotSerializer(require_serializer.serializer);
|
|
2511
|
-
(0, vitest.afterAll)(() => {
|
|
2512
|
-
uninstallCjsBridge();
|
|
2513
|
-
});
|
|
2514
|
-
//#endregion
|