diff --git a/packages/producer/src/services/htmlCompiler.remoteFontText.test.ts b/packages/producer/src/services/htmlCompiler.remoteFontText.test.ts new file mode 100644 index 0000000000..52ffaf6147 --- /dev/null +++ b/packages/producer/src/services/htmlCompiler.remoteFontText.test.ts @@ -0,0 +1,68 @@ +// @vitest-environment node +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { parseHTML } from "linkedom"; +import { compileForRender } from "./htmlCompiler.js"; + +const SHEET = "https://fonts.example.com/brand.css"; +const requested = vi.hoisted(() => [] as string[]); + +vi.mock("../utils/urlDownloader.js", async (importOriginal) => ({ + ...(await importOriginal()), + downloadToTemp: async (url: string) => { + requested.push(url); + throw new Error("offline test"); + }, + fetchPublicHttpsText: async (url: string) => { + requested.push(url); + if (url !== SHEET) throw new Error("offline test"); + return ( + `@font-face { font-family: "Brand` + + `` + + ``; + const fontCssWithLtAsCssEscape = fontFaceBlocks.join("\n").replace(//* Inlined external font stylesheet */\n${fontCssWithLtAsCssEscape}\n`; try { budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length); } catch (error) {