test(hooks): restore module mock cleanup
This commit is contained in:
+5
-1
@@ -1,5 +1,5 @@
|
||||
/// <reference types="bun-types" />
|
||||
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from "bun:test"
|
||||
|
||||
import type { AutoCompactState } from "./types"
|
||||
|
||||
@@ -38,6 +38,10 @@ mock.module("../../features/hook-message-injector", () => ({
|
||||
import { _resetForTesting as resetSessionState, updateSessionAgent } from "../../features/claude-code-session-state/state"
|
||||
import { runAggressiveTruncationStrategy } from "./aggressive-truncation-strategy"
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
type FakeClient = {
|
||||
session: {
|
||||
promptAsync: (input: PromptAsyncCall) => Promise<unknown>
|
||||
|
||||
@@ -18,8 +18,8 @@ mock.module("./tool-result-storage", () => ({
|
||||
truncateToolResult,
|
||||
}))
|
||||
|
||||
async function importFreshStorage(): Promise<typeof import("./storage")> {
|
||||
return import(`./storage?test=${Date.now()}-${Math.random()}`)
|
||||
async function importFreshStorage(): Promise<typeof import("./target-token-truncation")> {
|
||||
return import(`./target-token-truncation?test=${Date.now()}-${Math.random()}`)
|
||||
}
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, mock, test } from "bun:test"
|
||||
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
@@ -16,6 +16,10 @@ mock.module("../../shared/opencode-storage-detection", () => ({
|
||||
resetSqliteBackendCache: () => {},
|
||||
}))
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
type LongTimerCallback = (...args: unknown[]) => void | Promise<void>
|
||||
|
||||
describe("atlas background task retry", () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { describe, expect, mock, test } from "bun:test"
|
||||
import { afterAll, describe, expect, mock, test } from "bun:test"
|
||||
|
||||
type CreateAutoUpdateCheckerHook = typeof import("./hook").createAutoUpdateCheckerHook
|
||||
type HookOptions = Parameters<CreateAutoUpdateCheckerHook>[1]
|
||||
@@ -34,6 +34,10 @@ mock.module("./hook/deferred-startup-check", () => ({
|
||||
scheduleDeferredStartupCheck: scheduleDeferredStartupCheckMock,
|
||||
}))
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
const createPluginInput = (): PluginInput => ({
|
||||
client: {} as PluginInput["client"],
|
||||
directory: "/tmp/project",
|
||||
@@ -41,6 +45,7 @@ const createPluginInput = (): PluginInput => ({
|
||||
worktree: "/tmp/project",
|
||||
serverUrl: new URL("https://example.com"),
|
||||
$: {} as PluginInput["$"],
|
||||
experimental_workspace: { register: () => {} },
|
||||
} satisfies PluginInput)
|
||||
|
||||
const createDeps = (overrides: Partial<HookDeps> = {}) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { afterEach, beforeEach, describe, expect, mock, test } = require("bun:test")
|
||||
const { afterAll, afterEach, beforeEach, describe, expect, mock, test } = require("bun:test")
|
||||
|
||||
const capturedOptions: Array<Record<string, unknown>> = []
|
||||
|
||||
@@ -19,6 +19,10 @@ mock.module("./execute-http-hook", () => ({
|
||||
|
||||
const { dispatchHook } = await import("./dispatch-hook")
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
describe("dispatchHook", () => {
|
||||
beforeEach(() => {
|
||||
mockExecuteHookCommand.mockClear()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
@@ -14,6 +14,10 @@ mock.module("./plugin-entry-migrator.ts", () => ({
|
||||
|
||||
const autoMigrateModulePromise = import("./auto-migrate")
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
describe("autoMigrateLegacyPluginEntry", () => {
|
||||
let testConfigDir = ""
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
|
||||
let scheduledDeferredCheck: (() => void) | null = null
|
||||
mock.module("../auto-update-checker/hook/deferred-startup-check", () => ({
|
||||
@@ -9,6 +9,10 @@ mock.module("../auto-update-checker/hook/deferred-startup-check", () => ({
|
||||
|
||||
const { createAutoUpdateCheckerHook } = await import("../auto-update-checker/hook")
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
const mockShowConfigErrorsIfAny = mock(async () => {})
|
||||
const mockShowModelCacheWarningIfNeeded = mock(async () => {})
|
||||
const mockUpdateAndShowConnectedProvidersCacheStatus = mock(async () => {})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { afterEach, beforeEach, describe, expect, mock, test } = require("bun:test")
|
||||
const { afterAll, afterEach, beforeEach, describe, expect, mock, test } = require("bun:test")
|
||||
|
||||
const mockSetPluginHooksConfigs = mock(() => {})
|
||||
|
||||
@@ -8,6 +8,10 @@ mock.module("../hooks/claude-code-hooks/config", () => ({
|
||||
|
||||
const { applyHookConfig } = await import("./hook-config-handler")
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
describe("applyHookConfig", () => {
|
||||
beforeEach(() => {
|
||||
mockSetPluginHooksConfigs.mockClear()
|
||||
|
||||
Reference in New Issue
Block a user