-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
56 lines (51 loc) · 1.27 KB
/
Copy pathvitest.setup.ts
File metadata and controls
56 lines (51 loc) · 1.27 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
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@testing-library/react";
import { afterEach, vi } from "vitest";
import * as chrome from "vitest-chrome";
import { createFakeStorageArea } from "./vitest.fake-storage";
Object.assign(global, chrome);
const { area: storageArea, reset: resetStorage } = createFakeStorageArea();
const globalChrome = (globalThis as unknown as { chrome: Record<string, any> })
.chrome;
globalChrome.runtime = { ...globalChrome.runtime, id: "test-extension" };
globalChrome.storage = {
local: storageArea,
sync: storageArea,
managed: storageArea,
session: storageArea,
onChanged: { addListener: () => {}, removeListener: () => {} },
};
afterEach(() => {
cleanup();
resetStorage();
});
vi.mock("webextension-polyfill", () => ({
default: {
downloads: {
download: vi.fn(),
search: vi.fn(),
onChanged: {
addListener: vi.fn(),
removeListener: vi.fn(),
},
},
runtime: {
sendMessage: vi.fn(),
onMessage: {
addListener: vi.fn(),
removeListener: vi.fn(),
},
},
storage: {
local: {
get: vi.fn(),
set: vi.fn(),
},
},
tabs: {
create: vi.fn(),
query: vi.fn(),
sendMessage: vi.fn(),
},
},
}));