-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stdin-option' of https://github.com/Loonride/webpack-de…
…v-server into stdin-option
- Loading branch information
Showing
4 changed files
with
234 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('Hey.'); |
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,22 @@ | ||
'use strict'; | ||
|
||
module.exports = [ | ||
{ | ||
mode: 'development', | ||
context: __dirname, | ||
entry: './foo.js', | ||
output: { | ||
path: '/', | ||
}, | ||
node: false, | ||
}, | ||
{ | ||
mode: 'development', | ||
context: __dirname, | ||
entry: './foo.js', | ||
output: { | ||
path: '/', | ||
}, | ||
node: false, | ||
}, | ||
]; |
47 changes: 47 additions & 0 deletions
47
test/server/utils/__snapshots__/updateCompiler.test.js.snap
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,47 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`updateCompiler multi compiler config, hot and inline should apply plugins 1`] = ` | ||
Array [ | ||
HotModuleReplacementPlugin { | ||
"fullBuildTimeout": 200, | ||
"multiStep": undefined, | ||
"options": Object {}, | ||
"requestTimeout": 10000, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`updateCompiler multi compiler config, hot and inline should apply plugins 2`] = ` | ||
Array [ | ||
HotModuleReplacementPlugin { | ||
"fullBuildTimeout": 200, | ||
"multiStep": undefined, | ||
"options": Object {}, | ||
"requestTimeout": 10000, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`updateCompiler simple config with HMR already, hot and inline should apply plugins 1`] = ` | ||
Array [ | ||
HotModuleReplacementPlugin { | ||
"fullBuildTimeout": 200, | ||
"multiStep": undefined, | ||
"options": Object {}, | ||
"requestTimeout": 10000, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`updateCompiler simple config, hot and inline should apply plugins 1`] = ` | ||
Array [ | ||
HotModuleReplacementPlugin { | ||
"fullBuildTimeout": 200, | ||
"multiStep": undefined, | ||
"options": Object {}, | ||
"requestTimeout": 10000, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`updateCompiler simple config, inline should apply plugins without HMR 1`] = `undefined`; |
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,162 @@ | ||
'use strict'; | ||
|
||
const webpack = require('webpack'); | ||
const updateCompiler = require('../../../lib/utils/updateCompiler'); | ||
|
||
describe('updateCompiler', () => { | ||
describe('simple config, inline', () => { | ||
let compiler; | ||
beforeAll(() => { | ||
// eslint-disable-next-line global-require | ||
const webpackConfig = require('../../fixtures/simple-config/webpack.config'); | ||
compiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should apply plugins without HMR', () => { | ||
const spy = jest.spyOn(compiler.hooks.entryOption, 'call'); | ||
|
||
updateCompiler(compiler, { | ||
serverMode: 'sockjs', | ||
clientMode: 'sockjs', | ||
inline: true, | ||
}); | ||
|
||
let tapsByHMR = 0; | ||
let tapsByProvidePlugin = 0; | ||
compiler.hooks.compilation.taps.forEach((tap) => { | ||
if (tap.name === 'HotModuleReplacementPlugin') { | ||
tapsByHMR += 1; | ||
} else if (tap.name === 'ProvidePlugin') { | ||
tapsByProvidePlugin += 1; | ||
} | ||
}); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(tapsByHMR).toEqual(0); | ||
expect(tapsByProvidePlugin).toEqual(1); | ||
// should be empty | ||
expect(compiler.options.plugins).toMatchSnapshot(); | ||
|
||
spy.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('simple config, hot and inline', () => { | ||
let compiler; | ||
beforeAll(() => { | ||
// eslint-disable-next-line global-require | ||
const webpackConfig = require('../../fixtures/simple-config/webpack.config'); | ||
compiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should apply plugins', () => { | ||
const spy = jest.spyOn(compiler.hooks.entryOption, 'call'); | ||
|
||
updateCompiler(compiler, { | ||
serverMode: 'sockjs', | ||
clientMode: 'sockjs', | ||
inline: true, | ||
hot: true, | ||
}); | ||
|
||
let tapsByHMR = 0; | ||
let tapsByProvidePlugin = 0; | ||
compiler.hooks.compilation.taps.forEach((tap) => { | ||
if (tap.name === 'HotModuleReplacementPlugin') { | ||
tapsByHMR += 1; | ||
} else if (tap.name === 'ProvidePlugin') { | ||
tapsByProvidePlugin += 1; | ||
} | ||
}); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(tapsByHMR).toEqual(1); | ||
expect(tapsByProvidePlugin).toEqual(1); | ||
expect(compiler.options.plugins).toMatchSnapshot(); | ||
|
||
spy.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('simple config with HMR already, hot and inline', () => { | ||
let compiler; | ||
beforeAll(() => { | ||
// eslint-disable-next-line global-require | ||
const webpackConfig = require('../../fixtures/simple-config/webpack.config'); | ||
webpackConfig.plugins = [new webpack.HotModuleReplacementPlugin()]; | ||
compiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should apply plugins', () => { | ||
const spy = jest.spyOn(compiler.hooks.entryOption, 'call'); | ||
|
||
updateCompiler(compiler, { | ||
serverMode: 'sockjs', | ||
clientMode: 'sockjs', | ||
inline: true, | ||
hot: true, | ||
}); | ||
|
||
let tapsByHMR = 0; | ||
let tapsByProvidePlugin = 0; | ||
compiler.hooks.compilation.taps.forEach((tap) => { | ||
if (tap.name === 'HotModuleReplacementPlugin') { | ||
tapsByHMR += 1; | ||
} else if (tap.name === 'ProvidePlugin') { | ||
tapsByProvidePlugin += 1; | ||
} | ||
}); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(tapsByHMR).toEqual(1); | ||
expect(tapsByProvidePlugin).toEqual(1); | ||
expect(compiler.options.plugins).toMatchSnapshot(); | ||
|
||
spy.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('multi compiler config, hot and inline', () => { | ||
let multiCompiler; | ||
beforeAll(() => { | ||
// eslint-disable-next-line global-require | ||
const webpackConfig = require('../../fixtures/multi-compiler-2-config/webpack.config'); | ||
webpackConfig[1].plugins = [new webpack.HotModuleReplacementPlugin()]; | ||
multiCompiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should apply plugins', () => { | ||
const spies = []; | ||
multiCompiler.compilers.forEach((compiler) => { | ||
spies.push(jest.spyOn(compiler.hooks.entryOption, 'call')); | ||
}); | ||
|
||
updateCompiler(multiCompiler, { | ||
serverMode: 'sockjs', | ||
clientMode: 'sockjs', | ||
inline: true, | ||
hot: true, | ||
}); | ||
|
||
spies.forEach((spy) => { | ||
expect(spy).toHaveBeenCalledTimes(1); | ||
spy.mockRestore(); | ||
}); | ||
|
||
multiCompiler.compilers.forEach((compiler) => { | ||
let tapsByHMR = 0; | ||
let tapsByProvidePlugin = 0; | ||
compiler.hooks.compilation.taps.forEach((tap) => { | ||
if (tap.name === 'HotModuleReplacementPlugin') { | ||
tapsByHMR += 1; | ||
} else if (tap.name === 'ProvidePlugin') { | ||
tapsByProvidePlugin += 1; | ||
} | ||
}); | ||
expect(tapsByHMR).toEqual(1); | ||
expect(tapsByProvidePlugin).toEqual(1); | ||
expect(compiler.options.plugins).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |