Files
hyperframes/packages/cli/src/utils/clipboard.test.ts
T
Miguel Ángel 221f3671f2 fix(cli): stop 'hyperframes add' hanging when a desktop clipboard is available (#6271)
* fix(cli): stop 'hyperframes add' hanging when a desktop clipboard is available

* test(cli): assert the clipboard copy options instead of waiting on real time
2026-10-25 04:44:34 +00:00

32 lines
1.1 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const spawnSync = vi.hoisted(() => vi.fn());
vi.mock("node:child_process", () => ({ spawnSync }));
vi.mock("node:os", async (orig) => ({
...(await orig<typeof import("node:os")>()),
platform: () => "darwin",
}));
describe("copyToClipboard", () => {
beforeEach(() => {
spawnSync.mockReset();
vi.resetModules();
});
it("does not let the tool's background owner hold our output pipes or block forever", async () => {
spawnSync.mockReturnValue({ status: 0 });
const { copyToClipboard } = await import("./clipboard.js");
expect(copyToClipboard("snippet")).toBe(true);
const opts = spawnSync.mock.calls[0]![2];
expect(opts.input).toBe("snippet");
expect(opts.stdio).toEqual(["pipe", "ignore", "ignore"]);
expect(opts.timeout).toBeGreaterThan(0);
});
it("reports not copied when the tool times out", async () => {
spawnSync.mockReturnValue({ status: null, error: new Error("ETIMEDOUT") });
const { copyToClipboard } = await import("./clipboard.js");
expect(copyToClipboard("snippet")).toBe(false);
});
});