test(core): trim redundant test resets and use mockClear

This commit is contained in:
Peter Steinberger 2026-02-22 08:12:55 +00:00
parent e893157600
commit d6d73d0ed9
15 changed files with 14 additions and 16 deletions

View File

@ -30,7 +30,7 @@ describe("subscribeEmbeddedPiSession", () => {
const firstPayload = onPartialReply.mock.calls[0][0];
expect(firstPayload.text).toBe("Hi there");
onPartialReply.mockReset();
onPartialReply.mockClear();
emit({ type: "message_start", message: { role: "assistant" } });
emitAssistantTextDelta({ emit, delta: "</final>Oops no start" });

View File

@ -22,7 +22,7 @@ import { stageSandboxMedia } from "./reply/stage-sandbox-media.js";
afterEach(() => {
vi.restoreAllMocks();
childProcessMocks.spawn.mockReset();
childProcessMocks.spawn.mockClear();
});
describe("stageSandboxMedia", () => {

View File

@ -17,8 +17,6 @@ const { handleInlineActions } = await import("./get-reply-inline-actions.js");
describe("handleInlineActions", () => {
it("skips whatsapp replies when config is empty and From !== To", async () => {
handleCommandsMock.mockReset();
const typing: TypingController = {
onReplyStart: async () => {},
startTypingLoop: async () => {},

View File

@ -17,7 +17,7 @@ describe("noteSessionLockHealth", () => {
let envSnapshot: ReturnType<typeof captureEnv>;
beforeEach(async () => {
note.mockReset();
note.mockClear();
envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-doctor-locks-"));
process.env.OPENCLAW_STATE_DIR = root;

View File

@ -77,7 +77,7 @@ describe("doctor state integrity oauth dir checks", () => {
process.env.OPENCLAW_STATE_DIR = path.join(tempHome, ".openclaw");
delete process.env.OPENCLAW_OAUTH_DIR;
fs.mkdirSync(process.env.OPENCLAW_STATE_DIR, { recursive: true, mode: 0o700 });
vi.mocked(note).mockReset();
vi.mocked(note).mockClear();
});
afterEach(() => {

View File

@ -13,7 +13,7 @@ vi.mock("../infra/channel-activity.js", async (importOriginal) => {
describe("sendWebhookMessageDiscord activity", () => {
beforeEach(() => {
recordChannelActivityMock.mockReset();
recordChannelActivityMock.mockClear();
vi.stubGlobal(
"fetch",
vi.fn(async () => {

View File

@ -36,7 +36,7 @@ describe("ensureGatewayStartupAuth", () => {
beforeEach(() => {
vi.restoreAllMocks();
mocks.writeConfigFile.mockReset();
mocks.writeConfigFile.mockClear();
});
async function expectNoTokenGeneration(cfg: OpenClawConfig, mode: string) {

View File

@ -87,7 +87,7 @@ describe("imessage targets", () => {
describe("createIMessageRpcClient", () => {
beforeEach(() => {
spawnMock.mockReset();
spawnMock.mockClear();
vi.stubEnv("VITEST", "true");
});

View File

@ -91,7 +91,7 @@ describe("ports helpers", () => {
describeUnix("inspectPortUsage", () => {
beforeEach(() => {
runCommandWithTimeoutMock.mockReset();
runCommandWithTimeoutMock.mockClear();
});
it("reports busy when lsof is missing but loopback listener exists", async () => {

View File

@ -17,7 +17,7 @@ afterEach(() => {
envSnapshot.restore();
process.argv = [...originalArgv];
process.execArgv = [...originalExecArgv];
spawnMock.mockReset();
spawnMock.mockClear();
});
function clearSupervisorHints() {

View File

@ -15,7 +15,7 @@ let probeLineBot: typeof import("./probe.js").probeLineBot;
afterEach(() => {
vi.useRealTimers();
getBotInfoMock.mockReset();
getBotInfoMock.mockClear();
});
describe("probeLineBot", () => {

View File

@ -54,7 +54,7 @@ function setRegistry(entries: MockRegistryToolEntry[]) {
describe("resolvePluginTools optional tools", () => {
beforeEach(() => {
loadOpenClawPluginsMock.mockReset();
loadOpenClawPluginsMock.mockClear();
});
it("skips optional tools without explicit allowlist", () => {

View File

@ -25,7 +25,7 @@ describe("killProcessTree", () => {
let killSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
spawnMock.mockReset();
spawnMock.mockClear();
killSpy = vi.spyOn(process, "kill");
vi.useFakeTimers();
});

View File

@ -40,7 +40,7 @@ describe("process supervisor PTY command contract", () => {
});
beforeEach(() => {
createPtyAdapterMock.mockReset();
createPtyAdapterMock.mockClear();
});
it("passes PTY command verbatim to shell args", async () => {

View File

@ -19,7 +19,7 @@ vi.mock("../logging/subsystem.js", () => ({
describe("resolveTelegramAccount", () => {
afterEach(() => {
warnMock.mockReset();
warnMock.mockClear();
});
it("falls back to the first configured account when accountId is omitted", () => {