-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
43 lines (36 loc) · 1.09 KB
/
vitest.setup.ts
File metadata and controls
43 lines (36 loc) · 1.09 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
// Simple File constructor polyfill for test environment
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
// First, ensure we have a basic Blob polyfill
if (typeof globalThis.Blob === 'undefined') {
(globalThis as any).Blob = class MockBlob {
size: number;
type: string;
constructor(blobParts: any[] = [], options: any = {}) {
this.type = options.type || '';
this.size = 0;
}
arrayBuffer() {
return Promise.resolve(new ArrayBuffer(0));
}
text() {
return Promise.resolve('');
}
slice() {
return new MockBlob();
}
};
}
// Now create File that extends Blob
if (typeof globalThis.File === 'undefined') {
(globalThis as any).File = class MockFile extends (globalThis as any).Blob {
name: string;
lastModified: number;
webkitRelativePath: string;
constructor(fileBits: any, fileName: any, options: any = {}) {
super(fileBits, options);
this.name = fileName;
this.lastModified = options.lastModified || Date.now();
this.webkitRelativePath = '';
}
};
}