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
+7 -1
View File
@@ -4,7 +4,9 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { registerPerplexityConfigCommand } from "../src/commands/config.js";
import { loadConfig, saveConfig } from "../src/config.js";
let loadConfig: (configPath?: string) => Promise<import("../src/config.js").PerplexityConfig>;
let saveConfig: (config: import("../src/config.js").PerplexityConfig, configPath?: string) => Promise<void>;
let tempDir: string;
let configPath: string;
@@ -12,6 +14,10 @@ let configPath: string;
beforeEach(async () => {
tempDir = await mkdtemp(join(tmpdir(), "pi-perplexity-command-test-"));
configPath = join(tempDir, "config.json");
const mod = await import(`../src/config.ts?t=${Date.now()}`);
loadConfig = mod.loadConfig;
saveConfig = mod.saveConfig;
});
afterEach(async () => {