Skip to content

Commit 049343f

Browse files
committed
adding a test to prove shared entry code is not double-included
1 parent bdf201a commit 049343f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

fixtures/js/append_to_app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.getElementById('app').innerHTML = document.getElementById('app').innerHTML + 'Welcome to Encore!';

test/functional.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,37 @@ describe('Functional tests using webpack', function() {
660660
});
661661
});
662662

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+
663694
it('in production mode, code is uglified', (done) => {
664695
const config = createWebpackConfig('www/build', 'production');
665696
config.setPublicPath('/build');

0 commit comments

Comments
 (0)