Preserve global typography and metadata in MJML exports
Quality / quality (ubuntu-latest) (push) Failing after 0s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 17:02:11 +05:30
1 parent 6afffe9f08
commit 4e0f5adb5f
4 files changed
+39 -3

No files matched your search

@@ -0,0 +1,30 @@
import { expect, test } from "bun:test";
import { createRequire } from "node:module";
import type { BlockDocument } from "@wrnexus/blocks";
import { renderEmail } from "../src/index.ts";
const compile = createRequire(import.meta.url)("mjml");
test("MJML preserves document metadata and global typography in compiled HTML", async () => {
const document: BlockDocument = {
schemaVersion: 1, kind: "email", meta: { subject: 'Brand & "News" <today>', preheader: 'Preview <safe> & useful', lang: "en" }, theme: { tokens: {} },
root: { id: "root", type: "layout.email-document", version: 1, props: { width: "600", fontFamily: "Georgia, serif", textColor: "#123456" }, styles: {}, slots: {
content: [{ id: "text", type: "content.text", version: 1, props: { text: "Brand text" }, styles: {}, slots: {} }, { id: "button", type: "content.button", version: 1, props: { label: "Brand action", href: "https://example.com" }, styles: {}, slots: {} }],
} },
};
const before = structuredClone(document);
const result = await renderEmail(document, { mjml: true });
expect(result.ok).toBe(true);
if (!result.ok) return;
const source = result.value.exports!.mjml!;
expect(source).toContain('<mj-title>Brand &amp; &quot;News&quot; &lt;today&gt;</mj-title>');
expect(source).toContain('<mj-preview>Preview &lt;safe&gt; &amp; useful</mj-preview>');
expect(source).toContain('<mj-all font-family="Georgia, serif" />');
const compiled = await compile(source, { validationLevel: "strict", minify: false });
expect(compiled.errors).toEqual([]);
expect(compiled.html).toContain("font-family:Georgia, serif");
expect(compiled.html).toContain("color:#123456");
expect(compiled.html).toContain("Preview &lt;safe&gt; &amp; useful");
expect(compiled.html).not.toContain("<safe>");
expect(document).toEqual(before);
});