diff --git a/tests/present-frame.test.ts b/tests/present-frame.test.ts new file mode 100644 index 0000000..568415e --- /dev/null +++ b/tests/present-frame.test.ts @@ -0,0 +1,64 @@ +import { describe, expect, it } from "vitest"; +import { + PRESENT_BYTE_LIMIT, + PRESENT_FRAME_SANDBOX, + buildPresentSrcdoc, + isFrontendBundle, + 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.onData"); + expect(srcdoc).toContain("示例正文"); + expect(srcdoc).toContain(`default-src 'none'`); + expect(srcdoc.indexOf("window.present")).toBeLessThan(srcdoc.indexOf("data.blocks.body")); + const scripts = [...srcdoc.matchAll(/ + + +${htmlSafe} + + + +