import { describe, expect, it } from "vitest"; import { buildArtifactSrcdoc, buildDeployableHtml, isDeployableKind, } from "$lib/utils/previewSrcdoc"; import { BADGE_HOST_ATTRIBUTE } from "$lib/utils/deployBadge"; /** Drop the injected badge script so the rest of the document can be compared. */ function stripBadge(html: string): string { return html.replace(/\n` terminated the artifact's // script — breaking the page *and* losing the badge. it("never injects into a trailing script that mentions a closing body tag", () => { const doc = `

hi

\n\n`; const out = buildDeployableHtml("html", doc); expect(out.startsWith(doc)).toBe(true); expect(out).not.toContain('var tpl = "\n { const out = buildDeployableHtml("html", "

fragment only

"); expect(out.startsWith("

fragment only

")).toBe(true); expect(out).toContain(BADGE_HOST_ATTRIBUTE); }); // Selecting an injection point used to be quadratic in the number of // `` occurrences; appending is linear regardless of content. it("stays fast on content that repeats the closing body tag", () => { const doc = "" + "".repeat(20_000) + ""; const start = performance.now(); buildDeployableHtml("html", doc); expect(performance.now() - start).toBeLessThan(100); }); it("cannot be terminated early by artifact content", () => { const out = buildDeployableHtml("html", ""); // The badge script must contain no raw `