diff --git a/packages/replay/src/auth.ts b/packages/replay/src/auth.ts index cbdaf81b..652b72c1 100644 --- a/packages/replay/src/auth.ts +++ b/packages/replay/src/auth.ts @@ -1,3 +1,4 @@ +import fetch from "node-fetch"; import { spawn } from "child_process"; import { createHash } from "crypto"; import dbg from "./debug"; diff --git a/packages/shared/src/cachedFetch.test.ts b/packages/shared/src/cachedFetch.test.ts index 4a15a979..8768f69d 100644 --- a/packages/shared/src/cachedFetch.test.ts +++ b/packages/shared/src/cachedFetch.test.ts @@ -1,5 +1,8 @@ import assert from "assert"; -import { cachedFetch, resetCache } from "./cachedFetch"; +import type { + cachedFetch as cachedFetchStatic, + resetCache as resetCacheStatic, +} from "./cachedFetch"; class Response { public status: number; @@ -21,20 +24,22 @@ const failedResponse = new Response(500, "error"); const successResponse = new Response(200, "ok"); describe("cachedFetch", () => { - let globalFetch: typeof fetch; + let cachedFetch: typeof cachedFetchStatic; + let resetCache: typeof resetCacheStatic; let mockFetch: jest.Mock; beforeEach(() => { - globalFetch = global.fetch; - mockFetch = global.fetch = jest.fn(async (url: string) => { - return successResponse; - }) as jest.Mock; + jest.mock("undici"); + + mockFetch = require("undici").fetch; + mockFetch.mockReturnValue(successResponse); + + ({ cachedFetch, resetCache } = require("./cachedFetch")); }); afterEach(() => { - global.fetch = globalFetch; - resetCache(); + mockFetch.mockClear(); }); it("should return a successful response", async () => { diff --git a/packages/shared/src/cachedFetch.ts b/packages/shared/src/cachedFetch.ts index 59a1981b..c99f4f3c 100644 --- a/packages/shared/src/cachedFetch.ts +++ b/packages/shared/src/cachedFetch.ts @@ -1,3 +1,5 @@ +import { fetch } from "undici"; + type CacheEntry = { json: any | null; status: number; statusText: string }; export const cache: Map = new Map();