Skip to content

Commit db6a2ac

Browse files
test: hold EMBEDDED_LANGUAGES to the sites that offer it
Both lists say a caller reads them to know which languages it handles, so each entry needs a live offer site behind it and nothing may arrive that the list does not name. Neither direction was checked: a language added with no site, or a site removed, showed up only as an unexplained snapshot diff somewhere else. One document and one stylesheet reach every site, and each test asserts the offered set against the exported list, then that the renderer's answer is what the serialization carries — being offered a body is only half of minifying it.
1 parent f6b470a commit db6a2ac

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎test/CssSyntax.unittest.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7158,6 +7158,37 @@ describe("SourceProcessor — renderEmbeddedSource over a data: url", () => {
71587158
expect(offered('.a{background:url("./img.png")}')).toEqual([]);
71597159
});
71607160

7161+
it("offers every language `EMBEDDED_LANGUAGES` names, and prints each answer", () => {
7162+
const { EMBEDDED_LANGUAGES } = require("../lib/css/syntax");
7163+
7164+
// One stylesheet reaching every language a `data:` payload's media type can
7165+
// name, an `@import` among them.
7166+
const sheet =
7167+
'@import url("data:text/css,.inner { color : red }");' +
7168+
'.svg{background:url("data:image/svg+xml,<svg> <rect/> </svg>")}' +
7169+
'.html{background:url("data:text/html,<p> x </p>")}' +
7170+
".json{background:url('data:application/json,{ \"a\" : 1 }')}" +
7171+
'.js{background:url("data:text/javascript,var a = 1")}';
7172+
7173+
// The list is what a caller reads to say up front which languages it
7174+
// handles, so every entry needs a live offer site behind it, and nothing
7175+
// may arrive that the list does not name. Asserted over the whole set
7176+
// rather than per payload: either half drifting is what this catches.
7177+
expect([...new Set(offered(sheet).map(([type]) => type))].sort()).toEqual(
7178+
[...EMBEDDED_LANGUAGES].sort()
7179+
);
7180+
7181+
// And what the renderer answered is what the stylesheet carries — being
7182+
// offered a payload is only half of minifying it.
7183+
expect(minify(sheet, (source, { type }) => `/*${type}*/`)).toBe(
7184+
"@import url(data:text/css,/*css*/);" +
7185+
".svg{background:url(data:image/svg+xml,/*svg*/)}" +
7186+
".html{background:url(data:text/html,/*html*/)}" +
7187+
".json{background:url(data:application/json,/*json*/)}" +
7188+
".js{background:url(data:text/javascript,/*javascript*/)}"
7189+
);
7190+
});
7191+
71617192
it("rebuilds the url in the shortest form that parses back to it", () => {
71627193
// A rebuilt url keeps its base64-ness, and loses quotes it no longer needs.
71637194
expect(minify(svgUrl, (s) => s.replace(/\s+/g, ""))).toBe(

‎test/HtmlSyntax.unittest.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5317,6 +5317,40 @@ describe("SourceProcessor — renderEmbeddedSource", () => {
53175317
expect([...hosts]).toEqual(["html"]);
53185318
});
53195319

5320+
it("offers every language `EMBEDDED_LANGUAGES` names, and prints each answer", () => {
5321+
const { EMBEDDED_LANGUAGES } = require("../lib/html/syntax");
5322+
5323+
// One document reaching every offer site: an inline `<style>`, a `<script>`,
5324+
// a JSON `<script>`, a `style` attribute, an `<svg>` subtree and the
5325+
// document an `<iframe srcdoc>` holds.
5326+
const html =
5327+
"<style> .a { color : red } </style>" +
5328+
"<script> var a = 1 </script>" +
5329+
'<script type="application/json"> { "a" : 1 } </script>' +
5330+
'<p style=" color : red ">x</p>' +
5331+
'<svg viewBox="0 0 2 2"> <rect/> </svg>' +
5332+
'<iframe srcdoc="&lt;p&gt; inner &lt;/p&gt;"></iframe>';
5333+
5334+
// The list is what a caller reads to say up front which languages it
5335+
// handles, so every entry needs a live offer site behind it, and nothing
5336+
// may arrive that the list does not name. Asserted over the whole set
5337+
// rather than per site: either half drifting is what this catches.
5338+
expect([...new Set(offered(html).map(([type]) => type))].sort()).toEqual(
5339+
[...EMBEDDED_LANGUAGES].sort()
5340+
);
5341+
5342+
// And what the renderer answered is what the serialization carries — being
5343+
// offered a body is only half of minifying it.
5344+
expect(minify(html, (source, { type }) => `/*${type}*/`)).toBe(
5345+
"<style>/*css*/</style>" +
5346+
"<script>/*javascript*/</script>" +
5347+
"<script type=application/json>/*json*/</script>" +
5348+
"<p style=/*css*/>x</p>" +
5349+
"/*svg*/" +
5350+
'<iframe srcdoc="/*html*/"></iframe>'
5351+
);
5352+
});
5353+
53205354
it("offers a JSON `<script>` as json, by type and by `+json` subtype", () => {
53215355
expect(
53225356
offered(

0 commit comments

Comments
 (0)