-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
103 lines (90 loc) · 2.31 KB
/
vitest.setup.ts
File metadata and controls
103 lines (90 loc) · 2.31 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
import '@testing-library/jest-dom';
// Mock window.matchMedia for Mantine
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: () => {},
removeListener: () => {},
addEventListener: () => {},
removeEventListener: () => {},
dispatchEvent: () => true,
}),
});
// Mock URL.createObjectURL and revokeObjectURL
global.URL.createObjectURL = () => 'blob:mock-url';
global.URL.revokeObjectURL = () => {};
// Mock MediaRecorder API
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).MediaRecorder = class MediaRecorder {
static isTypeSupported = () => true;
ondataavailable: ((event: Event) => void) | null = null;
onerror: ((event: Event) => void) | null = null;
onstop: ((event: Event) => void) | null = null;
state = 'inactive';
start() {
this.state = 'recording';
}
stop() {
this.state = 'inactive';
if (this.onstop) {
this.onstop(new Event('stop'));
}
}
pause() {}
resume() {}
requestData() {}
addEventListener() {}
removeEventListener() {}
dispatchEvent() { return true; }
};
// Mock AudioContext
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).AudioContext = class AudioContext {
createMediaStreamSource() {
return {
connect: () => {},
};
}
createAnalyser() {
return {
fftSize: 2048,
frequencyBinCount: 1024,
getByteTimeDomainData: () => {},
};
}
close() {
return Promise.resolve();
}
};
// Mock getUserMedia
Object.defineProperty(global.navigator, 'mediaDevices', {
value: {
getUserMedia: () => Promise.resolve({
getTracks: () => [{
stop: () => {},
}],
}),
},
writable: true,
});
// Mock IndexedDB
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).indexedDB = {
open: () => ({
result: {},
onerror: null,
onsuccess: null,
onupgradeneeded: null,
}),
};
// Mock crypto.randomUUID
if (!global.crypto) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).crypto = {};
}
if (!global.crypto.randomUUID) {
global.crypto.randomUUID = () => Math.random().toString(36).substring(2, 15) as `${string}-${string}-${string}-${string}-${string}`;
}