Refine CLI version flag alias parsing and test expectations
This commit is contained in:
1 parent
ab440024b8
commit
802c32c6bd
2 files changed
+60
-10
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { join } from "node:path";
|
||||
import { VERSION } from "./version.js";
|
||||
|
||||
const CLI_PATH = join(import.meta.dirname, "cli.ts");
|
||||
|
||||
function runCli(args: string[]) {
|
||||
return spawnSync("bun", [CLI_PATH, ...args], {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
}
|
||||
|
||||
describe("CLI version & help handling", () => {
|
||||
test.each([
|
||||
["version"],
|
||||
["v"],
|
||||
["-v"],
|
||||
["-version"],
|
||||
["--version"],
|
||||
["-V"],
|
||||
["--v"],
|
||||
["--V"]
|
||||
])("version command alias '%s' returns version JSON", (flag) => {
|
||||
const result = runCli([flag]);
|
||||
expect(result.status).toBe(0);
|
||||
const parsed = JSON.parse(result.stdout.trim());
|
||||
expect(parsed.name).toBe("seal-home");
|
||||
expect(parsed.version).toBe(VERSION);
|
||||
});
|
||||
|
||||
test("help command prints standard help banner", () => {
|
||||
const result = runCli(["help"]);
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stdout).toContain("seal-home CLI");
|
||||
expect(result.stdout).toContain("Usage:");
|
||||
});
|
||||
|
||||
test("invalid command displays unknown command error with help hint", () => {
|
||||
const result = runCli(["invalid-command"]);
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("Unknown command: invalid-command. Run 'seal-home help' for available commands.");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user