@@ -238,6 +238,23 @@ describe("hot and live reload", () => {
238
238
} ,
239
239
} ,
240
240
// TODO we still output logs from webpack, need to improve this
241
+ {
242
+ title :
243
+ "should work with manual client setup and allow to enable hot module replacement" ,
244
+ webpackOptions : {
245
+ entry : [
246
+ "webpack/hot/dev-server" ,
247
+ `${ require . resolve ( "../../client-src/index.js" ) } ?hot=true` ,
248
+ require . resolve ( "../fixtures/reload-config/foo.js" ) ,
249
+ ] ,
250
+ plugins : [ new webpack . HotModuleReplacementPlugin ( ) ] ,
251
+ } ,
252
+ options : {
253
+ client : false ,
254
+ liveReload : false ,
255
+ hot : false ,
256
+ } ,
257
+ } ,
241
258
{
242
259
title :
243
260
"should work with manual client setup and allow to disable hot module replacement" ,
@@ -253,6 +270,21 @@ describe("hot and live reload", () => {
253
270
hot : true ,
254
271
} ,
255
272
} ,
273
+ {
274
+ title :
275
+ "should work with manual client setup and allow to enable live reload" ,
276
+ webpackOptions : {
277
+ entry : [
278
+ `${ require . resolve ( "../../client-src/index.js" ) } ?live-reload=true` ,
279
+ require . resolve ( "../fixtures/reload-config/foo.js" ) ,
280
+ ] ,
281
+ } ,
282
+ options : {
283
+ client : false ,
284
+ liveReload : false ,
285
+ hot : false ,
286
+ } ,
287
+ } ,
256
288
{
257
289
title :
258
290
"should work with manual client setup and allow to disable live reload" ,
@@ -307,14 +339,6 @@ describe("hot and live reload", () => {
307
339
} ) ;
308
340
} ) ;
309
341
310
- const hot =
311
- typeof testDevServerOptions . hot !== "undefined"
312
- ? testDevServerOptions . hot
313
- : true ;
314
- const liveReload =
315
- typeof testDevServerOptions . liveReload !== "undefined"
316
- ? testDevServerOptions . liveReload
317
- : true ;
318
342
const webSocketServerLaunched =
319
343
testDevServerOptions . webSocketServer !== false ;
320
344
@@ -451,65 +475,76 @@ describe("hot and live reload", () => {
451
475
"body { background-color: rgb(255, 0, 0); }"
452
476
) ;
453
477
454
- let doNothing = false ;
478
+ let waitHot =
479
+ typeof testDevServerOptions . hot !== "undefined"
480
+ ? testDevServerOptions . hot
481
+ : true ;
482
+ let waitLiveReload =
483
+ typeof testDevServerOptions . liveReload !== "undefined"
484
+ ? testDevServerOptions . liveReload
485
+ : true ;
455
486
456
- const query = mode . query || "" ;
457
- let allowToHotModuleReplacement = true ;
487
+ if ( webSocketServerLaunched === false ) {
488
+ waitHot = false ;
489
+ waitLiveReload = false ;
490
+ }
458
491
459
- if ( query . indexOf ( "webpack-dev-server-hot=false" ) !== - 1 ) {
460
- allowToHotModuleReplacement = false ;
492
+ if ( Array . isArray ( webpackOptions . entry ) ) {
493
+ if ( webpackOptions . entry . some ( ( item ) => item . includes ( "hot=true" ) ) ) {
494
+ waitHot = true ;
495
+ } else if (
496
+ webpackOptions . entry . some ( ( item ) => item . includes ( "hot=false" ) )
497
+ ) {
498
+ waitHot = false ;
499
+ }
461
500
}
462
501
463
- if (
464
- Array . isArray ( webpackOptions . entry ) &&
465
- webpackOptions . entry . map ( ( item ) => item . includes ( "hot=false" ) )
466
- ) {
467
- allowToHotModuleReplacement = false ;
502
+ if ( Array . isArray ( webpackOptions . entry ) ) {
503
+ if (
504
+ webpackOptions . entry . some ( ( item ) => item . includes ( "live-reload=true" ) )
505
+ ) {
506
+ waitLiveReload = true ;
507
+ } else if (
508
+ webpackOptions . entry . some ( ( item ) =>
509
+ item . includes ( "live-reload=false" )
510
+ )
511
+ ) {
512
+ waitLiveReload = false ;
513
+ }
468
514
}
469
515
470
- let allowToLiveReload = true ;
516
+ const query = mode . query || "" ;
471
517
472
- if ( query . indexOf ( "webpack-dev-server-live-reload =false" ) !== - 1 ) {
473
- allowToLiveReload = false ;
518
+ if ( query . includes ( "webpack-dev-server-hot =false" ) ) {
519
+ waitHot = false ;
474
520
}
475
521
476
- if (
477
- Array . isArray ( webpackOptions . entry ) &&
478
- webpackOptions . entry . map ( ( item ) => item . includes ( "live-reload=false" ) )
479
- ) {
480
- allowToLiveReload = false ;
522
+ if ( query . includes ( "webpack-dev-server-live-reload=false" ) ) {
523
+ waitLiveReload = false ;
481
524
}
482
525
483
- if (
484
- webSocketServerLaunched &&
485
- allowToHotModuleReplacement &&
486
- ( ( hot && liveReload ) || ( hot && ! liveReload ) )
487
- ) {
526
+ if ( waitHot ) {
488
527
await page . waitForFunction (
489
528
( ) =>
490
529
getComputedStyle ( document . body ) [ "background-color" ] ===
491
530
"rgb(255, 0, 0)"
492
531
) ;
493
532
494
533
expect ( doneHotUpdate ) . toBe ( true ) ;
495
- } else if ( webSocketServerLaunched && liveReload && allowToLiveReload ) {
534
+ } else if ( waitLiveReload ) {
496
535
await page . waitForNavigation ( {
497
536
waitUntil : "networkidle0" ,
498
537
} ) ;
499
- } else {
500
- if ( webSocketServerLaunched ) {
501
- await new Promise ( ( resolve ) => {
502
- const interval = setInterval ( ( ) => {
503
- if ( consoleMessages . includes ( INVALID_MESSAGE ) ) {
504
- clearInterval ( interval ) ;
505
-
506
- resolve ( ) ;
507
- }
508
- } , 100 ) ;
509
- } ) ;
510
- }
538
+ } else if ( webSocketServerLaunched ) {
539
+ await new Promise ( ( resolve ) => {
540
+ const interval = setInterval ( ( ) => {
541
+ if ( consoleMessages . includes ( INVALID_MESSAGE ) ) {
542
+ clearInterval ( interval ) ;
511
543
512
- doNothing = true ;
544
+ resolve ( ) ;
545
+ }
546
+ } , 100 ) ;
547
+ } ) ;
513
548
}
514
549
515
550
const backgroundColorAfter = await page . evaluate ( ( ) => {
@@ -518,7 +553,7 @@ describe("hot and live reload", () => {
518
553
return getComputedStyle ( body ) [ "background-color" ] ;
519
554
} ) ;
520
555
521
- if ( doNothing ) {
556
+ if ( ! waitHot && ! waitLiveReload ) {
522
557
expect ( backgroundColorAfter ) . toEqual ( "rgb(0, 0, 255)" ) ;
523
558
} else {
524
559
expect ( backgroundColorAfter ) . toEqual ( "rgb(255, 0, 0)" ) ;
0 commit comments