Skip to content

Commit 914e4fc

Browse files
committed
tests
1 parent a75179d commit 914e4fc

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

tests/cli.test.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const cliTools = ["cac", "citty"];
1818
describe.each(cliTools)("cli completion tests for %s", (cliTool) => {
1919
const commandPrefix = `pnpm tsx demo.${cliTool}.ts complete --`;
2020

21-
// it("should complete vite commands", async () => {
21+
// it("should complete positional commands", async () => {
2222
// const output = await runCommand(commandPrefix);
2323
// console.log(`[${cliTool}] Command Output:`, output);
2424
// expect(output).toContain("src/");
@@ -102,16 +102,49 @@ describe.each(cliTools)("cli completion tests for %s", (cliTool) => {
102102
console.log(`[${cliTool}] No Completion Available Output:`, output);
103103
expect(output.trim()).toMatch(/^(:\d+)?$/);
104104
});
105+
});
106+
107+
describe("edge case completions for end with space", () => {
108+
109+
it("should suggest port values if user ends with space after `--port`", async () => {
110+
const command = `${commandPrefix} dev --port ""`;
111+
const output = await runCommand(command);
112+
console.log(`[${cliTool}] End With Space (port) Output:`, output);
113+
expect(output).toContain("3000");
114+
});
115+
116+
it("should keep suggesting the --port option if user typed partial but didn't end with space", async () => {
117+
const command = `${commandPrefix} dev --po`;
118+
const output = await runCommand(command);
119+
console.log(`[${cliTool}] Partial Option (no space) Output:`, output);
120+
expect(output).toContain("--port");
121+
});
122+
123+
it("should suggest port values if user typed `--port=` and hasn't typed a space or value yet", async () => {
124+
const command = `${commandPrefix} dev --port ""`;
125+
const output = await runCommand(command);
126+
console.log(`[${cliTool}] --port= (no space) Output:`, output);
127+
expect(output).toContain("3000");
128+
});
129+
130+
});
105131

106-
// pnpm tsx demo.citty.ts complete -- dev --port ""
107-
// if the user done writing --port (ends with space) then it should suggest the ports (3000, ...)
108-
// if the user not done writing (no end with space), then it should keep suggesting the --port option
109-
// if the user wrote --port= (not end with space) then it should suggest the ports too (3000, ...)
132+
describe("positional argument completions", () => {
133+
it("should complete single positional argument when ending with space (vite src/)", async () => {
134+
const command = `${commandPrefix} vite src/ ""`;
135+
const output = await runCommand(command);
136+
console.log(`[${cliTool}] Single Positional Output:`, output);
110137

111-
// add test cases for positionals
112-
// like `vite src/` (single positional argument)
113-
// or `vite src/ ./` (multiple positionals, see https://www.npmjs.com/package/cac#variadic-arguments)
114-
// for all the tests we should use inline snapshots (https://vitest.dev/guide/snapshot.html#inline-snapshots) instead of regex or anything else
138+
expect(output).toContain("src/");
139+
expect(output).toContain("./");
140+
});
115141

142+
it("should complete multiple positional arguments when ending with space (vite src/ ./)", async () => {
143+
const command = `${commandPrefix} vite src/ ""`;
144+
const output = await runCommand(command);
145+
console.log(`[${cliTool}] Multiple Positional Output:`, output);
146+
147+
expect(output).toContain("./");
148+
});
116149
});
117-
});
150+
});

0 commit comments

Comments
 (0)