@@ -660,6 +660,37 @@ describe('Functional tests using webpack', function() {
660
660
} ) ;
661
661
} ) ;
662
662
663
+ it ( 'createdSharedEntry() does not run shared code twice' , ( done ) => {
664
+ const config = createWebpackConfig ( 'www/build' , 'dev' ) ;
665
+ config . setPublicPath ( '/build' ) ;
666
+ config . addEntry ( 'main' , [ './js/no_require' , './js/code_splitting' , './js/arrow_function' , './js/print_to_app' ] ) ;
667
+ config . addEntry ( 'other' , [ './js/no_require' , './css/h1_style.css' ] ) ;
668
+ // in this situation, we create a shared entry that contains zero shared code
669
+ // in practice (for some reason) this causes SplitChunksPlugin to NOT
670
+ // remove the "shared" entry, which, in theory, our hack would cause
671
+ // the code to be executed twice. However, in practice, thanks to our
672
+ // hack (the addition of the fake entry file), suddenly the shared
673
+ // entry DOES have chunks that should be split, and the "shared" entry
674
+ // is removed, like in all other situations. This test proves that this
675
+ // guarantees the code is not executed twice.
676
+ config . createSharedEntry ( 'shared' , './js/append_to_app' ) ;
677
+
678
+ testSetup . runWebpack ( config , ( webpackAssert ) => {
679
+ testSetup . requestTestPage (
680
+ path . join ( config . getContext ( ) , 'www' ) ,
681
+ [
682
+ 'build/runtime.js' ,
683
+ 'build/shared.js' ,
684
+ ] ,
685
+ ( browser ) => {
686
+ // assert JS code is executed, ONLY once
687
+ browser . assert . text ( '#app' , 'Welcome to Encore!' ) ;
688
+ done ( ) ;
689
+ }
690
+ ) ;
691
+ } ) ;
692
+ } ) ;
693
+
663
694
it ( 'in production mode, code is uglified' , ( done ) => {
664
695
const config = createWebpackConfig ( 'www/build' , 'production' ) ;
665
696
config . setPublicPath ( '/build' ) ;
0 commit comments