82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { join } from "node:path";
|
|
|
|
const entry = join(import.meta.dir, "../../index.ts");
|
|
|
|
function cli(...args: string[]) {
|
|
const result = Bun.spawnSync([process.execPath, entry, ...args], {
|
|
cwd: import.meta.dir,
|
|
env: { ...process.env, TERM: "dumb", NO_COLOR: "1" },
|
|
});
|
|
return {
|
|
status: result.exitCode,
|
|
output: new TextDecoder().decode(result.stdout),
|
|
error: new TextDecoder().decode(result.stderr),
|
|
};
|
|
}
|
|
|
|
describe("CLI startup", () => {
|
|
test("registers all original names as lazy commands", () => {
|
|
const probe = Bun.spawnSync([
|
|
process.execPath,
|
|
"-e",
|
|
`import { main } from ${JSON.stringify(join(import.meta.dir, "../../command/main.ts"))}; console.log(JSON.stringify(Object.entries(main.subCommands).map(([name, command]) => [name, typeof command])));`,
|
|
]);
|
|
expect(probe.exitCode).toBe(0);
|
|
const commands = JSON.parse(new TextDecoder().decode(probe.stdout)) as [
|
|
string,
|
|
string,
|
|
][];
|
|
expect(commands.map(([name]) => name)).toEqual([
|
|
"audit",
|
|
"ci",
|
|
"db",
|
|
"down",
|
|
"export",
|
|
"exec",
|
|
"logs",
|
|
"maintenance",
|
|
"login",
|
|
"logout",
|
|
"operations",
|
|
"ps",
|
|
"restart",
|
|
"rollback",
|
|
"s3",
|
|
"start",
|
|
"stop",
|
|
"up",
|
|
"users",
|
|
"trust",
|
|
"whoami",
|
|
]);
|
|
expect(commands.every(([, type]) => type === "function")).toBe(true);
|
|
});
|
|
|
|
test("root help retains descriptions, alias, and completion command", () => {
|
|
const result = cli("--help");
|
|
expect(result.status).toBe(0);
|
|
expect(result.output).toContain("rollback, fuck");
|
|
expect(result.output).toContain("complete");
|
|
expect(result.output).toContain("Create and start deployments");
|
|
|
|
const missingCommand = cli();
|
|
expect(missingCommand.status).toBe(1);
|
|
expect(missingCommand.output).toContain("complete");
|
|
});
|
|
|
|
test("alias and named subcommand have the same help", () => {
|
|
const alias = cli("fuck", "--help");
|
|
const named = cli("rollback", "--help");
|
|
expect(alias.status).toBe(0);
|
|
expect(alias.output).toBe(named.output);
|
|
expect(alias.output).toContain("DEPLOYMENT");
|
|
});
|
|
|
|
test("completion still resolves flags from nested commands", () => {
|
|
const result = cli("complete", "--", "logs", "--");
|
|
expect(result.status).toBe(0);
|
|
expect(result.output).toContain("--follow");
|
|
});
|
|
});
|