feat: release 2.7.0-rc2
This commit is contained in:
@@ -1,81 +1,24 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { join } from "node:path";
|
||||
import { expect, test } from "bun:test";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } 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])));`,
|
||||
test("init help starts in an empty directory without requiring Compose", async () => {
|
||||
const cwd = await mkdtemp(join(tmpdir(), "kuber-startup-test-"));
|
||||
try {
|
||||
const process = Bun.spawn(
|
||||
["bun", resolve(import.meta.dir, "../../index.ts"), "init", "--help"],
|
||||
{ cwd, stdout: "pipe", stderr: "pipe" },
|
||||
);
|
||||
const [status, out, err] = await Promise.all([
|
||||
process.exited,
|
||||
new Response(process.stdout).text(),
|
||||
new Response(process.stderr).text(),
|
||||
]);
|
||||
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");
|
||||
});
|
||||
expect(status).toBe(0);
|
||||
expect(out + err).toContain("init");
|
||||
expect(out + err).not.toContain("Compose file cannot be found");
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user