Skip to content

Commit b17e1bf

Browse files
committed
fix global fetch bug
1 parent 3d386ae commit b17e1bf

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/utils/chrome/__tests__/chrome-crawler.e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("Chrome Web Store Crawler E2E", () => {
1313
id: githubBetterLineCountsId,
1414
lastUpdated: expect.any(String),
1515
longDescription: expect.stringContaining("Isn't it annoying when you"),
16-
name: "GitHub: Better Line Counts",
16+
name: "GitHub Better Line Counts",
1717
rating: expect.any(Number),
1818
reviewCount: expect.any(Number),
1919
shortDescription: "Remove generated files from GitHub line counts",

src/utils/chrome/__tests__/chrome-crawler.test.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
// 5. You're done! The test is added, run `bun test`.
1111
//
1212

13-
import { beforeEach, describe, expect, it, mock } from "bun:test";
13+
import {
14+
afterAll,
15+
beforeEach,
16+
describe,
17+
expect,
18+
it,
19+
mock,
20+
spyOn,
21+
} from "bun:test";
1422
import { crawlExtension } from "../chrome-crawler";
1523
import { readdir } from "node:fs/promises";
1624
import { join } from "node:path";
1725

18-
const fetchMock = mock<typeof fetch>();
19-
globalThis.fetch = fetchMock as any;
26+
const fetchSpy = spyOn(globalThis, "fetch");
2027

2128
describe("Chrome Web Store Crawler", async () => {
2229
const fixturesDir = join(import.meta.dir, "fixtures/chrome-web-store");
@@ -27,14 +34,18 @@ describe("Chrome Web Store Crawler", async () => {
2734
file.match(/.*-([a-z]+)\.html/)![1]!;
2835

2936
beforeEach(() => {
30-
fetchMock.mockReset();
37+
fetchSpy.mockReset();
38+
});
39+
40+
afterAll(() => {
41+
fetchSpy.mockRestore();
3142
});
3243

3344
it.each(testFiles)(
3445
"should extract extension details from %s",
3546
async (file) => {
3647
const id = getExtensionIdFromFile(file);
37-
fetchMock.mockResolvedValueOnce(
48+
fetchSpy.mockResolvedValueOnce(
3849
new Response(Bun.file(join(fixturesDir, file))),
3950
);
4051
const res = await crawlExtension(id, "en", true);

0 commit comments

Comments
 (0)