mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 20:10:42 +00:00
test: share cli help version assertions
This commit is contained in:
@@ -90,6 +90,23 @@ describe("configureProgramHelp", () => {
|
||||
}
|
||||
}
|
||||
|
||||
function expectVersionExit(params: { expectedVersion: string }) {
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`exit:${code ?? ""}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
try {
|
||||
const program = makeProgramWithCommands();
|
||||
expect(() => configureProgramHelp(program, testProgramContext)).toThrow("exit:0");
|
||||
expect(logSpy).toHaveBeenCalledWith(params.expectedVersion);
|
||||
expect(exitSpy).toHaveBeenCalledWith(0);
|
||||
} finally {
|
||||
logSpy.mockRestore();
|
||||
exitSpy.mockRestore();
|
||||
}
|
||||
}
|
||||
|
||||
it("adds root help hint and marks commands with subcommands", () => {
|
||||
process.argv = ["node", "openclaw", "--help"];
|
||||
const program = makeProgramWithCommands();
|
||||
@@ -115,35 +132,12 @@ describe("configureProgramHelp", () => {
|
||||
|
||||
it("prints version and exits immediately when version flags are present", () => {
|
||||
process.argv = ["node", "openclaw", "--version"];
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`exit:${code ?? ""}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
const program = makeProgramWithCommands();
|
||||
expect(() => configureProgramHelp(program, testProgramContext)).toThrow("exit:0");
|
||||
expect(logSpy).toHaveBeenCalledWith("OpenClaw 9.9.9-test (abc1234)");
|
||||
expect(exitSpy).toHaveBeenCalledWith(0);
|
||||
|
||||
logSpy.mockRestore();
|
||||
exitSpy.mockRestore();
|
||||
expectVersionExit({ expectedVersion: "OpenClaw 9.9.9-test (abc1234)" });
|
||||
});
|
||||
|
||||
it("prints version and exits immediately without commit metadata", () => {
|
||||
process.argv = ["node", "openclaw", "--version"];
|
||||
resolveCommitHashMock.mockReturnValue(null);
|
||||
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`exit:${code ?? ""}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
const program = makeProgramWithCommands();
|
||||
expect(() => configureProgramHelp(program, testProgramContext)).toThrow("exit:0");
|
||||
expect(logSpy).toHaveBeenCalledWith("OpenClaw 9.9.9-test");
|
||||
expect(exitSpy).toHaveBeenCalledWith(0);
|
||||
|
||||
logSpy.mockRestore();
|
||||
exitSpy.mockRestore();
|
||||
expectVersionExit({ expectedVersion: "OpenClaw 9.9.9-test" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user