import { describe, expect, it } from "vitest"; import { generateFontFace, validateLocalPath } from "../../src/core/css"; import type { FontInspection } from "../../src/core/model"; const inspection: FontInspection = { fileName: "Variable.woff", fileSize: 1_000, container: "woff", flavor: "WOFF", names: { family: "Fixture", subfamily: "Regular" }, unitsPerEm: 1_000, ascender: 800, descender: -200, glyphCount: 3, unicodeCount: 3, coverageRanges: [{ start: 0x41, end: 0x43 }], coverageRangesTruncated: false, coverageBlocks: [], axes: [{ tag: "wght", name: "Weight", min: 200, default: 400, max: 900 }], embedding: { raw: 0, rawHex: "0x0000", level: "installable", label: "Installable embedding", noSubsetting: false, bitmapOnly: false, subsetAllowed: true, signals: [], }, tables: [], expandedSize: 2_000, warnings: [], }; describe("safe CSS generation", () => { it("quotes metadata, emits axes and a complete compact range", () => { const result = generateFontFace({ family: 'Fixture "Local"', sourcePath: "./fonts/fixture.woff", display: "swap", inspection, includeUnicodeRange: true, }); expect(result.css).toContain('font-family: "Fixture \\"Local\\""'); expect(result.css).toContain("font-weight: 200 900"); expect(result.css).toContain("unicode-range: U+0041-0043"); }); it("rejects remote and control-bearing paths", () => { expect(() => validateLocalPath("https://example.test/font.woff")).toThrow( /local asset paths/u, ); expect(() => validateLocalPath("./font\n.woff")).toThrow(/control/u); }); });