Skip to content

Commit bc2b302

Browse files
CopilotLipata
andcommitted
Add tests for MCP command functionality
Co-authored-by: Lipata <[email protected]>
1 parent bbe90ae commit bc2b302

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

spec/acceptance/help-spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ describe("Help command", () => {
2323
doc [term] opens the Infragistics search for the given term
2424
test executes project tests
2525
list list all templates [aliases: l]
26+
mcp Start the Ignite UI CLI MCP (Model Context Protocol)
27+
server
2628
upgrade-packages upgrades Ignite UI Packages
2729
Options:
2830
-v, --version Show current Ignite UI CLI version [boolean]

spec/acceptance/mcp-spec.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)