-
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.
fix: make sure the module user request is set (#30)
* fix: make sure the module user request is set * test: support webpack@2 require syntax
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import fs from 'mz/fs'; | |
|
||
import test from 'ava'; | ||
import includes from 'babel-runtime/core-js/string/includes'; | ||
import webpack from 'webpack'; | ||
|
||
import DynamicCdnWebpackPlugin from '../src'; | ||
|
||
|
@@ -572,3 +573,39 @@ test('when resolver retuns a Promise', async t => { | |
const doesIncludeReact = includes(output, 'THIS IS REACT!'); | ||
t.false(doesIncludeReact); | ||
}); | ||
|
||
test('when used with NamedModulesPlugin', async t => { | ||
await cleanDir(path.resolve(__dirname, './fixtures/output/named-modules')); | ||
|
||
const stats = await runWebpack({ | ||
context: path.resolve(__dirname, './fixtures/app'), | ||
|
||
output: { | ||
publicPath: '', | ||
path: path.resolve(__dirname, './fixtures/output/named-modules') | ||
}, | ||
|
||
entry: { | ||
app: './single.js' | ||
}, | ||
|
||
plugins: [ | ||
new DynamicCdnWebpackPlugin(), | ||
new webpack.NamedModulesPlugin() | ||
] | ||
}); | ||
|
||
const files = stats.compilation.chunks.reduce((files, x) => files.concat(x.files), []); | ||
|
||
t.is(files.length, 2); | ||
t.true(includes(files, 'app.js')); | ||
t.true(includes(files, 'https://unpkg.com/[email protected]/dist/react.js')); | ||
|
||
const output = await fs.readFile(path.resolve(__dirname, './fixtures/output/named-modules/app.js')); | ||
|
||
const doesHaveIncorrectRequire = includes(output, '__webpack_require__(undefined)'); | ||
t.false(doesHaveIncorrectRequire); | ||
|
||
const doesHaveCorrectReactRequire = includes(output, '__webpack_require__("react")') || includes(output, '__webpack_require__(0)'); | ||
t.true(doesHaveCorrectReactRequire); | ||
}); |