@@ -49,11 +49,16 @@ describe('renderToString', () => {
49
49
) ;
50
50
} ) ;
51
51
52
- it ( 'puts style last in the head tag' , async ( ) => {
52
+ it ( 'puts style after preconnect links in the head tag' , async ( ) => {
53
53
const { html } = await renderToString (
54
54
`<html>
55
55
<head>
56
56
<link rel="preconnect" href="https://some-url.com" />
57
+ <style>
58
+ .myComponent {
59
+ display: none;
60
+ }
61
+ </style>
57
62
</head>
58
63
59
64
<body>
@@ -72,11 +77,52 @@ describe('renderToString', () => {
72
77
{ fullDocument : true , serializeShadowRoot : false } ,
73
78
) ;
74
79
80
+ /**
81
+ * expect the scoped component styles to be injected after the preconnect link
82
+ */
75
83
expect ( html ) . toContain (
76
- '<link rel="preconnect" href="https://some-url.com"> <style sty-id="sc-scoped-car-list">.sc-scoped-car-list-h{ ' ,
84
+ '<link rel="preconnect" href="https://some-url.com"><style sty-id="sc-scoped-car-list">.sc-scoped-car-list-h' ,
77
85
) ;
78
- expect ( html ) . toContain (
79
- '.selected.sc-scoped-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style></head> <body> <div class="__next"> <main> <scoped-car-list cars' ,
86
+ /**
87
+ * expect the custom style tag to be last in the head tag
88
+ */
89
+ expect ( html . replaceAll ( / \n [ ] * / g, '' ) ) . toContain (
90
+ `.selected.sc-scoped-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style> <style>.myComponent {display: none;}</style> </head> <body>` ,
91
+ ) ;
92
+ } ) ;
93
+
94
+ it ( 'puts styles before any custom styles' , async ( ) => {
95
+ const { html } = await renderToString (
96
+ `<html>
97
+ <head>
98
+ <style>
99
+ .myComponent {
100
+ display: none;
101
+ }
102
+ </style>
103
+ </head>
104
+
105
+ <body>
106
+ <div class="__next">
107
+ <main>
108
+ <scoped-car-list cars=${ JSON . stringify ( [ vento , beetle ] ) } ></scoped-car-list>
109
+ </main>
110
+ </div>
111
+
112
+ <script type="module">
113
+ import { defineCustomElements } from "./static/loader/index.js";
114
+ defineCustomElements().catch(console.error);
115
+ </script>
116
+ </body>
117
+ </html>` ,
118
+ { fullDocument : true , serializeShadowRoot : false } ,
119
+ ) ;
120
+
121
+ /**
122
+ * expect the scoped component styles to be injected before custom styles
123
+ */
124
+ expect ( html . replaceAll ( / \n [ ] * / g, '' ) ) . toContain (
125
+ '.selected.sc-scoped-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style><style class="vjs-styles-defaults">.video-js {width: 300px;height: 150px;}.vjs-fluid {padding-top: 56.25%}</style> <style>.myComponent {display: none;}</style> </head>' ,
80
126
) ;
81
127
} ) ;
82
128
@@ -109,8 +155,8 @@ describe('renderToString', () => {
109
155
/**
110
156
* renders hydration styles and custom link tag within the head tag
111
157
*/
112
- expect ( html ) . toContain (
113
- '<link rel="stylesheet" href="whatever.css"> <style sty-id="sc-scoped-car-list">.sc-scoped-car-list-h{display:block;margin:10px;padding:10px;border:1px solid blue}ul.sc-scoped-car-list{display:block;margin:0;padding:0}li.sc-scoped-car-list{list-style:none;margin:0;padding:20px}.selected.sc-scoped-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style></head> <body > <div class="__next"> <main > <scoped-car-list cars= ' ,
158
+ expect ( html . replaceAll ( / \n [ ] * / g , '' ) ) . toContain (
159
+ '<head><meta charset="utf-8"> <style sty-id="sc-scoped-car-list">.sc-scoped-car-list-h{display:block;margin:10px;padding:10px;border:1px solid blue}ul.sc-scoped-car-list{display:block;margin:0;padding:0}li.sc-scoped-car-list{list-style:none;margin:0;padding:20px}.selected.sc-scoped-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style><style class="vjs-styles-defaults">.video-js {width: 300px;height: 150px;}.vjs-fluid {padding-top: 56.25%}</style > <link rel="stylesheet" href="whatever.css" > </head> ' ,
114
160
) ;
115
161
} ) ;
116
162
} ) ;
0 commit comments