Repository navigation
Expand file tree
/
Copy pathsetup.ts
More file actions
72 lines (65 loc) · 1.46 KB
/
Copy pathsetup.ts
File metadata and controls
72 lines (65 loc) · 1.46 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
/**
* Test setup file
* Configure test environment
*/
import { vi } from 'vitest';
// Mock chrome API
globalThis.chrome = {
storage: {
sync: {
get: vi.fn(),
set: vi.fn(),
remove: vi.fn(),
clear: vi.fn(),
},
onChanged: {
addListener: vi.fn(),
removeListener: vi.fn(),
},
},
runtime: {
lastError: null,
id: 'test-extension-id',
},
} as unknown as typeof chrome;
// Mock localStorage
const localStorageMock = (() => {
let store: Record<string, string> = {};
return {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value;
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
get length() {
return Object.keys(store).length;
},
};
})();
Object.defineProperty(window, 'localStorage', {
value: localStorageMock,
writable: true,
});
// Also expose localStorage globally (not just on window)
globalThis.localStorage = localStorageMock as unknown as Storage;
// Expose document globally
globalThis.document = window.document;
// Mock DOM API
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});