64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { runCli } from "./runner.js";
|
|
import { VERSION } from "../version.js";
|
|
|
|
describe("CLI runner - version and help aliases", () => {
|
|
const versionVariants = [
|
|
["version"],
|
|
["verSion"],
|
|
["versioN"],
|
|
["VERSION"],
|
|
["Version"],
|
|
["v"],
|
|
["V"],
|
|
["-v"],
|
|
["-V"],
|
|
["--version"],
|
|
["--verSion"],
|
|
["--VERSION"],
|
|
["--v"],
|
|
["--V"],
|
|
];
|
|
|
|
for (const args of versionVariants) {
|
|
it(`correctly outputs version for "${args.join(" ")}"`, async () => {
|
|
const result = await runCli(args);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stderr).toBe("");
|
|
expect(result.stdout).toBe(`hose-use v${VERSION}\n`);
|
|
});
|
|
}
|
|
|
|
const helpVariants = [
|
|
[],
|
|
["help"],
|
|
["HeLp"],
|
|
["HELP"],
|
|
["h"],
|
|
["H"],
|
|
["-h"],
|
|
["-H"],
|
|
["--help"],
|
|
["--HeLp"],
|
|
["--HELP"],
|
|
["?"],
|
|
["-?"],
|
|
];
|
|
|
|
for (const args of helpVariants) {
|
|
it(`correctly outputs help for "${args.join(" ") || "<empty>"}"`, async () => {
|
|
const result = await runCli(args);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stderr).toBe("");
|
|
expect(result.stdout).toContain(`合思/易快报企业级 CLI 工具 (hose-use) v${VERSION}`);
|
|
expect(result.stdout).toContain("用法:");
|
|
});
|
|
}
|
|
|
|
it("handles unknown commands gracefully", async () => {
|
|
const result = await runCli(["unknown-command-xyz"]);
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.stderr).toContain("未知命令域: unknown-command-xyz");
|
|
});
|
|
});
|