-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchrome-crawler.test.ts
More file actions
34 lines (30 loc) · 1.03 KB
/
chrome-crawler.test.ts
File metadata and controls
34 lines (30 loc) · 1.03 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
import { beforeEach, describe, expect, it, mock } from "bun:test";
import { crawlExtension } from "../chrome-crawler";
import { readdir } from "node:fs/promises";
import { join } from "node:path";
const fetchMock = mock<typeof fetch>(() => {
throw Error("Not mocked");
});
globalThis.fetch = fetchMock;
describe("Chrome Web Store Crawler", async () => {
const fixturesDir = join(import.meta.dir, "fixtures/chrome-web-store");
const testFiles = (await readdir(fixturesDir))
.filter((file) => !file.startsWith("."))
.toSorted();
const getExtensionIdFromFile = (file: string) =>
file.match(/.*-([a-z]+)\.html/)![1];
beforeEach(() => {
fetchMock.mockReset();
});
it.each(testFiles)(
"should extract extension details from %s",
async (file) => {
const id = getExtensionIdFromFile(file);
globalThis.fetch = mock(() =>
Promise.resolve(new Response(Bun.file(join(fixturesDir, file)))),
);
const res = await crawlExtension(id, "en", true);
expect(res).toMatchSnapshot();
},
);
});