-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
301 lines (256 loc) · 8.07 KB
/
vitest.setup.ts
File metadata and controls
301 lines (256 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// @ts-nocheck
import { beforeAll, afterAll, vi } from 'vitest';
// mock to allow tests to pass while globals attempt to polyfill crypto
vi.stubGlobal('crypto', {
randomUUID: vi.fn(() => 'mock-uuid'),
// Add other necessary crypto methods as mocks
});
// Mock out global variables and platform APIs touched while unit testing
global.__UNIT_TEST__ = true;
global.__DEV__ = true;
global.__ANDROID__ = false;
global.__IOS__ = true;
global.__VISIONOS__ = false;
global.__APPLE__ = true;
global.__COMMONJS__ = false;
global.WeakRef.prototype.get = global.WeakRef.prototype.deref;
global.NativeClass = function () {};
global.NSBundle = {
mainBundle: {
bundleIdentifier: 'test',
objectForInfoDictionaryKey(key: string) {
return true;
},
},
};
global.NSTimer = class NSTimer {};
global.NSObject = class NSObject {
static new() {
return new NSObject();
}
};
global.NSNumber = {};
global.NSString = {
stringWithString() {
return {
intValue: 13,
};
},
pathWithComponents(components: string[] | NSArray<string>) {
return {
stringByStandardizingPath: '',
};
},
};
// global.NSObject = class NSObject {};
global.NSFileManager = {
defaultManager: {
fileExistsAtPathIsDirectory(path: string, isDirectory?: boolean) {
return true;
},
},
};
global.NSNotificationCenter = {
defaultCenter: {
addObserverSelectorNameObject(observer: any, selector: any, name: any, object: any) {},
},
};
global.interop = {
Reference: class Reference {
constructor(type: any, ref?: boolean) {}
},
types: {
bool: {},
},
};
global.UIApplication = {
sharedApplication: {
statusBarOrientation: 1, // Portrait by default
},
};
global.UIDevice = {
currentDevice: {
systemVersion: '13.0',
},
};
global.UIScreen = {
mainScreen: {
scale: 1,
bounds: {
origin: {
x: 0,
y: 0,
},
size: {
height: 1000,
width: 1000,
},
},
},
};
global.UIInterfaceOrientation = {
Unknown: 0,
Portrait: 1,
PortraitUpsideDown: 2,
LandscapeLeft: 4,
LandscapeRight: 3,
};
global.UIWindowSceneDelegate = function () {};
const cgColors = { CGColor: 1 };
global.UIColor = {
alloc() {
return {
initWithRedGreenBlueAlpha(r, g, b, a) {
return {};
},
};
},
clearColor: cgColors,
};
global.UITextField = function () {};
global.UITextFieldDelegate = function () {};
global.NSSearchPathDirectory = {
LibraryDirectory: '',
DeveloperDirectory: '',
DesktopDirectory: '',
DownloadsDirectory: '',
};
global.NativeScriptUtils = {
createUIFont(descriptor: any) {
return {};
},
};
global.NSURLSessionConfiguration = {
defaultSessionConfiguration: function () {
return {};
},
ephemeralSessionConfiguration: function () {
return {};
},
};
global.NSURLSessionTaskDelegate = function () {};
global.NSOperationQueue = {
mainQueue: {
addOperationWithBlock(fn: Function) {
if (fn) {
fn();
}
},
},
};
global.NSThread = {
isMainThread: true,
};
global.CFRunLoopGetMain = function () {
return {};
};
global.kCFRunLoopDefaultMode = 1;
global.CFRunLoopPerformBlock = function (runloop, kCFRunLoopDefaultMode, func) {};
global.CFRunLoopWakeUp = function (runloop) {};
global.NativeScriptGlobals = {
events: {
on: (args) => {},
once: (args) => {},
off: (args) => {},
notify: (args) => {},
hasListeners: (args) => {},
},
};
global.CADisplayLink = function () {};
global.NSNotification = function () {};
global.UIApplicationDelegate = function () {};
global.UIApplicationDidFinishLaunchingNotification = 'UIApplicationDidFinishLaunchingNotification';
global.UIApplicationDidBecomeActiveNotification = 'UIApplicationDidBecomeActiveNotification';
global.UIApplicationDidEnterBackgroundNotification = 'UIApplicationDidEnterBackgroundNotification';
global.UIApplicationWillTerminateNotification = 'UIApplicationWillTerminateNotification';
global.UIApplicationDidReceiveMemoryWarningNotification = 'UIApplicationDidReceiveMemoryWarningNotification';
global.UIApplicationDidChangeStatusBarOrientationNotification = 'UIApplicationDidChangeStatusBarOrientationNotification';
global.UIResponder = function () {};
global.UIResponder.extend = function () {};
global.UIViewController = function () {};
global.UIViewControllerTransitioningDelegate = function () {};
global.UINavigationControllerDelegate = function () {};
global.UINavigationController = function () {};
global.UIUserInterfaceIdiom = {
Phone: 0,
Pad: 1,
TV: 2,
CarPlay: 3,
Mac: 4,
};
global.UIGestureRecognizer = function () {};
global.UIGestureRecognizerDelegate = function () {};
global.UIAdaptivePresentationControllerDelegate = function () {};
global.UIPopoverPresentationControllerDelegate = function () {};
global.UIContentSizeCategoryExtraSmall = 0.5;
global.UIContentSizeCategorySmall = 0.7;
global.UIContentSizeCategoryMedium = 0.85;
global.UIContentSizeCategoryLarge = 1;
global.UIContentSizeCategoryExtraLarge = 1.15;
global.UIContentSizeCategoryExtraExtraLarge = 1.3;
global.UIContentSizeCategoryExtraExtraExtraLarge = 1.5;
global.UIContentSizeCategoryAccessibilityMedium = 2;
global.UIContentSizeCategoryAccessibilityLarge = 2.5;
global.UIContentSizeCategoryAccessibilityExtraLarge = 3;
global.UIContentSizeCategoryAccessibilityExtraExtraLarge = 3.5;
global.UIContentSizeCategoryAccessibilityExtraExtraExtraLarge = 4;
global.UIViewControllerAnimatedTransitioning = function () {};
// global.UIDocumentInteractionController = {
// interactionControllerWithURL(url: any) {
// return null;
// },
// };
// global.NSURL = {
// fileURLWithPath(path: string) {
// return null;
// },
// };
// declare class UIDocumentInteractionController extends NSObject implements UIActionSheetDelegate {
// static alloc(): UIDocumentInteractionController; // inherited from NSObject
// static interactionControllerWithURL(url: NSURL): UIDocumentInteractionController;
// static new(): UIDocumentInteractionController; // inherited from NSObject
// URL: NSURL;
// UTI: string;
// annotation: any;
// delegate: UIDocumentInteractionControllerDelegate;
// readonly gestureRecognizers: NSArray<UIGestureRecognizer>;
// readonly icons: NSArray<UIImage>;
// name: string;
// readonly debugDescription: string; // inherited from NSObjectProtocol
// readonly description: string; // inherited from NSObjectProtocol
// readonly hash: number; // inherited from NSObjectProtocol
// readonly isProxy: boolean; // inherited from NSObjectProtocol
// readonly superclass: typeof NSObject; // inherited from NSObjectProtocol
// readonly // inherited from NSObjectProtocol
// actionSheetCancel(actionSheet: UIActionSheet): void;
// actionSheetClickedButtonAtIndex(actionSheet: UIActionSheet, buttonIndex: number): void;
// actionSheetDidDismissWithButtonIndex(actionSheet: UIActionSheet, buttonIndex: number): void;
// actionSheetWillDismissWithButtonIndex(actionSheet: UIActionSheet, buttonIndex: number): void;
// class(): typeof NSObject;
// conformsToProtocol(aProtocol: any /* Protocol */): boolean;
// didPresentActionSheet(actionSheet: UIActionSheet): void;
// dismissMenuAnimated(animated: boolean): void;
// dismissPreviewAnimated(animated: boolean): void;
// isEqual(object: any): boolean;
// isKindOfClass(aClass: typeof NSObject): boolean;
// isMemberOfClass(aClass: typeof NSObject): boolean;
// performSelector(aSelector: string): any;
// performSelectorWithObject(aSelector: string, object: any): any;
// performSelectorWithObjectWithObject(aSelector: string, object1: any, object2: any): any;
// presentOpenInMenuFromBarButtonItemAnimated(item: UIBarButtonItem, animated: boolean): boolean;
// presentOpenInMenuFromRectInViewAnimated(rect: CGRect, view: UIView, animated: boolean): boolean;
// presentOptionsMenuFromBarButtonItemAnimated(item: UIBarButtonItem, animated: boolean): boolean;
// presentOptionsMenuFromRectInViewAnimated(rect: CGRect, view: UIView, animated: boolean): boolean;
// presentPreviewAnimated(animated: boolean): boolean;
// respondsToSelector(aSelector: string): boolean;
// retainCount(): number;
// self(): this;
// willPresentActionSheet(actionSheet: UIActionSheet): void;
// }
// Example of a lifecycle hook
beforeAll(() => {
console.log('Setting up tests...');
});
afterAll(() => {
console.log('Cleaning up after tests...');
});