Skip to content

Commit

Permalink
test: make sure lazy loading doesn't affect the CDN (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver authored Jul 19, 2017
1 parent 0352c09 commit 4ebe078
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,37 @@ test('require files without extension', async t => {
t.true(includes(files, 'app.js'));
t.false(includes(files, 'https://unpkg.com/[email protected]/dist/react.js'));
});

test('async loading', async t => {
await cleanDir(path.resolve(__dirname, './fixtures/output/async'));

const stats = await runWebpack({
context: path.resolve(__dirname, './fixtures/app'),

output: {
publicPath: '',
path: path.resolve(__dirname, './fixtures/output/async')
},

entry: {
app: './async.js'
},

plugins: [
new ModulesCdnWebpackPlugin()
]
});

const files = stats.compilation.chunks.reduce((files, x) => files.concat(x.files), []);

t.true(includes(files, 'app.js'));
t.true(includes(files, 'https://unpkg.com/[email protected]/dist/react.js'));

const outputs = await Promise.all(files.filter(x => !x.startsWith('https://unpkg.com')).map(async file => {
return fs.readFile(path.resolve(__dirname, `./fixtures/output/async/${file}`));
}));

// NOTE: not inside t.false to prevent ava to display whole file in console
const doesIncludeReact = outputs.some(output => includes(output, 'THIS IS REACT!'));
t.false(doesIncludeReact);
});
3 changes: 3 additions & 0 deletions test/fixtures/app/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import('react').then(react => {

});

0 comments on commit 4ebe078

Please sign in to comment.