@@ -8,7 +8,6 @@ const path = require("path");
8
8
const WebSocket = require ( "ws" ) ;
9
9
const SockJS = require ( "sockjs-client" ) ;
10
10
const webpack = require ( "webpack" ) ;
11
- const request = require ( "supertest" ) ;
12
11
const fs = require ( "graceful-fs" ) ;
13
12
const Server = require ( "../../lib/Server" ) ;
14
13
const reloadConfig = require ( "../fixtures/reload-config/webpack.config" ) ;
@@ -302,42 +301,44 @@ describe("hot and live reload", () => {
302
301
} ,
303
302
] ;
304
303
304
+ let browser ;
305
+ let server ;
306
+
307
+ beforeEach ( ( ) => {
308
+ fs . writeFileSync ( cssFilePath , "body { background-color: rgb(0, 0, 255); }" ) ;
309
+ } ) ;
310
+
311
+ afterEach ( async ( ) => {
312
+ if ( browser ) {
313
+ await browser . close ( ) ;
314
+ }
315
+
316
+ if ( server ) {
317
+ await server . stop ( ) ;
318
+ }
319
+
320
+ fs . unlinkSync ( cssFilePath ) ;
321
+ } ) ;
322
+
305
323
modes . forEach ( ( mode ) => {
306
324
const webSocketServerTitle =
307
325
mode . options && mode . options . webSocketServer
308
326
? mode . options . webSocketServer
309
327
: "default" ;
310
328
311
329
it ( `${ mode . title } (${ webSocketServerTitle } )` , async ( ) => {
312
- fs . writeFileSync (
313
- cssFilePath ,
314
- "body { background-color: rgb(0, 0, 255); }"
315
- ) ;
316
-
317
- const webpackOptions = { ...reloadConfig , ...mode . webpackOptions } ;
330
+ const webpackOptions = {
331
+ ...reloadConfig ,
332
+ ...mode . webpackOptions ,
333
+ watchOptions : { aggregateTimeout : 2000 } ,
334
+ } ;
318
335
const compiler = webpack ( webpackOptions ) ;
319
336
const testDevServerOptions = mode . options || { } ;
320
- const devServerOptions = {
321
- port,
322
- ...testDevServerOptions ,
323
- } ;
324
- const server = new Server ( devServerOptions , compiler ) ;
325
-
326
- await server . start ( ) ;
337
+ const devServerOptions = { port, ...testDevServerOptions } ;
327
338
328
- await new Promise ( ( resolve , reject ) => {
329
- request ( `http://127.0.0.1:${ devServerOptions . port } ` )
330
- . get ( "/main" )
331
- . expect ( 200 , ( error ) => {
332
- if ( error ) {
333
- reject ( error ) ;
339
+ server = new Server ( devServerOptions , compiler ) ;
334
340
335
- return ;
336
- }
337
-
338
- resolve ( ) ;
339
- } ) ;
340
- } ) ;
341
+ await server . start ( ) ;
341
342
342
343
const webSocketServerLaunched =
343
344
testDevServerOptions . webSocketServer !== false ;
@@ -432,7 +433,11 @@ describe("hot and live reload", () => {
432
433
}
433
434
} ) ;
434
435
435
- const { page, browser } = await runBrowser ( ) ;
436
+ const launched = await runBrowser ( ) ;
437
+
438
+ ( { browser } = launched ) ;
439
+
440
+ const page = launched . page ;
436
441
437
442
const consoleMessages = [ ] ;
438
443
const pageErrors = [ ] ;
@@ -561,11 +566,6 @@ describe("hot and live reload", () => {
561
566
562
567
expect ( consoleMessages ) . toMatchSnapshot ( "console messages" ) ;
563
568
expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
564
-
565
- fs . unlinkSync ( cssFilePath ) ;
566
-
567
- await browser . close ( ) ;
568
- await server . stop ( ) ;
569
569
} ) ;
570
570
} ) ;
571
571
} ) ;
0 commit comments