Skip to content

Commit 4820190

Browse files
committed
update cac tests
1 parent ab1040c commit 4820190

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

tests/cli.test.ts

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { exec } from "child_process";
2-
import { describe, it, expect } from "vitest";
2+
import { describe, it, expect, test } from "vitest";
33

44
function runCommand(command: string): Promise<string> {
55
return new Promise((resolve, reject) => {
@@ -13,16 +13,16 @@ function runCommand(command: string): Promise<string> {
1313
});
1414
}
1515

16-
describe("CLI Completion Tests cac", () => {
17-
it("should complete vite commands", async () => {
16+
describe("CLI Completion Tests for CAC", () => {
17+
it("Completes Vite Commands Correctly", async () => {
1818
const output = await runCommand("pnpm tsx demo.cac.ts complete --");
1919
console.log("Command Output:", output);
2020
expect(output).toContain("src/");
2121
expect(output).toContain("./");
2222
// expect(output).toContain('--base');
2323
});
2424

25-
it("should complete options", async () => {
25+
it("Completes CLI Options Correctly", async () => {
2626
const output = await runCommand("pnpm tsx demo.cac.ts complete -- --");
2727
console.log("Command Output:", output);
2828
expect(output).toContain("--port");
@@ -33,3 +33,69 @@ describe("CLI Completion Tests cac", () => {
3333
expect(output).toContain("--mode");
3434
});
3535
});
36+
37+
describe("CLI Option Completion for Partial Inputs", () => {
38+
const optionTests = [
39+
{ partial: "--p", expected: "--port" },
40+
];
41+
42+
test.each(optionTests)(
43+
"Completes Option When Given Partial Input '%s'",
44+
async ({ partial, expected }) => {
45+
const command = `pnpm tsx demo.cac.ts complete -- ${partial}`;
46+
const output = await runCommand(command);
47+
console.log(`Complete ${partial} Output:`, output);
48+
expect(output).toContain(expected);
49+
}
50+
);
51+
});
52+
53+
describe("CLI Option Completion When Options Are Already Specified", () => {
54+
const alreadySpecifiedTests = [
55+
{ specified: "--port", shouldNotContain: "--port" },
56+
];
57+
58+
test.each(alreadySpecifiedTests)(
59+
"Does Not Suggest Already Specified Option '%s'",
60+
async ({ specified, shouldNotContain }) => {
61+
const command = `pnpm tsx demo.cac.ts complete -- ${specified} --`;
62+
const output = await runCommand(command);
63+
console.log(`Already Specified ${specified} Output:`, output);
64+
expect(output).not.toContain(shouldNotContain);
65+
}
66+
);
67+
});
68+
69+
describe("CLI Option Value Handling", () => {
70+
71+
it("Resolves Port Value Correctly", async () => {
72+
const command = "pnpm tsx demo.cac.ts complete -- --port 3";
73+
const output = await runCommand(command);
74+
console.log("Conflicting Options Output:", output);
75+
expect(output).toContain("3000");
76+
});
77+
78+
it("Handles Conflicting Options Appropriately", async () => {
79+
const command = "pnpm tsx demo.cac.ts complete -- --port 3000 --";
80+
const output = await runCommand(command);
81+
console.log("Conflicting Options Output:", output);
82+
expect(output).not.toContain("--port");
83+
expect(output).toContain("--config");
84+
// expect(output).toContain("--base");
85+
});
86+
87+
it("Resolves Config Option Values Correctly", async () => {
88+
const command = "pnpm tsx demo.cac.ts complete -- --port 3000 --config vite.config";
89+
const output = await runCommand(command);
90+
console.log("Conflicting Options Output:", output);
91+
expect(output).toContain("vite.config.ts");
92+
expect(output).toContain("vite.config.js");
93+
});
94+
95+
it("Gracefully Handles Unknown Options with No Completions", async () => {
96+
const command = "pnpm tsx demo.cac.ts complete -- --unknownoption";
97+
const output = await runCommand(command);
98+
console.log("No Completion Available Output:", output);
99+
expect(output.trim()).toMatch(/^(:\d+)?$/);
100+
});
101+
});

0 commit comments

Comments
 (0)