|
| 1 | +import { GoogleAnalytics, Util } from "@igniteui/cli-core"; |
| 2 | +import * as cli from "../../packages/cli/lib/cli"; |
| 3 | + |
| 4 | +const execLocation = "packages/cli/bin/execute.js"; |
| 5 | + |
| 6 | +describe("MCP command", () => { |
| 7 | + beforeEach(() => { |
| 8 | + spyOn(GoogleAnalytics, "post"); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should be listed in help", async () => { |
| 12 | + const consoleSpy = spyOn(console, "log"); |
| 13 | + |
| 14 | + try { |
| 15 | + await cli.run(["--help"]); |
| 16 | + } catch (e) { |
| 17 | + fail(e); |
| 18 | + } |
| 19 | + |
| 20 | + expect(consoleSpy).toHaveBeenCalledTimes(1); |
| 21 | + const helpText: string = consoleSpy.calls.mostRecent().args[0] + ""; |
| 22 | + expect(helpText).toContain("mcp"); |
| 23 | + expect(helpText).toContain("Start the Ignite UI CLI MCP (Model Context Protocol)"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should show help for the mcp command", async () => { |
| 27 | + const child = Util.spawnSync("node", [execLocation, "mcp", "-h"], { |
| 28 | + encoding: "utf-8" |
| 29 | + }); |
| 30 | + |
| 31 | + const expectedHelpText: string = ` |
| 32 | + Options: |
| 33 | + -v, --version Show current Ignite UI CLI version [boolean] |
| 34 | + -h, --help Show help [boolean] |
| 35 | + --read-only Only register read-only tools [boolean] [default: false] |
| 36 | + `; |
| 37 | + |
| 38 | + const replacedHelpText: string = expectedHelpText.replace(/\s/g, ""); |
| 39 | + const actualText: string = (child.stdout.toString()).replace(/\s/g, ""); |
| 40 | + |
| 41 | + expect(actualText).toContain(replacedHelpText); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should run without error", async () => { |
| 45 | + // The MCP command checks if running in a TTY |
| 46 | + // When run interactively (TTY), it shows a message |
| 47 | + // When run non-interactively (not TTY), it starts the MCP server |
| 48 | + // Since we can't easily test the server startup, we just verify no errors |
| 49 | + const child = Util.spawnSync("timeout", ["1", "node", execLocation, "mcp"], { |
| 50 | + encoding: "utf-8" |
| 51 | + }); |
| 52 | + |
| 53 | + // Command will timeout when trying to start server (which is expected) |
| 54 | + // or show the interactive message if TTY is detected |
| 55 | + // Either way, we should not get an error status code before timeout |
| 56 | + expect(child.status).not.toBe(1); |
| 57 | + }); |
| 58 | +}); |
0 commit comments