test(terminal): compare restore with the actual fullscreen exit

This commit is contained in:
paseo-bot[bot]
2026-10-10 14:23:46 +02:00
parent 9d4a422838
commit 6eb61db7ea
@@ -568,6 +568,7 @@ describe("createTerminal", () => {
});
it("clears restored fullscreen content when the application leaves the alternate screen", async () => {
const exitOutput = "\x1b[?1049lPROMPT";
const session = trackSession(
await createTerminal({
workspaceId: "ws-test",
@@ -577,23 +578,27 @@ describe("createTerminal", () => {
command: process.execPath,
args: [
"-e",
"process.stdout.write('SHELL\\r\\n\\x1b[?1049h\\x1b[2J\\x1b[HFULLSCREEN'); setInterval(() => {}, 100000);",
`process.stdout.write('SHELL\\r\\n\\x1b[?1049h\\x1b[2J\\x1b[HFULLSCREEN'); process.stdin.setRawMode(true); process.stdin.on('data', () => process.stdout.write(${JSON.stringify(exitOutput)}));`,
],
}),
);
const state = await waitForState(session, (current) => getRowText(current, 0) === "FULLSCREEN");
session.write("q");
const exited = await waitForState(session, (current) => getRowText(current, 1) === "PROMPT");
const expected = getLines(exited).join("\n").trim();
expect(expected).toBe("SHELL\nPROMPT");
const restored = new xterm.Terminal({ cols: 80, rows: 10, allowProposedApi: true });
try {
await new Promise<void>((resolve) =>
restored.write(renderTerminalSnapshotToAnsi(state), resolve),
);
expect(restored.buffer.active.getLine(0)?.translateToString(true)).toBe("FULLSCREEN");
await new Promise<void>((resolve) => restored.write("\x1b[?1049lPROMPT", resolve));
await new Promise<void>((resolve) => restored.write(exitOutput, resolve));
const visible = Array.from({ length: restored.rows }, (_, row) =>
restored.buffer.active.getLine(row)?.translateToString(true),
).join("\n");
expect(visible).not.toContain("FULLSCREEN");
expect(visible.trim()).toBe("PROMPT");
expect(visible.trim()).toBe(expected);
} finally {
restored.dispose();
}