fix(test): isolate tests from mock.module cache pollution

mock.module() in index-execute.test.ts permanently poisons Bun's
module cache — mock.restore() does not undo it in Bun 1.3.11.

Use cache-busted dynamic imports (../src/mod.ts?t=${Date.now()}) in
beforeEach for the three affected test files so each test gets a
fresh, unpoisoned module instance.
This commit is contained in:
Ivan Pereira
2026-03-21 21:29:00 +00:00
parent 96a3246d1e
commit 0f301e7f47
3 changed files with 39 additions and 4 deletions
+8 -2
View File
@@ -1,8 +1,9 @@
import { afterEach, describe, expect, test } from "bun:test";
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import { searchPerplexity } from "../../src/search/client.js";
import { SearchError } from "../../src/search/types.js";
let searchPerplexity: typeof import("../../src/search/client.js").searchPerplexity;
function createSseResponse(events: Array<Record<string, unknown>>, status = 200): Response {
const streamText = [
...events.map((event) => `data: ${JSON.stringify(event)}\n\n`),
@@ -18,6 +19,11 @@ function createSseResponse(events: Array<Record<string, unknown>>, status = 200)
describe("searchPerplexity", () => {
const originalFetch = globalThis.fetch;
beforeEach(async () => {
const mod = await import(`../../src/search/client.ts?t=${Date.now()}`);
searchPerplexity = mod.searchPerplexity;
});
afterEach(() => {
globalThis.fetch = originalFetch;
});