|
| 1 | +// @effect-diagnostics nodeBuiltinImport:off -- exercises the checked-in WASM artifacts. |
| 2 | +import * as NodeFS from "node:fs"; |
| 3 | +import * as NodeURL from "node:url"; |
| 4 | + |
| 5 | +import { afterEach, describe, expect, it, vi } from "vite-plus/test"; |
| 6 | + |
| 7 | +import { GhosttyTerminalCore, type GhosttyTheme } from "./core"; |
| 8 | + |
| 9 | +vi.mock("./vendor/ghostty-vt.wasm?url", () => ({ default: "test://ghostty-vt.wasm" })); |
| 10 | +vi.mock("./vendor/ghostty-write-pty.wasm?url&no-inline", () => ({ |
| 11 | + default: "test://ghostty-write-pty.wasm", |
| 12 | +})); |
| 13 | + |
| 14 | +const testTheme: GhosttyTheme = { |
| 15 | + foreground: { r: 255, g: 255, b: 255 }, |
| 16 | + background: { r: 0, g: 0, b: 0 }, |
| 17 | + cursor: { r: 255, g: 255, b: 255 }, |
| 18 | +}; |
| 19 | + |
| 20 | +const wasmPaths = { |
| 21 | + "ghostty-vt.wasm": NodeURL.fileURLToPath(new URL("./vendor/ghostty-vt.wasm", import.meta.url)), |
| 22 | + "ghostty-write-pty.wasm": NodeURL.fileURLToPath( |
| 23 | + new URL("./vendor/ghostty-write-pty.wasm", import.meta.url), |
| 24 | + ), |
| 25 | +} as const; |
| 26 | + |
| 27 | +async function serveVendoredWasm(input: string | URL | Request): Promise<Response> { |
| 28 | + const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; |
| 29 | + const filename = Object.keys(wasmPaths).find((candidate) => url.includes(candidate)); |
| 30 | + if (!filename) return new Response(null, { status: 404 }); |
| 31 | + |
| 32 | + const bytes = NodeFS.readFileSync(wasmPaths[filename as keyof typeof wasmPaths]); |
| 33 | + return new Response(Uint8Array.from(bytes).buffer); |
| 34 | +} |
| 35 | + |
| 36 | +describe("GhosttyTerminalCore", () => { |
| 37 | + afterEach(() => vi.unstubAllGlobals()); |
| 38 | + |
| 39 | + it("retains history through the app's configured scrollback budget", async () => { |
| 40 | + vi.stubGlobal("fetch", serveVendoredWasm); |
| 41 | + const core = await GhosttyTerminalCore.create(80, 10, 8, 16, testTheme, () => {}); |
| 42 | + |
| 43 | + try { |
| 44 | + core.write(Array.from({ length: 1_200 }, (_, index) => `${index + 1}\r\n`).join("")); |
| 45 | + const scrollbar = core.scrollbarState(); |
| 46 | + if (!scrollbar) throw new Error("libghostty-vt did not return scrollbar state"); |
| 47 | + |
| 48 | + // This scenario retained only 602 rows with the previous 10,000-byte |
| 49 | + // configuration. The byte budget does not promise an exact row count. |
| 50 | + expect(scrollbar.total - scrollbar.len).toBeGreaterThan(1_000); |
| 51 | + } finally { |
| 52 | + core.dispose(); |
| 53 | + } |
| 54 | + }); |
| 55 | +}); |
0 commit comments