fix(tests): replace mock.module with spyOn to prevent test pollution
The opencode-config-agents-reader.test.ts was using mock.module() which permanently replaced the module in bun's module cache, causing state pollution in downstream tests (plugin-detection, write-omo-config, config-loader). Replaced with spyOn() pattern that properly restores in afterEach.
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
import { describe, expect, it, beforeEach, afterEach } from "bun:test"
|
||||
import { mock } from "bun:test"
|
||||
import { describe, expect, it, beforeEach, afterEach, spyOn } from "bun:test"
|
||||
import * as fs from "node:fs"
|
||||
import * as os from "node:os"
|
||||
import * as path from "node:path"
|
||||
|
||||
// Mock getOpenCodeConfigDir to prevent global config leakage
|
||||
let mockGlobalConfigDir: string
|
||||
mock.module("../../shared/opencode-config-dir", () => ({
|
||||
getOpenCodeConfigDir: () => mockGlobalConfigDir,
|
||||
}))
|
||||
|
||||
const { readOpencodeConfigAgents } = require("./opencode-config-agents-reader")
|
||||
import * as configDir from "../../shared/opencode-config-dir"
|
||||
import { readOpencodeConfigAgents } from "./opencode-config-agents-reader"
|
||||
|
||||
describe("readOpencodeConfigAgents", () => {
|
||||
let mockGlobalConfigDir = ""
|
||||
let configDirSpy: ReturnType<typeof spyOn>
|
||||
|
||||
beforeEach(() => {
|
||||
mockGlobalConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-mock-global-"))
|
||||
configDirSpy = spyOn(configDir, "getOpenCodeConfigDir").mockReturnValue(mockGlobalConfigDir)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
configDirSpy.mockRestore()
|
||||
fs.rmSync(mockGlobalConfigDir, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user