import { describe, expect, it } from "vitest"; import { PRESENT_BYTE_LIMIT, PRESENT_FRAME_SANDBOX, buildPresentSrcdoc, isFrontendBundle, presentFrameSlotHtml, presentSourceBytes, previewPacket, } from "../web/present-frame.js"; describe("present frame srcdoc", () => { it("keeps the sandbox flag to scripts only", () => { expect(PRESENT_FRAME_SANDBOX).toBe("allow-scripts"); expect(PRESENT_FRAME_SANDBOX).not.toContain("allow-same-origin"); }); it("embeds the skeleton, styles, script, and sample packet", () => { const srcdoc = buildPresentSrcdoc({ html: `
`, css: `#app { color: #e1e7f0; }`, js: `present.onData(function (data) { document.getElementById("app").textContent = data.blocks.body; });`, packet: { schema: "present.v1", blocks: { body: "示例正文" } }, frameId: "pf1", }); expect(srcdoc).toContain(`
`); expect(srcdoc).toContain(`#app { color: #e1e7f0; }`); expect(srcdoc).toContain("present-host"); expect(srcdoc).toContain("applyPacket"); expect(srcdoc).toContain("示例正文"); expect(srcdoc).toContain(`default-src 'none'`); expect(srcdoc.indexOf("window.present")).toBeLessThan(srcdoc.indexOf("data.blocks.body")); const scripts = [...srcdoc.matchAll(/