| 1 | import { readFileSync } from "node:fs"; |
| 2 | import { createHash } from "node:crypto"; |
| 3 | import { describe, expect, it } from "vitest"; |
| 4 | import { TERMINAL_SCREENSHOT } from "./media-manifest"; |
| 5 | |
| 6 | const webRoot = new URL("../", import.meta.url); |
| 7 | |
| 8 | function pngDimensions(src: string): [number, number] { |
| 9 | const image = readFileSync(new URL(`public/${src}`, webRoot)); |
| 10 | expect(image.subarray(1, 4).toString("ascii")).toBe("PNG"); |
| 11 | return [image.readUInt32BE(16), image.readUInt32BE(20)]; |
| 12 | } |
| 13 | |
| 14 | describe("media manifest integrity", () => { |
| 15 | it("keeps the terminal capture tied to its measured file and captured build", () => { |
| 16 | const src = TERMINAL_SCREENSHOT.src.slice(1); |
| 17 | const bytes = readFileSync(new URL(`public/${src}`, webRoot)); |
| 18 | expect(createHash("sha256").update(bytes).digest("hex")).toBe(TERMINAL_SCREENSHOT.sha256); |
| 19 | expect(pngDimensions(src)).toEqual([TERMINAL_SCREENSHOT.width, TERMINAL_SCREENSHOT.height]); |
| 20 | expect(TERMINAL_SCREENSHOT.sourceCommit).toMatch(/^[0-9a-f]{40}$/); |
| 21 | }); |
| 22 | }); |
| 23 |