import { expect, test } from "bun:test"; import { renderDocument } from "../src/index.ts"; test("escapes metadata and script URLs while preserving trusted rendered body", () => { const html = renderDocument({ meta: { title: '', description: '" onload="x' }, body: "
trusted
", scripts: ['">'], }); expect(html).not.toContain(''); expect(html).toContain("</title>"); expect(html).toContain("
trusted
"); expect(html).not.toContain(""); }); test("deduplicates runtime scripts and module preloads", () => { const html = renderDocument({ meta: { title: "Page" }, body: "", scripts: ["/app.js", "/app.js"], }); expect(html.match(/rel="modulepreload"/g)).toHaveLength(1); expect(html.match(/src="\/app\.js"/g)).toHaveLength(1); }); test("always emits a document language and preserves an explicit language", () => { const fallback = renderDocument({ meta: {}, body: "" }); expect(fallback).toContain(''); const explicit = renderDocument({ meta: {}, body: "", htmlAttrs: ' data-theme="dark" lang="fr"', }); expect(explicit).toContain(''); expect(explicit).not.toContain('lang="en"'); });