-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-vitest.ts
More file actions
53 lines (47 loc) · 1.63 KB
/
setup-vitest.ts
File metadata and controls
53 lines (47 loc) · 1.63 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
import { PatchConnection } from 'src/app/services/patch-connection.model';
import { vi } from 'vitest';
const mock = () => {
let storage: Record<string, string> = {};
return {
getItem: (key: string) => (key in storage ? storage[key] : null),
setItem: (key: string, value: string) => (storage[key] = value || ''),
removeItem: (key: string) => delete storage[key],
clear: () => (storage = {}),
};
};
Object.defineProperty(window, 'localStorage', { value: mock() });
Object.defineProperty(window, 'sessionStorage', { value: mock() });
Object.defineProperty(window, 'getComputedStyle', {
value: () => ['-webkit-appearance'],
});
const mockPatchConnection: PatchConnection = {
requestStatusUpdate: vi.fn(),
addStatusListener: vi.fn(),
removeStatusListener: vi.fn(),
resetToInitialState: vi.fn(),
sendEventOrValue: vi.fn(),
sendMIDIInputEvent: vi.fn(),
sendParameterGestureStart: vi.fn(),
sendParameterGestureEnd: vi.fn(),
requestStoredStateValue: vi.fn(),
sendStoredStateValue: vi.fn(),
addStoredStateValueListener: vi.fn(),
removeStoredStateValueListener: vi.fn(),
sendFullStoredState: vi.fn(),
requestFullStoredState: vi.fn(),
addEndpointEventListener: vi.fn(),
removeEndpointEventListener: vi.fn(),
requestParameterValue: vi.fn(),
addParameterListener: vi.fn(),
removeParameterListener: vi.fn(),
addAllParameterListener: vi.fn(),
removeAllParameterListener: vi.fn(),
getResourceAddress: vi.fn(),
};
Object.defineProperty(window, 'parent', {
value: {
patchConnection: mockPatchConnection,
},
});
/* output shorter and more meaningful Zone error stack traces */
// Error.stackTraceLimit = 2;