@@ -90,29 +90,33 @@ describe("host", () => {
90
90
91
91
const { page, browser } = await runBrowser ( ) ;
92
92
93
- const pageErrors = [ ] ;
94
- const consoleMessages = [ ] ;
95
-
96
- page
97
- . on ( "console" , ( message ) => {
98
- consoleMessages . push ( message ) ;
99
- } )
100
- . on ( "pageerror" , ( error ) => {
101
- pageErrors . push ( error ) ;
93
+ try {
94
+ const pageErrors = [ ] ;
95
+ const consoleMessages = [ ] ;
96
+
97
+ page
98
+ . on ( "console" , ( message ) => {
99
+ consoleMessages . push ( message ) ;
100
+ } )
101
+ . on ( "pageerror" , ( error ) => {
102
+ pageErrors . push ( error ) ;
103
+ } ) ;
104
+
105
+ await page . goto ( `http://${ hostname } :${ port } /` , {
106
+ waitUntil : "networkidle0" ,
102
107
} ) ;
103
108
104
- await page . goto ( `http:// ${ hostname } : ${ port } /` , {
105
- waitUntil : "networkidle0" ,
106
- } ) ;
109
+ expect (
110
+ consoleMessages . map ( ( message ) => message . text ( ) )
111
+ ) . toMatchSnapshot ( "console messages" ) ;
107
112
108
- expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
109
- "console messages"
110
- ) ;
111
-
112
- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
113
-
114
- await browser . close ( ) ;
115
- await server . stop ( ) ;
113
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
114
+ } catch ( error ) {
115
+ throw error ;
116
+ } finally {
117
+ await browser . close ( ) ;
118
+ await server . stop ( ) ;
119
+ }
116
120
} ) ;
117
121
118
122
it ( `should work using "${ host } " host and port as string` , async ( ) => {
@@ -159,29 +163,33 @@ describe("host", () => {
159
163
160
164
const { page, browser } = await runBrowser ( ) ;
161
165
162
- const pageErrors = [ ] ;
163
- const consoleMessages = [ ] ;
166
+ try {
167
+ const pageErrors = [ ] ;
168
+ const consoleMessages = [ ] ;
164
169
165
- page
166
- . on ( "console" , ( message ) => {
167
- consoleMessages . push ( message ) ;
168
- } )
169
- . on ( "pageerror" , ( error ) => {
170
- pageErrors . push ( error ) ;
171
- } ) ;
172
-
173
- await page . goto ( `http://${ hostname } :${ port } /` , {
174
- waitUntil : "networkidle0" ,
175
- } ) ;
170
+ page
171
+ . on ( "console" , ( message ) => {
172
+ consoleMessages . push ( message ) ;
173
+ } )
174
+ . on ( "pageerror" , ( error ) => {
175
+ pageErrors . push ( error ) ;
176
+ } ) ;
176
177
177
- expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
178
- "console messages"
179
- ) ;
178
+ await page . goto ( `http:// ${ hostname } : ${ port } /` , {
179
+ waitUntil : "networkidle0" ,
180
+ } ) ;
180
181
181
- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
182
+ expect (
183
+ consoleMessages . map ( ( message ) => message . text ( ) )
184
+ ) . toMatchSnapshot ( "console messages" ) ;
182
185
183
- await browser . close ( ) ;
184
- await server . stop ( ) ;
186
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
187
+ } catch ( error ) {
188
+ throw error ;
189
+ } finally {
190
+ await browser . close ( ) ;
191
+ await server . stop ( ) ;
192
+ }
185
193
} ) ;
186
194
187
195
it ( `should work using "${ host } " host and "auto" port` , async ( ) => {
@@ -231,31 +239,35 @@ describe("host", () => {
231
239
const address = server . server . address ( ) ;
232
240
const { page, browser } = await runBrowser ( ) ;
233
241
234
- const pageErrors = [ ] ;
235
- const consoleMessages = [ ] ;
236
-
237
- page
238
- . on ( "console" , ( message ) => {
239
- consoleMessages . push ( message ) ;
240
- } )
241
- . on ( "pageerror" , ( error ) => {
242
- pageErrors . push ( error ) ;
243
- } ) ;
242
+ try {
243
+ const pageErrors = [ ] ;
244
+ const consoleMessages = [ ] ;
244
245
245
- await page . goto ( `http://${ hostname } :${ address . port } /` , {
246
- waitUntil : "networkidle0" ,
247
- } ) ;
246
+ page
247
+ . on ( "console" , ( message ) => {
248
+ consoleMessages . push ( message ) ;
249
+ } )
250
+ . on ( "pageerror" , ( error ) => {
251
+ pageErrors . push ( error ) ;
252
+ } ) ;
248
253
249
- expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
250
- "console messages"
251
- ) ;
254
+ await page . goto ( `http:// ${ hostname } : ${ address . port } /` , {
255
+ waitUntil : "networkidle0" ,
256
+ } ) ;
252
257
253
- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
258
+ expect (
259
+ consoleMessages . map ( ( message ) => message . text ( ) )
260
+ ) . toMatchSnapshot ( "console messages" ) ;
254
261
255
- delete process . env . WEBPACK_DEV_SERVER_BASE_PORT ;
262
+ expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
263
+ } catch ( error ) {
264
+ throw error ;
265
+ } finally {
266
+ delete process . env . WEBPACK_DEV_SERVER_BASE_PORT ;
256
267
257
- await browser . close ( ) ;
258
- await server . stop ( ) ;
268
+ await browser . close ( ) ;
269
+ await server . stop ( ) ;
270
+ }
259
271
} ) ;
260
272
}
261
273
0 commit comments