81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
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 }],
|
|
layout: [],
|
|
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);
|
|
});
|
|
|
|
it("labels collection CSS as non-portable face selection", () => {
|
|
const result = generateFontFace({
|
|
family: "Fixture collection face",
|
|
sourcePath: "./fonts/fixture.ttc",
|
|
display: "swap",
|
|
inspection: {
|
|
...inspection,
|
|
fileName: "fixture.ttc",
|
|
container: "collection",
|
|
collection: {
|
|
version: "1.0",
|
|
selectedFace: 0,
|
|
hasDigitalSignature: false,
|
|
faces: [],
|
|
},
|
|
},
|
|
includeUnicodeRange: false,
|
|
});
|
|
expect(result.css).toContain('format("collection")');
|
|
expect(result.warnings).toContainEqual(
|
|
expect.stringMatching(/cannot portably identify/u),
|
|
);
|
|
});
|
|
});
|