perf(test): fold imessage rpc client guard into targets suite

This commit is contained in:
Peter Steinberger
2026-02-16 00:26:43 +00:00
parent 8d2029a03d
commit e1350ff976
2 changed files with 22 additions and 23 deletions

View File

@@ -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();
});
});

View File

@@ -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();
});
});