Skip to content

Commit 3150b8a

Browse files
test(html): hold XML stylesheets to the browsers a renderer targets
Claude-Session: https://claude.ai/code/session_01WzCD9CDRFzG1j2yQARWzLp Co-authored-by: Alexander Akait <[email protected]>
1 parent 7da5084 commit 3150b8a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎test/unitCases/HtmlSyntax.unittest.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,6 +3880,30 @@ b&#10;c">
38803880
).toMatchSnapshot();
38813881
});
38823882

3883+
it("should write only what the target browsers read", () => {
3884+
const { builtinEmbeddedRenderer } = require("../../lib/html/builtinEmbeddedRenderer");
3885+
const document =
3886+
'<svg xmlns="http://www.w3.org/2000/svg"><style>g > .b { fill: rgba(0,0,255,0.5) } @media (min-width: 0px) { .e { fill: red } } .p { user-select: none }</style><rect style="fill: rgba(255,0,0,0.5)"/></svg>';
3887+
/**
3888+
* @param {string[]=} browsers the browserslist selection
3889+
* @returns {string} the minified document
3890+
*/
3891+
const minify = (browsers) =>
3892+
/** @type {{ code: string }} */ (
3893+
new SourceProcessor().process(document, {
3894+
xml: true,
3895+
mode: "minify",
3896+
renderEmbeddedSource: builtinEmbeddedRenderer(
3897+
browsers === undefined ? undefined : { environment: { browsers } }
3898+
)
3899+
})
3900+
).code;
3901+
expect(minify()).toMatchSnapshot("every ability");
3902+
expect(minify(["chrome 60", "safari 10", "ie 11"])).toMatchSnapshot(
3903+
"legacy browsers"
3904+
);
3905+
});
3906+
38833907
it("should defer an XML stylesheet to an asynchronous renderer", async () => {
38843908
/** @type {string[]} */
38853909
const offered = [];

‎test/unitCases/__snapshots__/HtmlSyntax.unittest.js.snap‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ b&#10;c\\">
9696
</svg>"
9797
`;
9898
99+
exports[`parseHtml XML mode printing should write only what the target browsers read: every ability 1`] = `"<svg xmlns=\\"http://www.w3.org/2000/svg\\"><style>g>.b{fill:#0000ff80}@media (width>=0px){.e{fill:red}}.p{user-select:none}</style><rect style=\\"fill:#ff000080\\"/></svg>"`;
100+
101+
exports[`parseHtml XML mode printing should write only what the target browsers read: legacy browsers 1`] = `"<svg xmlns=\\"http://www.w3.org/2000/svg\\"><style>g>.b{fill:rgba(0,0,255,.5)}@media (min-width:0px){.e{fill:red}}.p{-webkit-user-select:none;-ms-user-select:none;user-select:none}</style><rect style=\\"fill:rgba(255,0,0,.5)\\"/></svg>"`;
102+
99103
exports[`parseHtml XML mode printing should write the shortest well-formed XML when minifying 1`] = `
100104
"<?xml version=\\"1.0\\"?><!DOCTYPE svg [ <!ENTITY ns \\"http://www.w3.org/2000/svg\\"> <!ATTLIST svg version CDATA \\"1.1\\"> ]><svg xmlns=\\"&ns;\\" viewBox=\\"0 0 10 10\\" data-q='say \\"hi\\"' data-both='it&apos;s \\"q\\"' data-ws=\\"a b&#10;c\\">
101105
<title>A &amp; B &gt; C</title>

0 commit comments

Comments
 (0)