import { afterEach, describe, expect, it, vi } from "vitest"; vi.mock("@hyperframes/core/compiler", () => ({ bundleToSingleHtml: vi.fn(async () => "
bundled"), })); import { __resetFontLocalizationWarningsForTests, bundleWithLocalizedFonts, localizeWithProducer, } from "./bundleWithLocalizedFonts.js"; afterEach(() => { __resetFontLocalizationWarningsForTests(); vi.clearAllMocks(); }); describe("bundleWithLocalizedFonts (call-site integration)", () => { it("runs the injected font localizer over the plain bundle", async () => { const localize = vi.fn(async (html: string) => html.replace("bundled", "bundled+fonts")); const html = await bundleWithLocalizedFonts("/project", localize); expect(localize).toHaveBeenCalledOnce(); expect(localize).toHaveBeenCalledWith("bundled"); expect(html).toBe("bundled+fonts"); }); it("returns the localizer output verbatim (localization is the last step)", async () => { const html = await bundleWithLocalizedFonts("/project", async () => "embedded"); expect(html).toBe("embedded"); }); }); describe("localizeWithProducer", () => { it("embeds fonts when the injector is available", async () => { const inject = vi.fn(async (html: string) => `${html}`); const warn = vi.fn(); const out = await localizeWithProducer("", async () => inject, warn); expect(out).toBe(""); expect(warn).not.toHaveBeenCalled(); }); it("fails open silently when producer is unavailable (module absent → null)", async () => { const warn = vi.fn(); const out = await localizeWithProducer("plain", async () => null, warn); // Never worse than a plain bundle; benign absence is not a warning. expect(out).toBe("plain"); expect(warn).not.toHaveBeenCalled(); }); it("fails open WITH a diagnostic when the injector itself throws", async () => { const warn = vi.fn(); const boom: () => Promise