[READ-ONLY] Mirror of https://github.com/bombshell-dev/tab. shell autocompletions for javascript CLIs
4

Configure Feed

Select the types of activity you want to include in your feed.

update cac tests

AmirSa12 (Dec 24, 2024, 9:20 PM +0330) 48201905 ab1040ce

+70 -4
+70 -4
tests/cli.test.ts
··· 1 1 import { exec } from "child_process"; 2 - import { describe, it, expect } from "vitest"; 2 + import { describe, it, expect, test } from "vitest"; 3 3 4 4 function runCommand(command: string): Promise<string> { 5 5 return new Promise((resolve, reject) => { ··· 13 13 }); 14 14 } 15 15 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 () => { 18 18 const output = await runCommand("pnpm tsx demo.cac.ts complete --"); 19 19 console.log("Command Output:", output); 20 20 expect(output).toContain("src/"); ··· 22 22 // expect(output).toContain('--base'); 23 23 }); 24 24 25 - it("should complete options", async () => { 25 + it("Completes CLI Options Correctly", async () => { 26 26 const output = await runCommand("pnpm tsx demo.cac.ts complete -- --"); 27 27 console.log("Command Output:", output); 28 28 expect(output).toContain("--port"); ··· 33 33 expect(output).toContain("--mode"); 34 34 }); 35 35 }); 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 + });