mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 06:37:28 +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", () => {
|
it("adds root help hint and marks commands with subcommands", () => {
|
||||||
process.argv = ["node", "openclaw", "--help"];
|
process.argv = ["node", "openclaw", "--help"];
|
||||||
const program = makeProgramWithCommands();
|
const program = makeProgramWithCommands();
|
||||||
@@ -115,35 +132,12 @@ describe("configureProgramHelp", () => {
|
|||||||
|
|
||||||
it("prints version and exits immediately when version flags are present", () => {
|
it("prints version and exits immediately when version flags are present", () => {
|
||||||
process.argv = ["node", "openclaw", "--version"];
|
process.argv = ["node", "openclaw", "--version"];
|
||||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
expectVersionExit({ expectedVersion: "OpenClaw 9.9.9-test (abc1234)" });
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prints version and exits immediately without commit metadata", () => {
|
it("prints version and exits immediately without commit metadata", () => {
|
||||||
process.argv = ["node", "openclaw", "--version"];
|
process.argv = ["node", "openclaw", "--version"];
|
||||||
resolveCommitHashMock.mockReturnValue(null);
|
resolveCommitHashMock.mockReturnValue(null);
|
||||||
|
expectVersionExit({ expectedVersion: "OpenClaw 9.9.9-test" });
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user