@@ -13,89 +13,94 @@ function runCommand(command: string): Promise<string> {
1313 } ) ;
1414}
1515
16- describe ( "CLI Completion Tests for CAC" , ( ) => {
17- it ( "Completes Vite Commands Correctly" , async ( ) => {
18- const output = await runCommand ( "pnpm tsx demo.cac.ts complete --" ) ;
19- console . log ( "Command Output:" , output ) ;
20- expect ( output ) . toContain ( "src/" ) ;
21- expect ( output ) . toContain ( "./" ) ;
22- // expect(output).toContain('--base');
23- } ) ;
16+ const cliTools = [ "cac" , "citty" ] ;
17+
18+ describe . each ( cliTools ) ( "cli completion tests for %s" , ( cliTool ) => {
19+ const commandPrefix = `pnpm tsx demo.${ cliTool } .ts complete --` ;
20+
21+ // it("should complete vite commands", async () => {
22+ // const output = await runCommand(commandPrefix);
23+ // console.log(`[${cliTool}] Command Output:`, output);
24+ // expect(output).toContain("src/");
25+ // expect(output).toContain("./");
26+ // // expect(output).toContain('--base');
27+ // });
2428
25- it ( "Completes CLI Options Correctly " , async ( ) => {
26- const output = await runCommand ( "pnpm tsx demo.cac.ts complete -- --" ) ;
27- console . log ( " Command Output:" , output ) ;
29+ it ( "should complete cli options " , async ( ) => {
30+ const output = await runCommand ( ` ${ commandPrefix } --` ) ;
31+ console . log ( `[ ${ cliTool } ] Command Output:` , output ) ;
2832 expect ( output ) . toContain ( "--port" ) ;
2933 expect ( output ) . toContain ( "--config" ) ;
3034 expect ( output ) . toContain ( "--base" ) ;
3135 expect ( output ) . toContain ( "--logLevel" ) ;
3236 expect ( output ) . toContain ( "--filter" ) ;
3337 expect ( output ) . toContain ( "--mode" ) ;
3438 } ) ;
35- } ) ;
3639
37- describe ( "CLI Option Completion for Partial Inputs " , ( ) => {
38- const optionTests = [
39- { partial : "--p" , expected : "--port" } ,
40- ] ;
40+ describe ( "cli option completion tests " , ( ) => {
41+ const optionTests = [
42+ { partial : "--p" , expected : "--port" } ,
43+ ] ;
4144
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- } ) ;
45+ test . each ( optionTests ) (
46+ "should complete option for partial input '%s'",
47+ async ( { partial, expected } ) => {
48+ const command = `${ commandPrefix } ${ partial } ` ;
49+ const output = await runCommand ( command ) ;
50+ console . log ( `[ ${ cliTool } ] Complete ${ partial } Output:` , output ) ;
51+ expect ( output ) . toContain ( expected ) ;
52+ }
53+ ) ;
54+ } ) ;
5255
53- describe ( "CLI Option Completion When Options Are Already Specified " , ( ) => {
54- const alreadySpecifiedTests = [
55- { specified : "--port" , shouldNotContain : "--port" } ,
56- ] ;
56+ describe ( "cli option exclusion tests " , ( ) => {
57+ const alreadySpecifiedTests = [
58+ { specified : "--port" , shouldNotContain : "--port" } ,
59+ ] ;
5760
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- } ) ;
61+ test . each ( alreadySpecifiedTests ) (
62+ "should not suggest already specified option '%s'" ,
63+ async ( { specified, shouldNotContain } ) => {
64+ const command = `${ commandPrefix } ${ specified } --` ;
65+ const output = await runCommand ( command ) ;
66+ console . log ( `[${ cliTool } ] Already Specified ${ specified } Output:` , output ) ;
67+ expect ( output ) . not . toContain ( shouldNotContain ) ;
68+ // expect(output).toContain("--base");
69+ }
70+ ) ;
71+ } ) ;
6872
69- describe ( "CLI Option Value Handling " , ( ) => {
73+ describe ( "cli option value handling " , ( ) => {
7074
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- } ) ;
75+ it ( "should resolve port value correctly " , async ( ) => {
76+ const command = ` ${ commandPrefix } -- port 3` ;
77+ const output = await runCommand ( command ) ;
78+ console . log ( `[ ${ cliTool } ] Port Value Output:` , output ) ;
79+ expect ( output ) . toContain ( "3000" ) ;
80+ } ) ;
7781
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- } ) ;
82+ it ( "should handle conflicting options appropriately " , async ( ) => {
83+ const command = ` ${ commandPrefix } -- port 3000 --` ;
84+ const output = await runCommand ( command ) ;
85+ console . log ( `[ ${ cliTool } ] Conflicting Options Output:` , output ) ;
86+ expect ( output ) . not . toContain ( "--port" ) ;
87+ expect ( output ) . toContain ( "--config" ) ;
88+ // expect(output).toContain("--base");
89+ } ) ;
8690
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- } ) ;
91+ it ( "should resolve config option values correctly " , async ( ) => {
92+ const command = ` ${ commandPrefix } -- port 3000 --config vite.config` ;
93+ const output = await runCommand ( command ) ;
94+ console . log ( `[ ${ cliTool } ] Config Option Output:` , output ) ;
95+ expect ( output ) . toContain ( "vite.config.ts" ) ;
96+ expect ( output ) . toContain ( "vite.config.js" ) ;
97+ } ) ;
9498
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 + ) ? $ / ) ;
99+ it ( "should handle unknown options with no completions" , async ( ) => {
100+ const command = `${ commandPrefix } --unknownoption` ;
101+ const output = await runCommand ( command ) ;
102+ console . log ( `[${ cliTool } ] No Completion Available Output:` , output ) ;
103+ expect ( output . trim ( ) ) . toMatch ( / ^ ( : \d + ) ? $ / ) ;
104+ } ) ;
100105 } ) ;
101106} ) ;
0 commit comments