Skip to content

Commit baa2fc1

Browse files
test(html): drive collapseWhitespace through SourceProcessor in-process
The config case exercises it only inside the minimizer's worker pool, which jest's coverage cannot see — the same reason the CSS `convertLengthUnits` transforms are unit-tested directly.
1 parent f4219a6 commit baa2fc1

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎test/HtmlSyntax.unittest.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,6 +3673,47 @@ describe("parseHtml — SourceProcessor", () => {
36733673
});
36743674
});
36753675

3676+
describe("SourceProcessor — collapseWhitespace", () => {
3677+
const { SourceProcessor } = require("../lib/html/syntax");
3678+
3679+
/**
3680+
* @param {string} html input markup
3681+
* @returns {string} the minified serialization with text whitespace collapsed
3682+
*/
3683+
const collapse = (html) =>
3684+
new SourceProcessor().process(html, {
3685+
minimize: true,
3686+
collapseWhitespace: true
3687+
}).code;
3688+
3689+
it("collapses each run of whitespace to one space, never removing it", () => {
3690+
expect(collapse("<p>a \t\n b</p>")).toBe("<p>a b");
3691+
});
3692+
3693+
it("prints a lone tab as the shorter single space", () => {
3694+
expect(collapse("<p>a\tb</p>")).toBe("<p>a b");
3695+
});
3696+
3697+
it("collapses a trailing run", () => {
3698+
expect(collapse("<p>a b </p>")).toBe("<p>a b ");
3699+
});
3700+
3701+
it("keeps already-collapsed text on the source passthrough", () => {
3702+
expect(collapse("<p>a b</p>")).toBe("<p>a b");
3703+
});
3704+
3705+
it("keeps whitespace verbatim under `pre`, at any depth", () => {
3706+
expect(collapse("<pre>a b</pre>")).toBe("<pre>a b</pre>");
3707+
expect(collapse("<pre><span>a b</span></pre>")).toBe(
3708+
"<pre><span>a b</span></pre>"
3709+
);
3710+
});
3711+
3712+
it("keeps text carrying a `<` on the passthrough path", () => {
3713+
expect(collapse("<p><%= x %></p>")).toBe("<p><%= x %>");
3714+
});
3715+
});
3716+
36763717
describe("parseHtml — insertion-mode edge cases", () => {
36773718
it("merges foster-parented text runs before a table", () => {
36783719
const nodes = body("<table>x<tr></tr>y</table>");

0 commit comments

Comments
 (0)