import { describe, it, expect, vi } from "vitest"; vi.mock("../lib/api-client.js", () => ({ apiRequest: vi.fn(), })); vi.mock("ora", () => ({ default: () => ({ start: vi.fn().mockReturnThis(), succeed: vi.fn().mockReturnThis(), fail: vi.fn().mockReturnThis(), info: vi.fn().mockReturnThis(), text: "", }), })); vi.mock("chalk", () => ({ default: { bold: (s: string) => s, cyan: (s: string) => s, red: (s: string) => s, green: (s: string) => s, yellow: (s: string) => s, dim: (s: string) => s, }, })); import { apiRequest } from "../lib/api-client.js"; const mockApiRequest = vi.mocked(apiRequest); describe("test command", () => { it("exports testCommand", async () => { const { testCommand } = await import("./test.js"); expect(testCommand.name()).toBe("test"); expect(testCommand.description()).toContain("test cases"); }); it("exits gracefully when no test cases exist", async () => { mockApiRequest.mockResolvedValueOnce([]); const { testCommand } = await import("./test.js"); const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => { throw new Error("exit"); }); try { await testCommand.parseAsync(["test", "my-skill"], { from: "user" }); } catch { // may throw from parseAsync } exitSpy.mockRestore(); }); it("reports results with pass/fail", async () => { const testCases = [ { id: "tc1", label: "Basic test", input: "hello", expectedOutput: "world", sortOrder: 0, }, ]; mockApiRequest .mockResolvedValueOnce(testCases) // GET test-cases .mockResolvedValueOnce({ id: "run1" }) // POST sandbox .mockResolvedValueOnce({ // GET sandbox run result id: "run1", status: "COMPLETED", output: "world is here", durationMs: 150, errorMessage: null, }); const { testCommand } = await import("./test.js"); const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => { throw new Error("exit"); }); try { await testCommand.parseAsync(["test", "my-skill"], { from: "user" }); } catch { // may throw } exitSpy.mockRestore(); }); });