@@ -37,6 +37,7 @@ describe("cross-origin requests", () => {
37
37
htmlServer . listen ( htmlServerPort , htmlServerHost ) ;
38
38
39
39
const { page, browser } = await runBrowser ( ) ;
40
+
40
41
try {
41
42
const pageErrors = [ ] ;
42
43
@@ -91,6 +92,111 @@ describe("cross-origin requests", () => {
91
92
htmlServer . listen ( htmlServerPort , htmlServerHost ) ;
92
93
93
94
const { page, browser } = await runBrowser ( ) ;
95
+
96
+ try {
97
+ const pageErrors = [ ] ;
98
+
99
+ page . on ( "pageerror" , ( error ) => {
100
+ pageErrors . push ( error ) ;
101
+ } ) ;
102
+
103
+ const scriptTagRequest = page . waitForResponse (
104
+ `http://localhost:${ devServerPort } /main.js` ,
105
+ ) ;
106
+
107
+ await page . goto ( `http://${ htmlServerHost } :${ htmlServerPort } ` ) ;
108
+
109
+ const response = await scriptTagRequest ;
110
+
111
+ expect ( response . status ( ) ) . toBe ( 200 ) ;
112
+ } catch ( error ) {
113
+ throw error ;
114
+ } finally {
115
+ await browser . close ( ) ;
116
+ await server . stop ( ) ;
117
+ htmlServer . close ( ) ;
118
+ }
119
+ } ) ;
120
+
121
+ it ( "should return 200 for cross-origin no-cors non-module script tag requests with the 'allowedHost' option and 'all' value" , async ( ) => {
122
+ const compiler = webpack ( config ) ;
123
+ const devServerOptions = {
124
+ port : devServerPort ,
125
+ allowedHosts : "all" ,
126
+ } ;
127
+ const server = new Server ( devServerOptions , compiler ) ;
128
+
129
+ await server . start ( ) ;
130
+
131
+ // Start a separate server for serving the HTML file
132
+ const http = require ( "http" ) ;
133
+ const htmlServer = http . createServer ( ( req , res ) => {
134
+ res . writeHead ( 200 , { "Content-Type" : "text/html" } ) ;
135
+ res . end ( `
136
+ <html>
137
+ <head>
138
+ <script src="http://localhost:${ devServerPort } /main.js"></script>
139
+ </head>
140
+ <body></body>
141
+ </html>
142
+ ` ) ;
143
+ } ) ;
144
+ htmlServer . listen ( htmlServerPort , htmlServerHost ) ;
145
+
146
+ const { page, browser } = await runBrowser ( ) ;
147
+
148
+ try {
149
+ const pageErrors = [ ] ;
150
+
151
+ page . on ( "pageerror" , ( error ) => {
152
+ pageErrors . push ( error ) ;
153
+ } ) ;
154
+
155
+ const scriptTagRequest = page . waitForResponse (
156
+ `http://localhost:${ devServerPort } /main.js` ,
157
+ ) ;
158
+
159
+ await page . goto ( `http://${ htmlServerHost } :${ htmlServerPort } ` ) ;
160
+
161
+ const response = await scriptTagRequest ;
162
+
163
+ expect ( response . status ( ) ) . toBe ( 200 ) ;
164
+ } catch ( error ) {
165
+ throw error ;
166
+ } finally {
167
+ await browser . close ( ) ;
168
+ await server . stop ( ) ;
169
+ htmlServer . close ( ) ;
170
+ }
171
+ } ) ;
172
+
173
+ it ( "should return 200 for cross-origin no-cors non-module script tag requests with the `allowedHost` option and the `localhost` value" , async ( ) => {
174
+ const compiler = webpack ( config ) ;
175
+ const devServerOptions = {
176
+ port : devServerPort ,
177
+ allowedHosts : [ "localhost" ] ,
178
+ } ;
179
+ const server = new Server ( devServerOptions , compiler ) ;
180
+
181
+ await server . start ( ) ;
182
+
183
+ // Start a separate server for serving the HTML file
184
+ const http = require ( "http" ) ;
185
+ const htmlServer = http . createServer ( ( req , res ) => {
186
+ res . writeHead ( 200 , { "Content-Type" : "text/html" } ) ;
187
+ res . end ( `
188
+ <html>
189
+ <head>
190
+ <script src="http://localhost:${ devServerPort } /main.js"></script>
191
+ </head>
192
+ <body></body>
193
+ </html>
194
+ ` ) ;
195
+ } ) ;
196
+ htmlServer . listen ( htmlServerPort , htmlServerHost ) ;
197
+
198
+ const { page, browser } = await runBrowser ( ) ;
199
+
94
200
try {
95
201
const pageErrors = [ ] ;
96
202
0 commit comments