-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make sure lazy loading doesn't affect the CDN (#17)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import('react').then(react => { | ||
|
||
}); |