init
This commit is contained in:
commit
932d4ad420
46 changed files with 5800 additions and 0 deletions
57
tests/lib/cli.test.ts
Normal file
57
tests/lib/cli.test.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { describe, it, expect } from "vitest"
|
||||
import { CLICommand } from "../../lib/cli/CLICommand"
|
||||
|
||||
class TestLeafCommand extends CLICommand {
|
||||
readonly name = "leaf"
|
||||
readonly help = "A leaf command"
|
||||
readonly description = "Test leaf"
|
||||
|
||||
async execute(): Promise<number> {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
class TestChildA extends CLICommand {
|
||||
readonly name = "child-a"
|
||||
readonly help = "Child A"
|
||||
readonly description = "Test child A"
|
||||
}
|
||||
|
||||
class TestChildB extends CLICommand {
|
||||
readonly name = "child-b"
|
||||
readonly help = "Child B"
|
||||
readonly description = "Test child B"
|
||||
}
|
||||
|
||||
class TestBranchCommand extends CLICommand {
|
||||
readonly name = "branch"
|
||||
readonly help = "A branch command"
|
||||
readonly description = "Test branch"
|
||||
|
||||
static override _subcommands = [TestChildA, TestChildB]
|
||||
}
|
||||
|
||||
describe("CLICommand", () => {
|
||||
it("leaf command returns exit code from execute()", async () => {
|
||||
const cmd = new TestLeafCommand()
|
||||
expect(await cmd.execute({} as any)).toBe(42)
|
||||
})
|
||||
|
||||
it("branch command has subcommands", () => {
|
||||
expect(TestBranchCommand._subcommands).toHaveLength(2)
|
||||
expect(new TestBranchCommand().name).toBe("branch")
|
||||
})
|
||||
|
||||
it("base CLICommand.execute returns 0", async () => {
|
||||
const cmd = new TestChildA()
|
||||
expect(await cmd.execute({} as any)).toBe(0)
|
||||
})
|
||||
|
||||
it("subcommands are constructable", () => {
|
||||
for (const Sub of TestBranchCommand._subcommands) {
|
||||
const instance = new Sub()
|
||||
expect(instance.name).toBeTruthy()
|
||||
expect(instance.help).toBeTruthy()
|
||||
}
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue