// @vitest-environment happy-dom import { describe, expect, it } from "vitest"; import { PREVIEW_RASTER_ATTR, RUNTIME_STAMPED_ATTR, STUDIO_PREVIEW_LAZY_ATTR, PREVIEW_VIDEO_CANVAS_ATTR, PREVIEW_VIDEO_FRAME_ATTR, PREVIEW_VIDEO_SOURCE_ATTR, } from "@hyperframes/core/studio-preview-mark"; import { authoredStyles, liveMarkupWithoutPreviewMarks } from "./authoredSource"; describe("liveMarkupWithoutPreviewMarks", () => { it("omits generated video surfaces and their hiding marks from copied composition markup", () => { const live = document.createElement("div"); live.innerHTML = ``; expect(liveMarkupWithoutPreviewMarks(live)).toBe( '
', ); expect(live.querySelectorAll("canvas")).toHaveLength(2); }); it("drops the preview's raster mark from an element and its descendants", () => { const live = document.createElement("div"); live.innerHTML = `
LOUD
`; live.setAttribute(PREVIEW_RASTER_ATTR, ""); expect(liveMarkupWithoutPreviewMarks(live)).toBe( '
LOUD
', ); expect(live.hasAttribute(PREVIEW_RASTER_ATTR)).toBe(true); }); it("gives a lazily previewed image back its authored loading", () => { const live = document.createElement("div"); live.innerHTML = ``; expect(liveMarkupWithoutPreviewMarks(live)).toBe('
'); }); it("drops the runtime's stamp so copied markup cannot carry it into a project file", () => { const live = document.createElement("div"); live.innerHTML = `
`; live.setAttribute(RUNTIME_STAMPED_ATTR, "1"); expect(liveMarkupWithoutPreviewMarks(live)).toBe( '
', ); }); }); // fails without the fix: an SVG element named template has no content, and the search read it as an HTML one. describe("authoredStyles", () => { it("reads a page holding an SVG element named template around a composition root", () => { const html = `
`; expect(authoredStyles(html)).toContainEqual(["#a", "color: red"]); }); });