File size: 1,106 Bytes
eb3f11e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // Command tree tests cover CLI command hierarchy construction and lookup.
import { Command } from "commander";
import { describe, expect, it } from "vitest";
import { removeCommandByName } from "./command-tree.js";
describe("command-tree", () => {
it("removes by command name", () => {
const program = new Command();
program.command("alpha");
program.command("beta");
expect(removeCommandByName(program, "alpha")).toBe(true);
expect(program.commands.map((command) => command.name())).toEqual(["beta"]);
});
it("removes by command alias", () => {
const program = new Command();
program.command("alpha").alias("a");
program.command("beta");
expect(removeCommandByName(program, "a")).toBe(true);
expect(program.commands.map((command) => command.name())).toEqual(["beta"]);
});
it("returns false when name does not exist", () => {
const program = new Command();
program.command("alpha");
expect(removeCommandByName(program, "missing")).toBe(false);
expect(program.commands.map((command) => command.name())).toEqual(["alpha"]);
});
});
|