-
Notifications
You must be signed in to change notification settings - Fork 2
/
vitest.setup.ts
64 lines (57 loc) · 1.52 KB
/
vitest.setup.ts
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
import { beforeEach, vi } from "vitest";
import fetch from "node-fetch-cache";
import fetchPost from "./src/lib/fetchPost";
import { __reset } from "./src/lib/memoize";
import ether from "./src/lib/test/ether";
import getSitemap from "./src/lib/test/getSitemap";
vi.mock("./src/lib/fetchPost");
vi.mock("./src/lib/readSources");
vi.mock("./src/lib/test/createReport");
vi.mock("./src/lib/test/saveScreenshot");
vi.mock("./src/lib/test/getSitemap");
vi.mock("./src/lib/test/readScreenshot");
vi.mock("./src/lib/test/resizeImage");
vi.mock("node-fetch-cache");
vi.mock("puppeteer", () => ({
default: {
launch: vi.fn(async () => ({
newPage: vi.fn(async () => ({
setViewport: vi.fn(),
goto: vi.fn(),
screenshot: vi.fn(),
close: vi.fn(),
})),
close: vi.fn(),
})),
},
}));
vi.mock("fs");
vi.mock("astro", () => ({
preview: vi.fn(async () => ({
stop: vi.fn(),
})),
}));
vi.mock("pixelmatch");
vi.mock("pngjs");
vi.mock("sharp");
beforeEach(() => {
global.fetch = vi.fn(() =>
Promise.resolve({ text: vi.fn(async () => "") } as any),
);
vi.mocked(fetch).mockReturnValue(
Promise.resolve({ text: vi.fn(async () => "") } as any),
);
vi.mocked(fetchPost).mockResolvedValue(ether());
vi.mocked(getSitemap).mockResolvedValue([]);
vi.stubGlobal("console", {
...console,
info: vi.fn(),
time: vi.fn(),
timeEnd: vi.fn(),
});
vi.stubGlobal("process", {
...process,
env: { ...process.env, ETHERPAD_DOMAIN: "the_etherpad_domain" },
});
__reset();
});