import { expect, test } from "bun:test"; import { browserFont } from "./browser-fonts"; test("browser fonts are external WOFF2 files with conditional caching and a fixed allowlist", async () => { const url = "http://localhost/fonts/browser/InstrumentSerif-Regular.woff2"; const response = browserFont(new Request(url)); expect(response.status).toBe(200); expect(response.headers.get("Content-Type")).toBe("font/woff2"); const bytes = new Uint8Array(await response.arrayBuffer()); expect(new TextDecoder().decode(bytes.slice(0, 4))).toBe("wOF2"); expect(browserFont(new Request(url, { headers: { "If-None-Match": response.headers.get("ETag")! } })).status).toBe(304); expect(browserFont(new Request("http://localhost/fonts/browser/.env")).status).toBe(404); expect(browserFont(new Request("http://localhost/fonts/browser/%2e%2e%2f.env")).status).toBe(404); expect(await browserFont(new Request(url, { method: "HEAD" })).text()).toBe(""); });