@@ -531,20 +531,26 @@ describe('Server', () => {
531
531
532
532
function writeToDisk ( value , done ) {
533
533
app = express ( ) ;
534
+
534
535
const compiler = webpack ( webpackConfig ) ;
536
+
535
537
instance = middleware ( compiler , {
536
538
stats : 'errors-only' ,
537
539
logLevel,
538
540
writeToDisk : value ,
539
541
} ) ;
542
+
540
543
app . use ( instance ) ;
541
544
app . use ( ( req , res ) => {
542
545
res . sendStatus ( 200 ) ;
543
546
} ) ;
547
+
544
548
listen = listenShorthand ( done ) ;
549
+
550
+ return { compiler, instance } ;
545
551
}
546
552
547
- describe ( 'write to disk' , ( ) => {
553
+ describe ( 'write to disk with true ' , ( ) => {
548
554
beforeAll ( ( done ) => {
549
555
writeToDisk ( true , done ) ;
550
556
} ) ;
@@ -568,6 +574,28 @@ describe('Server', () => {
568
574
} ) ;
569
575
} ) ;
570
576
577
+ describe ( 'write to disk with false' , ( ) => {
578
+ beforeAll ( ( done ) => {
579
+ writeToDisk ( false , done ) ;
580
+ } ) ;
581
+ afterAll ( close ) ;
582
+
583
+ it ( 'should not find the bundle file on disk' , ( done ) => {
584
+ request ( app )
585
+ . get ( '/foo/bar' )
586
+ . expect ( 200 , ( ) => {
587
+ const bundlePath = path . join (
588
+ __dirname ,
589
+ './fixtures/server-test/bundle.js'
590
+ ) ;
591
+
592
+ expect ( fs . existsSync ( bundlePath ) ) . toBe ( false ) ;
593
+
594
+ done ( ) ;
595
+ } ) ;
596
+ } ) ;
597
+ } ) ;
598
+
571
599
describe ( 'write to disk with filter' , ( ) => {
572
600
beforeAll ( ( done ) => {
573
601
writeToDisk ( ( filePath ) => / b u n d l e \. j s $ / . test ( filePath ) , done ) ;
@@ -705,4 +733,84 @@ describe('Server', () => {
705
733
} ) ;
706
734
} ) ;
707
735
} ) ;
736
+
737
+ describe ( 'write to disk with true hooks' , ( ) => {
738
+ let compiler = null ;
739
+
740
+ beforeAll ( ( done ) => {
741
+ ( { compiler, instance } = writeToDisk ( true , done ) ) ;
742
+ } ) ;
743
+ afterAll ( close ) ;
744
+
745
+ it ( 'should not find the bundle file on disk' , ( done ) => {
746
+ request ( app )
747
+ . get ( '/foo/bar' )
748
+ . expect ( 200 , ( ) => {
749
+ const bundlePath = path . join (
750
+ __dirname ,
751
+ './fixtures/server-test/bundle.js'
752
+ ) ;
753
+
754
+ expect (
755
+ compiler . hooks . assetEmitted . taps . filter (
756
+ ( hook ) => hook . name === 'WebpackDevMiddleware'
757
+ ) . length
758
+ ) . toBe ( 1 ) ;
759
+ expect ( fs . existsSync ( bundlePath ) ) . toBe ( true ) ;
760
+
761
+ fs . unlinkSync ( bundlePath ) ;
762
+
763
+ instance . invalidate ( ) ;
764
+
765
+ compiler . hooks . done . tap ( 'WebpackDevMiddlewareWriteToDiskTest' , ( ) => {
766
+ expect (
767
+ compiler . hooks . assetEmitted . taps . filter (
768
+ ( hook ) => hook . name === 'WebpackDevMiddleware'
769
+ ) . length
770
+ ) . toBe ( 1 ) ;
771
+
772
+ done ( ) ;
773
+ } ) ;
774
+ } ) ;
775
+ } ) ;
776
+ } ) ;
777
+
778
+ describe ( 'write to disk with false hooks' , ( ) => {
779
+ let compiler = null ;
780
+
781
+ beforeAll ( ( done ) => {
782
+ ( { compiler } = writeToDisk ( false , done ) ) ;
783
+ } ) ;
784
+ afterAll ( close ) ;
785
+
786
+ it ( 'should not find the bundle file on disk' , ( done ) => {
787
+ request ( app )
788
+ . get ( '/foo/bar' )
789
+ . expect ( 200 , ( ) => {
790
+ const bundlePath = path . join (
791
+ __dirname ,
792
+ './fixtures/server-test/bundle.js'
793
+ ) ;
794
+
795
+ expect (
796
+ compiler . hooks . assetEmitted . taps . filter (
797
+ ( hook ) => hook . name === 'WebpackDevMiddleware'
798
+ ) . length
799
+ ) . toBe ( 0 ) ;
800
+ expect ( fs . existsSync ( bundlePath ) ) . toBe ( false ) ;
801
+
802
+ instance . invalidate ( ) ;
803
+
804
+ compiler . hooks . done . tap ( 'WebpackDevMiddlewareWriteToDiskTest' , ( ) => {
805
+ expect (
806
+ compiler . hooks . assetEmitted . taps . filter (
807
+ ( hook ) => hook . name === 'WebpackDevMiddleware'
808
+ ) . length
809
+ ) . toBe ( 0 ) ;
810
+
811
+ done ( ) ;
812
+ } ) ;
813
+ } ) ;
814
+ } ) ;
815
+ } ) ;
708
816
} ) ;
0 commit comments