diff options
| author | Matt Pocock <bot@x> | 2026-11-30 10:54:04 +0000 |
|---|---|---|
| committer | Matt Pocock <bot@x> | 2026-11-30 10:54:04 +0000 |
| commit | 6bb71dcc1e726a4298eb38aa29d2567467caeb02 (patch) | |
| tree | 22d8e61f58778d643aec0265692c351d3491a561 | |
| parent | 5f880b392862a8afc309b130573aa613c34c35b0 (diff) | |
wizard: test the full-screen restore guardwizard-harness
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | packages/wizard/test/screen.test.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/wizard/test/screen.test.ts b/packages/wizard/test/screen.test.ts new file mode 100644 index 0000000..1b70447 --- /dev/null +++ b/packages/wizard/test/screen.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from "vitest"; +import { enterFullScreen } from "../src/screen.js"; + +function fakeTty(isTTY = true) { + const writes: string[] = []; + const stream = { isTTY, write: (s: string) => writes.push(s) } as unknown as NodeJS.WriteStream; + return { stream, writes }; +} + +describe("enterFullScreen", () => { + it("enters the alternate screen with bracketed paste, and restores it once", () => { + const { stream, writes } = fakeTty(); + const before = process.listenerCount("exit"); + const screen = enterFullScreen(stream); + expect(writes[0]).toContain("\u001b[?1049h"); + expect(writes[0]).toContain("\u001b[?2004h"); + expect(process.listenerCount("exit")).toBe(before + 1); + screen.restore(); + screen.restore(); + expect(writes.slice(1)).toEqual(["\u001b[?2004l\u001b[?25h\u001b[?1049l"]); + expect(process.listenerCount("exit")).toBe(before); + screen.reclaim(); + expect(writes).toHaveLength(2); + }); + + it("restores the screen when the process exits without a clean close", () => { + const { stream, writes } = fakeTty(); + enterFullScreen(stream); + const restore = process.listeners("exit").at(-1) as () => void; + restore(); + expect(writes.at(-1)).toContain("\u001b[?1049l"); + }); + + it("leaves a non-terminal alone", () => { + const { stream, writes } = fakeTty(false); + enterFullScreen(stream).restore(); + expect(writes).toEqual([]); + }); +}); |
