Pre Release New Changes
This commit is contained in:
@@ -88,3 +88,60 @@ test("renders rich script metadata and deduplicates by source", () => {
|
||||
expect(html).toContain('data-wrnexus-runtime-src="captcha"');
|
||||
expect(html).not.toContain('rel="modulepreload" href="/__wrnexus/assets/captcha.abc.js"');
|
||||
});
|
||||
|
||||
test("promotes WRN style blocks into head after global CSS with CSP nonce", () => {
|
||||
const html = renderDocument({
|
||||
meta: { title: "Styled" },
|
||||
extraHead: '<link rel="stylesheet" href="/global.css" />',
|
||||
styleNonce: "nonce-123",
|
||||
body:
|
||||
'<style data-wrnexus-style="Card" data-wrnexus-style-id="card" data-wrnexus-style-kind="component">.shared{color:blue}</style>' +
|
||||
'<style data-wrnexus-style="Page" data-wrnexus-style-id="page" data-wrnexus-style-kind="page">.shared{color:red}</style>' +
|
||||
'<style data-wrnexus-style="Layout" data-wrnexus-style-id="layout" data-wrnexus-style-kind="layout">.shared{color:green}</style>' +
|
||||
'<main class="shared">Styled</main>',
|
||||
});
|
||||
|
||||
expect(html).not.toContain('<div id="app"><style');
|
||||
expect(html).toContain('<main class="shared">Styled</main>');
|
||||
expect(html.match(/data-wrnexus-style-id=/g)).toHaveLength(3);
|
||||
expect(html.match(/nonce="nonce-123"/g)).toHaveLength(3);
|
||||
|
||||
const globalIndex = html.indexOf("/global.css");
|
||||
const layoutIndex = html.indexOf('data-wrnexus-style-id="layout"');
|
||||
const pageIndex = html.indexOf('data-wrnexus-style-id="page"');
|
||||
const componentIndex = html.indexOf('data-wrnexus-style-id="card"');
|
||||
expect(globalIndex).toBeLessThan(layoutIndex);
|
||||
expect(layoutIndex).toBeLessThan(pageIndex);
|
||||
expect(pageIndex).toBeLessThan(componentIndex);
|
||||
});
|
||||
|
||||
test("deduplicates repeated component style blocks", () => {
|
||||
const style =
|
||||
'<style data-wrnexus-style="Card" data-wrnexus-style-id="card" data-wrnexus-style-kind="component">.card{display:grid}</style>';
|
||||
const html = renderDocument({
|
||||
meta: { title: "Repeated" },
|
||||
body: `${style}<article>One</article>${style}<article>Two</article>`,
|
||||
});
|
||||
|
||||
expect(html.match(/data-wrnexus-style-id="card"/g)).toHaveLength(1);
|
||||
expect(html).toContain("<article>One</article><article>Two</article>");
|
||||
});
|
||||
|
||||
test("places document-layout WRN styles at the end of head", () => {
|
||||
const html = renderDocument({
|
||||
meta: { title: "Document styles" },
|
||||
styleNonce: "document-nonce",
|
||||
body: "",
|
||||
documentTemplate:
|
||||
'<html><head><link rel="stylesheet" href="/document-global.css" /></head><body>' +
|
||||
'<style data-wrnexus-style="Document" data-wrnexus-style-id="document-layout" data-wrnexus-style-kind="layout">.shell{display:block}</style>' +
|
||||
'<div id="app" class="shell">Page</div></body></html>',
|
||||
});
|
||||
|
||||
const globalIndex = html.indexOf("/document-global.css");
|
||||
const styleIndex = html.indexOf('data-wrnexus-style-id="document-layout"');
|
||||
const headEnd = html.indexOf("</head>");
|
||||
expect(globalIndex).toBeLessThan(styleIndex);
|
||||
expect(styleIndex).toBeLessThan(headEnd);
|
||||
expect(html).not.toContain("<body><style");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user