Skip to content

Commit 377d164

Browse files
test(html): assert <link> precedes <script> for JS-imported CSS
Reinforce the html-webpack-plugin#1813 invariant in the css-imported-from-js case: a <link rel=stylesheet> emitted for a CSS chunk pulled in by a <script src> entry must precede the <script> tag itself, so browsers start the stylesheet download before the script download. The snapshot already captures the order; the explicit assertion documents the requirement and matches the pattern used by the sibling tests (css-split-chunks-order, css-mixed-link-and-js-import, css-runtime-and-split-chunks).
1 parent 6c5f2f8 commit 377d164

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

  • test/configCases/html/css-imported-from-js

test/configCases/html/css-imported-from-js/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ it("should emit a <link rel=stylesheet> for the entry chunk's CSS file, copying
4040
expect(linkTag).not.toContain("defer");
4141
expect(linkTag).not.toContain("integrity");
4242

43+
// The `<link>` must precede the `<script>` so the browser starts the
44+
// stylesheet download before the script download — otherwise scripts
45+
// race ahead and the stylesheet's render-blocking arrival is pushed
46+
// out (the html-webpack-plugin#1813 concern, applied to JS-imported
47+
// CSS in HTML entries).
48+
const scriptIdx = extracted.indexOf("<script");
49+
const linkIdx = extracted.indexOf('<link rel="stylesheet"');
50+
expect(linkIdx).toBeGreaterThan(-1);
51+
expect(linkIdx).toBeLessThan(scriptIdx);
52+
4353
// The referenced files actually exist on disk.
4454
expect(() => readFile(scriptMatch[1])).not.toThrow();
4555
const css = readFile(hrefMatch[1]);

0 commit comments

Comments
 (0)