60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { runCompletion } from "../src/commands/completion";
|
|
|
|
function stripAnsi(text: string) {
|
|
return text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
}
|
|
|
|
test("shows completion help text", async () => {
|
|
const result = await runCompletion(["--help"]);
|
|
const plainStdout = stripAnsi(result.stdout);
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
expect(plainStdout.startsWith("\n")).toBe(true);
|
|
expect(result.stdout).toContain("Usage:");
|
|
expect(result.stdout).toContain("bunx skvlt completion");
|
|
expect(result.stdout).toContain("\x1b[1mUsage:\x1b[0m");
|
|
expect(plainStdout).toContain(
|
|
"\n\nExplore the open-source repo at https://github.com/xixu-me/skills-vault",
|
|
);
|
|
expect(
|
|
plainStdout.endsWith(
|
|
"Explore the open-source repo at https://github.com/xixu-me/skills-vault\n\n",
|
|
),
|
|
).toBe(true);
|
|
expect(result.stdout).toContain(
|
|
"Explore the open-source repo at https://github.com/xixu-me/skills-vault",
|
|
);
|
|
});
|
|
|
|
test("prints a bash completion script", async () => {
|
|
const result = await runCompletion(["bash"]);
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.errorCode).toBeUndefined();
|
|
expect(result.stdout).toContain("_skvlt_completion");
|
|
expect(result.stdout).toContain("COMPREPLY");
|
|
expect(result.stdout).toContain("backup restore doctor completion");
|
|
expect(result.payload).toMatchObject({
|
|
shell: "bash",
|
|
});
|
|
});
|
|
|
|
test("rejects unsupported shells with a stable error code", async () => {
|
|
const result = await runCompletion(["fish"]);
|
|
const plainStderr = stripAnsi(result.stderr);
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.errorCode).toBe("INVALID_ARGUMENT");
|
|
expect(plainStderr.startsWith("\n")).toBe(true);
|
|
expect(plainStderr).toContain("ERROR");
|
|
expect(plainStderr).toContain("Unsupported shell: fish");
|
|
expect(plainStderr).toContain("Usage:");
|
|
expect(plainStderr).toContain("bunx skvlt completion <bash|zsh|powershell>");
|
|
expect(plainStderr).toContain("Example:");
|
|
expect(plainStderr).toContain("bunx skvlt completion bash");
|
|
expect(plainStderr.endsWith("\n\n")).toBe(true);
|
|
expect(result.stderr).toContain("\x1b[");
|
|
expect(result.stderr).toContain("ERROR");
|
|
});
|