test(hooks): replace global module and timer overrides

This commit is contained in:
YeonGyu-Kim
2026-05-30 23:50:57 +09:00
parent 4a15dfe971
commit 1b9e667486
7 changed files with 80 additions and 68 deletions
+8 -16
View File
@@ -1,6 +1,9 @@
/// <reference path="../../../bun-test.d.ts" />
import { afterAll, beforeAll, beforeEach, describe, expect, mock, test } from "bun:test"
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test"
import * as tmuxRunner from "../../shared/tmux/runner"
import * as tmuxPathResolver from "../../tools/interactive-bash/tmux-path-resolver"
type MockTmuxCommandResult = {
success: boolean
@@ -21,28 +24,17 @@ const runTmuxCommandMock = mock(
)
const getTmuxPathMock = mock(async (): Promise<string | null> => "/mock/tmux")
let tmuxModule: typeof import("../tmux")
beforeAll(async () => {
mock.module("../../shared/tmux/runner", () => ({
runTmuxCommand: runTmuxCommandMock,
}))
mock.module("../../tools/interactive-bash/tmux-path-resolver", () => ({
getTmuxPath: getTmuxPathMock,
}))
tmuxModule = await import("../tmux")
})
const tmuxModule = await import("../tmux")
beforeEach(() => {
runTmuxCommandMock.mockReset()
getTmuxPathMock.mockReset()
getTmuxPathMock.mockResolvedValue("/mock/tmux")
spyOn(tmuxRunner, "runTmuxCommand").mockImplementation(runTmuxCommandMock)
spyOn(tmuxPathResolver, "getTmuxPath").mockImplementation(getTmuxPathMock)
})
afterAll(() => {
afterEach(() => {
mock.restore()
})
+4 -4
View File
@@ -1,13 +1,13 @@
import { runTmuxCommand } from "../shared/tmux/runner"
import { getTmuxPath } from "../tools/interactive-bash/tmux-path-resolver"
import * as tmuxRunner from "../shared/tmux/runner"
import * as tmuxPathResolver from "../tools/interactive-bash/tmux-path-resolver"
async function runOpenClawTmuxCommand(args: string[]) {
const tmuxPath = await getTmuxPath()
const tmuxPath = await tmuxPathResolver.getTmuxPath()
if (!tmuxPath) {
return null
}
return runTmuxCommand(tmuxPath, args)
return tmuxRunner.runTmuxCommand(tmuxPath, args)
}
export function getCurrentTmuxSession(): string | null {