PettyUI/packages/mcp/tests/cli.test.ts
Mats Bosson e20b69d7e8 Wire up MCP CLI
- Add packages/mcp/src/cli.ts with init/list/inspect/discover/add commands
- Add packages/mcp/tests/cli.test.ts with 11 parseCommand tests (42 total)
- Update server.ts to register all 5 tools: discover, inspect, validate, add, compose
- Add @types/node devDep, switch to tsc --noCheck build to avoid re-checking
  core source under stricter NodeNext moduleResolution
- tsconfig: NodeNext module, types: [node], exclude core/src
2026-03-30 01:25:45 +07:00

65 lines
2.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { parseCommand } from "../src/cli.js";
describe("parseCommand", () => {
it("empty argv → command: help", () => {
expect(parseCommand([])).toEqual({ command: "help", args: {} });
});
it("unknown command → command: help", () => {
expect(parseCommand(["unknown"])).toEqual({ command: "help", args: {} });
});
it("init → command: init", () => {
const result = parseCommand(["init"]);
expect(result.command).toBe("init");
});
it("list → command: list", () => {
const result = parseCommand(["list"]);
expect(result.command).toBe("list");
});
it("add dialog → command: add, args.component: dialog", () => {
const result = parseCommand(["add", "dialog"]);
expect(result.command).toBe("add");
expect(result.args["component"]).toBe("dialog");
});
it("add dialog --dir src/ui → args.dir: src/ui", () => {
const result = parseCommand(["add", "dialog", "--dir", "src/ui"]);
expect(result.command).toBe("add");
expect(result.args["component"]).toBe("dialog");
expect(result.args["dir"]).toBe("src/ui");
});
it("inspect dialog → command: inspect, args.component: dialog", () => {
const result = parseCommand(["inspect", "dialog"]);
expect(result.command).toBe("inspect");
expect(result.args["component"]).toBe("dialog");
});
it("discover modal → command: discover, args.component: modal", () => {
const result = parseCommand(["discover", "modal"]);
expect(result.command).toBe("discover");
expect(result.args["component"]).toBe("modal");
});
it("help → command: help", () => {
const result = parseCommand(["help"]);
expect(result.command).toBe("help");
});
it("init --dir src/styles → args.dir: src/styles", () => {
const result = parseCommand(["init", "--dir", "src/styles"]);
expect(result.command).toBe("init");
expect(result.args["dir"]).toBe("src/styles");
});
it("--dir without value is ignored", () => {
const result = parseCommand(["list", "--dir"]);
expect(result.command).toBe("list");
expect(result.args["dir"]).toBeUndefined();
});
});