mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-11 09:11:13 +00:00
test: align bash exec mocks with reset modules
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
import { afterEach, expect, test } from "vitest";
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
import { killProcessTree } from "../process/kill-tree.js";
|
||||
import {
|
||||
getFinishedSession,
|
||||
getSession,
|
||||
resetProcessRegistryForTests,
|
||||
} from "./bash-process-registry.js";
|
||||
import { createExecTool } from "./bash-tools.exec.js";
|
||||
|
||||
const BACKGROUND_HOLD_CMD = 'node -e "setTimeout(() => {}, 5000)"';
|
||||
const ABORT_SETTLE_MS = process.platform === "win32" ? 200 : 25;
|
||||
@@ -19,10 +13,22 @@ const TEST_EXEC_DEFAULTS = {
|
||||
ask: "off" as const,
|
||||
};
|
||||
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
let getFinishedSession: typeof import("./bash-process-registry.js").getFinishedSession;
|
||||
let getSession: typeof import("./bash-process-registry.js").getSession;
|
||||
let resetProcessRegistryForTests: typeof import("./bash-process-registry.js").resetProcessRegistryForTests;
|
||||
|
||||
const createTestExecTool = (
|
||||
defaults?: Parameters<typeof createExecTool>[0],
|
||||
): ReturnType<typeof createExecTool> => createExecTool({ ...TEST_EXEC_DEFAULTS, ...defaults });
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ createExecTool } = await import("./bash-tools.exec.js"));
|
||||
({ getFinishedSession, getSession, resetProcessRegistryForTests } =
|
||||
await import("./bash-process-registry.js"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetProcessRegistryForTests();
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
let resetProcessRegistryForTests: typeof import("./bash-process-registry.js").resetProcessRegistryForTests;
|
||||
|
||||
const { ptySpawnMock } = vi.hoisted(() => ({
|
||||
ptySpawnMock: vi.fn(),
|
||||
@@ -13,6 +13,7 @@ vi.mock("@lydell/node-pty", () => ({
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ createExecTool } = await import("./bash-tools.exec.js"));
|
||||
({ resetProcessRegistryForTests } = await import("./bash-process-registry.js"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
import { listRunningSessions, resetProcessRegistryForTests } from "./bash-process-registry.js";
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
let listRunningSessions: typeof import("./bash-process-registry.js").listRunningSessions;
|
||||
let resetProcessRegistryForTests: typeof import("./bash-process-registry.js").resetProcessRegistryForTests;
|
||||
|
||||
const { supervisorSpawnMock } = vi.hoisted(() => ({
|
||||
supervisorSpawnMock: vi.fn(),
|
||||
@@ -24,6 +25,8 @@ vi.mock("../process/supervisor/index.js", () => ({
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ createExecTool } = await import("./bash-tools.exec.js"));
|
||||
({ listRunningSessions, resetProcessRegistryForTests } =
|
||||
await import("./bash-process-registry.js"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
import { resetProcessRegistryForTests } from "./bash-process-registry.js";
|
||||
let createExecTool: typeof import("./bash-tools.exec.js").createExecTool;
|
||||
let resetProcessRegistryForTests: typeof import("./bash-process-registry.js").resetProcessRegistryForTests;
|
||||
|
||||
vi.mock("@lydell/node-pty", () => ({
|
||||
spawn: () => {
|
||||
@@ -13,6 +13,7 @@ vi.mock("@lydell/node-pty", () => ({
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ createExecTool } = await import("./bash-tools.exec.js"));
|
||||
({ resetProcessRegistryForTests } = await import("./bash-process-registry.js"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user