test(cli): add banner emission reset helper (#87121)

This commit is contained in:
Gavin Lee
2026-06-23 03:12:07 +08:00
committed by GitHub
parent b4bc1f20c9
commit 8c366bfefd
2 changed files with 32 additions and 0 deletions

View File

@@ -132,4 +132,29 @@ describe("emitCliBanner", () => {
expect(writeSpy).toHaveBeenCalledWith("\n🦞 OpenClaw 2026.3.7 (abc1234)\n\n");
expect(hasEmittedCliBanner()).toBe(true);
});
it("can reset banner emission state for same-module tests", async () => {
const { emitCliBanner, hasEmittedCliBanner, testing } = await importFreshBannerModule();
setStdoutIsTty(true);
const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
const options = {
argv: ["node", "openclaw"],
commit: "abc1234",
env: { LANG: "en_US.UTF-8" },
isTty: true,
mode: "off" as const,
platform: "darwin" as const,
richTty: false,
};
emitCliBanner("2026.3.7", options);
expect(hasEmittedCliBanner()).toBe(true);
testing.resetBannerEmittedForTests();
expect(hasEmittedCliBanner()).toBe(false);
emitCliBanner("2026.3.7", options);
expect(writeSpy).toHaveBeenCalledTimes(2);
});
});

View File

@@ -117,3 +117,10 @@ export function emitCliBanner(version: string, options: BannerOptions = {}) {
export function hasEmittedCliBanner(): boolean {
return bannerEmitted;
}
export const testing = {
resetBannerEmittedForTests(): void {
bannerEmitted = false;
},
};
export { testing as __testing };