mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 11:27:26 +00:00
perf(test): fold imessage rpc client guard into targets suite
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const spawnMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("node:child_process", () => ({
|
||||
spawn: (...args: unknown[]) => spawnMock(...args),
|
||||
}));
|
||||
|
||||
describe("createIMessageRpcClient", () => {
|
||||
beforeEach(() => {
|
||||
spawnMock.mockReset();
|
||||
vi.stubEnv("VITEST", "true");
|
||||
});
|
||||
|
||||
it("refuses to spawn imsg rpc in test environments", async () => {
|
||||
const { createIMessageRpcClient } = await import("./client.js");
|
||||
await expect(createIMessageRpcClient()).rejects.toThrow(
|
||||
/Refusing to start imsg rpc in test environment/i,
|
||||
);
|
||||
expect(spawnMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
formatIMessageChatTarget,
|
||||
isAllowedIMessageSender,
|
||||
@@ -6,6 +6,12 @@ import {
|
||||
parseIMessageTarget,
|
||||
} from "./targets.js";
|
||||
|
||||
const spawnMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("node:child_process", () => ({
|
||||
spawn: (...args: unknown[]) => spawnMock(...args),
|
||||
}));
|
||||
|
||||
describe("imessage targets", () => {
|
||||
it("parses chat_id targets", () => {
|
||||
const target = parseIMessageTarget("chat_id:123");
|
||||
@@ -70,3 +76,18 @@ describe("imessage targets", () => {
|
||||
expect(formatIMessageChatTarget(undefined)).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createIMessageRpcClient", () => {
|
||||
beforeEach(() => {
|
||||
spawnMock.mockReset();
|
||||
vi.stubEnv("VITEST", "true");
|
||||
});
|
||||
|
||||
it("refuses to spawn imsg rpc in test environments", async () => {
|
||||
const { createIMessageRpcClient } = await import("./client.js");
|
||||
await expect(createIMessageRpcClient()).rejects.toThrow(
|
||||
/Refusing to start imsg rpc in test environment/i,
|
||||
);
|
||||
expect(spawnMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user