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:
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user