diff --git a/lib/utils/DevServerPlugin.js b/lib/utils/DevServerPlugin.js index 312e3a449e..406c168b8a 100644 --- a/lib/utils/DevServerPlugin.js +++ b/lib/utils/DevServerPlugin.js @@ -37,6 +37,7 @@ class DevServerPlugin { : ''; /** @type {string} */ let path = ''; + // only add the path if it is not default if ( options.client && @@ -45,11 +46,13 @@ class DevServerPlugin { ) { path = `&path=${options.client.path}`; } + /** @type {string} */ const port = options.client && options.client.port ? `&port=${options.client.port}` : ''; + /** @type {string} */ const clientEntry = `${require.resolve( '../../client/default/' @@ -119,14 +122,22 @@ class DevServerPlugin { */ // eslint-disable-next-line no-shadow const checkInject = (option, _config, defaultValue) => { - if (typeof option === 'boolean') return option; - if (typeof option === 'function') return option(_config); + if (typeof option === 'boolean') { + return option; + } + + if (typeof option === 'function') { + return option(_config); + } + return defaultValue; }; const compilerOptions = compiler.options; + compilerOptions.plugins = compilerOptions.plugins || []; - /** @type {Boolean} */ + + /** @type {boolean} */ const isWebTarget = compilerOptions.externalsPresets ? compilerOptions.externalsPresets.web : [ @@ -138,6 +149,7 @@ class DevServerPlugin { undefined, null, ].includes(compilerOptions.target); + /** @type {Entry} */ const additionalEntries = checkInject( options.injectClient, @@ -153,24 +165,12 @@ class DevServerPlugin { // use a hook to add entries if available if (EntryPlugin) { - compiler.hooks.make.tapPromise('DevServerPlugin', (compilation) => - Promise.all( - additionalEntries.map( - (entry) => - new Promise((resolve, reject) => { - compilation.addEntry( - compiler.context, - EntryPlugin.createDependency(entry, {}), - {}, // global entry - (err) => { - if (err) return reject(err); - resolve(); - } - ); - }) - ) - ) - ); + for (const additionalEntry of additionalEntries) { + new EntryPlugin(compiler.context, additionalEntry, { + // eslint-disable-next-line no-undefined + name: undefined, + }).apply(compiler); + } } else { compilerOptions.entry = prependEntry( compilerOptions.entry || './src', @@ -185,6 +185,7 @@ class DevServerPlugin { const providePlugin = new webpack.ProvidePlugin({ __webpack_dev_server_client__: getSocketClientPath(options), }); + providePlugin.apply(compiler); if ( @@ -195,6 +196,7 @@ class DevServerPlugin { ) { // apply the HMR plugin, if it didn't exist before. const plugin = new webpack.HotModuleReplacementPlugin(); + plugin.apply(compiler); } } diff --git a/lib/utils/updateCompiler.js b/lib/utils/updateCompiler.js index a2b4e8f712..db77355950 100644 --- a/lib/utils/updateCompiler.js +++ b/lib/utils/updateCompiler.js @@ -4,6 +4,7 @@ const DevServerPlugin = require('./DevServerPlugin'); function updateCompiler(compiler, options) { const compilers = compiler.compilers || [compiler]; + // eslint-disable-next-line no-shadow compilers.forEach((compiler) => { new DevServerPlugin(options).apply(compiler); diff --git a/test/e2e/DevServer.test.js b/test/e2e/DevServer.test.js new file mode 100644 index 0000000000..aef36fb1cd --- /dev/null +++ b/test/e2e/DevServer.test.js @@ -0,0 +1,114 @@ +'use strict'; + +const testBin = require('../helpers/test-bin'); +const isWebpack5 = require('../helpers/isWebpack5'); + +describe('DevServer', () => { + const webpack5Test = isWebpack5 ? it : it.skip; + + it('should add devServer entry points to a single entry point', (done) => { + testBin('--config ./test/fixtures/dev-server/default-config.js') + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('client/default/index.js?'); + done(); + }) + .catch(done); + }); + + it('should add devServer entry points to a multi entry point object', (done) => { + testBin( + '--config ./test/fixtures/dev-server/multi-entry.js --stats=verbose' + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('client/default/index.js?'); + expect(output.stderr).toContain('foo.js'); + done(); + }) + .catch(done); + }); + + webpack5Test('should supports entry as descriptor', (done) => { + testBin( + '--config ./test/fixtures/entry-as-descriptor/webpack.config --stats detailed' + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('foo.js'); + done(); + }) + .catch(done); + }); + + it('should only prepends devServer entry points to "web" target', (done) => { + testBin( + '--config ./test/fixtures/dev-server/default-config.js --target web' + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('client/default/index.js?'); + expect(output.stderr).toContain('foo.js'); + done(); + }) + .catch(done); + }); + + it('should not prepend devServer entry points to "node" target', (done) => { + testBin( + '--config ./test/fixtures/dev-server/default-config.js --target node' + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).not.toContain('client/default/index.js?'); + expect(output.stderr).toContain('foo.js'); + done(); + }) + .catch(done); + }); + + it('should prepends the hot runtime to "node" target as well', (done) => { + testBin( + '--config ./test/fixtures/dev-server/default-config.js --target node --hot' + ) + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('webpack/hot/dev-server'); + done(); + }) + .catch(done); + }); + + it('does not use client.path when default', (done) => { + testBin('--config ./test/fixtures/dev-server/client-default-path-config.js') + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).not.toContain('&path=/ws'); + done(); + }) + .catch(done); + }); + + it('should use client.path when custom', (done) => { + testBin('--config ./test/fixtures/dev-server/client-custom-path-config.js') + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('&path=/custom/path'); + done(); + }) + .catch(done); + }); + + webpack5Test( + 'should prepend devServer entry points depending on targetProperties', + (done) => { + testBin('--config ./test/fixtures/dev-server/target-config.js') + .then((output) => { + expect(output.exitCode).toEqual(0); + expect(output.stderr).toContain('client/default/index.js'); + done(); + }) + .catch(done); + } + ); +}); diff --git a/test/fixtures/dev-server/bar.js b/test/fixtures/dev-server/bar.js new file mode 100644 index 0000000000..22bcef09f7 --- /dev/null +++ b/test/fixtures/dev-server/bar.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('I am bar'); diff --git a/test/fixtures/dev-server/client-custom-path-config.js b/test/fixtures/dev-server/client-custom-path-config.js new file mode 100644 index 0000000000..300ef62d86 --- /dev/null +++ b/test/fixtures/dev-server/client-custom-path-config.js @@ -0,0 +1,18 @@ +'use strict'; + +const { resolve } = require('path'); + +module.exports = { + mode: 'development', + stats: 'detailed', + entry: resolve(__dirname, './foo.js'), + devServer: { + client: { + path: '/custom/path', + }, + transportMode: { + server: 'sockjs', + client: 'sockjs', + }, + }, +}; diff --git a/test/fixtures/dev-server/client-default-path-config.js b/test/fixtures/dev-server/client-default-path-config.js new file mode 100644 index 0000000000..d36d7aff85 --- /dev/null +++ b/test/fixtures/dev-server/client-default-path-config.js @@ -0,0 +1,18 @@ +'use strict'; + +const { resolve } = require('path'); + +module.exports = { + mode: 'development', + stats: 'detailed', + entry: resolve(__dirname, './foo.js'), + devServer: { + client: { + path: '/ws', + }, + transportMode: { + server: 'sockjs', + client: 'sockjs', + }, + }, +}; diff --git a/test/fixtures/dev-server/default-config.js b/test/fixtures/dev-server/default-config.js new file mode 100644 index 0000000000..300ef62d86 --- /dev/null +++ b/test/fixtures/dev-server/default-config.js @@ -0,0 +1,18 @@ +'use strict'; + +const { resolve } = require('path'); + +module.exports = { + mode: 'development', + stats: 'detailed', + entry: resolve(__dirname, './foo.js'), + devServer: { + client: { + path: '/custom/path', + }, + transportMode: { + server: 'sockjs', + client: 'sockjs', + }, + }, +}; diff --git a/test/fixtures/dev-server/foo.js b/test/fixtures/dev-server/foo.js new file mode 100644 index 0000000000..051a2d2c21 --- /dev/null +++ b/test/fixtures/dev-server/foo.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log('I am foo'); diff --git a/test/fixtures/dev-server/multi-entry.js b/test/fixtures/dev-server/multi-entry.js new file mode 100644 index 0000000000..20b7e08c16 --- /dev/null +++ b/test/fixtures/dev-server/multi-entry.js @@ -0,0 +1,19 @@ +'use strict'; + +const { resolve } = require('path'); + +module.exports = { + mode: 'development', + stats: 'detailed', + context: __dirname, + entry: { + foo: resolve(__dirname, './foo.js'), + bar: resolve(__dirname, './bar.js'), + }, + devServer: { + transportMode: { + server: 'sockjs', + client: 'sockjs', + }, + }, +}; diff --git a/test/fixtures/dev-server/target-config.js b/test/fixtures/dev-server/target-config.js new file mode 100644 index 0000000000..8f1567286a --- /dev/null +++ b/test/fixtures/dev-server/target-config.js @@ -0,0 +1,24 @@ +'use strict'; + +const { resolve } = require('path'); + +module.exports = { + mode: 'development', + stats: 'detailed', + entry: resolve(__dirname, './foo.js'), + target: ['web', 'webworker'], + output: { + chunkLoading: false, + wasmLoading: false, + workerChunkLoading: false, + }, + devServer: { + client: { + path: '/custom/path', + }, + transportMode: { + server: 'sockjs', + client: 'sockjs', + }, + }, +}; diff --git a/test/server/utils/DevServerPlugin.test.js b/test/server/utils/DevServerPlugin.test.js index b7de5cc00b..723ee1b029 100644 --- a/test/server/utils/DevServerPlugin.test.js +++ b/test/server/utils/DevServerPlugin.test.js @@ -6,7 +6,6 @@ const DevServerPlugin = require('../../../lib/utils/DevServerPlugin'); const isWebpack5 = require('../../helpers/isWebpack5'); const config = require('../../fixtures/simple-config/webpack.config'); const configEntryAsFunction = require('../../fixtures/entry-as-function/webpack.config'); -const configEntryAsDescriptor = require('../../fixtures/entry-as-descriptor/webpack.config'); const normalize = (entry) => entry.split(path.sep).join('/'); @@ -45,147 +44,6 @@ describe('DevServerPlugin util', () => { return entryOption; } - (isWebpack5 ? it : it.skip)('should add hooks to add entries', async () => { - const tapPromise = jest.fn(); - const compiler = { - options: {}, - hooks: { - compilation: { - tap: jest.fn(), - }, - make: { - tapPromise, - }, - }, - }; - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - const compilation = { - addEntry: jest.fn((_context, _dep, _options, cb) => cb()), - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - expect(tapPromise).toBeCalledTimes(1); - expect(tapPromise.mock.calls[0]).toMatchInlineSnapshot(` - Array [ - "DevServerPlugin", - [Function], - ] - `); - - await tapPromise.mock.calls[0][1](compilation); - expect(compilation.addEntry).toBeCalledTimes(1); - }); - - it('should adds devServer entry points to a single entry point', async () => { - const webpackOptions = Object.assign({}, config); - const compiler = webpack(webpackOptions); - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - expect(entries.length).toEqual(2); - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - expect(normalize(entries[1])).toEqual('./foo.js'); - }); - - it('should adds devServer entry points to a multi-module entry point', async () => { - const webpackOptions = Object.assign({}, config, { - entry: ['./foo.js', './bar.js'], - }); - const compiler = webpack(webpackOptions); - - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - expect(entries.length).toEqual(3); - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - expect(entries[1]).toEqual('./foo.js'); - expect(entries[2]).toEqual('./bar.js'); - }); - - it('should adds devServer entry points to a multi entry point object', async () => { - const webpackOptions = Object.assign({}, config, { - entry: { - foo: './foo.js', - bar: './bar.js', - }, - }); - const compiler = webpack(webpackOptions); - - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - if (isWebpack5) { - expect(entries.length).toEqual(1); - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - - expect(entries.foo.import.length).toEqual(1); - expect(entries.foo.import[0]).toEqual('./foo.js'); - expect(entries.bar.import[0]).toEqual('./bar.js'); - } else { - expect(entries.foo.length).toEqual(2); - - expect( - normalize(entries.foo[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - expect(entries.foo[1]).toEqual('./foo.js'); - expect(entries.bar[1]).toEqual('./bar.js'); - } - }); - - it('should set defaults to src if no entry point is given', async () => { - const webpackOptions = {}; - const compiler = webpack(webpackOptions); - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - expect(entries.length).toEqual(2); - expect(entries[1]).toEqual('./src'); - }); - it('should preserves dynamic entry points', (done) => { let i = 0; const webpackOptions = { @@ -278,62 +136,6 @@ describe('DevServerPlugin util', () => { }); }); - it("should prepends webpack's hot reload client script", async () => { - const webpackOptions = Object.assign({}, config, { - entry: { - app: './app.js', - }, - }); - const compiler = webpack(webpackOptions); - - const devServerOptions = { - hot: true, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - const hotClientScript = (isWebpack5 ? entries : entries.app)[1]; - - expect( - normalize(hotClientScript).includes('webpack/hot/dev-server') - ).toBeTruthy(); - expect(hotClientScript).toEqual(require.resolve(hotClientScript)); - }); - - it("should prepends webpack's hot-only client script", async () => { - const webpackOptions = Object.assign({}, config, { - entry: { - app: './app.js', - }, - }); - const compiler = webpack(webpackOptions); - - const devServerOptions = { - hot: 'only', - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - const hotClientScript = (isWebpack5 ? entries : entries.app)[1]; - - expect( - normalize(hotClientScript).includes('webpack/hot/only-dev-server') - ).toBeTruthy(); - expect(hotClientScript).toEqual(require.resolve(hotClientScript)); - }); - it("should doesn't add the HMR plugin if not hot and no plugins", () => { const webpackOptions = Object.assign({}, config); const compiler = webpack(webpackOptions); @@ -452,313 +254,4 @@ describe('DevServerPlugin util', () => { expect(typeof entries === 'function').toBe(true); }); - - (isWebpack5 ? it : it.skip)( - 'should supports entry as descriptor', - async () => { - const webpackOptions = Object.assign({}, configEntryAsDescriptor); - const compiler = webpack(webpackOptions); - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - - expect(entries.length).toEqual(2); - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - expect(normalize(entries[1])).toEqual('./foo.js'); - } - ); - - it('should only prepends devServer entry points to web targets by default', async () => { - const webpackOptions = [ - Object.assign({}, config), - Object.assign({ target: 'web' }, config), - Object.assign({ target: 'webworker' }, config), - Object.assign({ target: 'electron-renderer' }, config), - Object.assign({ target: 'node-webkit' }, config), - Object.assign({ target: 'node' }, config) /* index:5 */, - ]; - const compiler = webpack(webpackOptions); - - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - await Promise.all( - // eslint-disable-next-line no-shadow - compiler.compilers.map((compiler, index) => { - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - - return getEntries(compiler).then((entries) => { - const expectInline = index !== 5; /* all but the node target */ - - expect(entries.length).toEqual(expectInline ? 2 : 1); - - if (expectInline) { - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - } - - expect(normalize(entries[expectInline ? 1 : 0])).toEqual('./foo.js'); - }); - }) - ); - }); - - (isWebpack5 ? it : it.skip)( - 'should prepend devServer entry points depending on targetProperties', - async () => { - // https://github.com/webpack/webpack/issues/11660 - const configNoChunkLoading = Object.assign({}, config); - configNoChunkLoading.output = Object.assign( - { - chunkLoading: false, - wasmLoading: false, - workerChunkLoading: false, - }, - config.output - ); - - const webpackOptions = [ - Object.assign({ target: ['web', 'webworker'] }, configNoChunkLoading), - Object.assign({ target: 'browserslist:last 2 versions' }, config), - Object.assign({ target: ['web', 'node'] }, configNoChunkLoading), - Object.assign( - { target: 'browserslist:last 2 versions, maintained node versions' }, - configNoChunkLoading - ), - Object.assign( - { target: 'browserslist:maintained node versions' }, - config - ), - Object.assign({ target: false }, config), - ]; - const compiler = webpack(webpackOptions); - - const devServerOptions = { - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - await Promise.all( - // eslint-disable-next-line no-shadow - compiler.compilers.map((compiler, index) => { - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - - return getEntries(compiler).then((entries) => { - const expectInline = index < 2; /* all but the node target */ - - expect(entries.length).toEqual(expectInline ? 2 : 1); - - if (expectInline) { - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - } - - expect(normalize(entries[expectInline ? 1 : 0])).toEqual( - './foo.js' - ); - }); - }) - ); - } - ); - - it('should allows selecting compilations to inline the client into', async () => { - const webpackOptions = [ - Object.assign({}, config), - Object.assign({ target: 'web' }, config), - Object.assign({ name: 'only-include' }, config) /* index:2 */, - Object.assign({ target: 'node' }, config), - ]; - const compiler = webpack(webpackOptions); - - const devServerOptions = { - injectClient: (compilerConfig) => compilerConfig.name === 'only-include', - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - await Promise.all( - // eslint-disable-next-line no-shadow - compiler.compilers.map((compiler, index) => { - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - return getEntries(compiler).then((entries) => { - const expectInline = - index === 2; /* only the "only-include" compiler */ - - expect(entries.length).toEqual(expectInline ? 2 : 1); - - if (expectInline) { - expect( - normalize(entries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - } - - expect(normalize(entries[expectInline ? 1 : 0])).toEqual('./foo.js'); - }); - }) - ); - }); - - it('should prepends the hot runtime to all targets by default (when hot)', async () => { - const webpackOptions = [ - Object.assign({ target: 'web' }, config), - Object.assign({ target: 'node' }, config), - ]; - const compiler = webpack(webpackOptions); - - const devServerOptions = { - // disable inlining the client so entry indexes match up - // and we can use the same assertions for both configs - injectClient: false, - hot: true, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - await Promise.all( - // eslint-disable-next-line no-shadow - compiler.compilers.map((compiler) => { - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - - return getEntries(compiler).then((entries) => { - expect(entries.length).toEqual(2); - - expect( - normalize(entries[0]).includes('webpack/hot/dev-server') - ).toBeTruthy(); - - expect(normalize(entries[1])).toEqual('./foo.js'); - }); - }) - ); - }); - - it('should allows selecting which compilations to inject the hot runtime into', async () => { - const webpackOptions = [ - Object.assign({ target: 'web' }, config), - Object.assign({ target: 'node' }, config), - ]; - const compiler = webpack(webpackOptions); - - const devServerOptions = { - injectHot: (compilerConfig) => compilerConfig.target === 'node', - hot: true, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - // eslint-disable-next-line no-shadow - compiler.compilers.forEach((compiler) => { - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - }); - - // node target should have the client runtime but not the hot runtime - const webEntries = await getEntries(compiler.compilers[0]); - - expect(webEntries.length).toEqual(2); - - expect( - normalize(webEntries[0]).indexOf('client/default/index.js?') !== -1 - ).toBeTruthy(); - - expect(normalize(webEntries[1])).toEqual('./foo.js'); - - // node target should have the hot runtime but not the client runtime - const nodeEntries = await getEntries(compiler.compilers[1]); - - expect(nodeEntries.length).toEqual(2); - - expect( - normalize(nodeEntries[0]).includes('webpack/hot/dev-server') - ).toBeTruthy(); - - expect(normalize(nodeEntries[1])).toEqual('./foo.js'); - }); - - it('does not use client.path when default', async () => { - const webpackOptions = Object.assign({}, config); - const compiler = webpack(webpackOptions); - const devServerOptions = { - client: { - path: '/ws', - }, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - expect(entries[0]).not.toContain('&path=/ws'); - }); - - it('uses custom client.path', async () => { - const webpackOptions = Object.assign({}, config); - const compiler = webpack(webpackOptions); - const devServerOptions = { - client: { - path: '/custom/path', - }, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - expect(entries[0]).toContain('&path=/custom/path'); - }); - - it('uses custom client', async () => { - const webpackOptions = Object.assign({}, config); - const compiler = webpack(webpackOptions); - const devServerOptions = { - client: { - host: 'my.host', - port: 8080, - path: '/custom/path', - }, - transportMode: { - server: 'sockjs', - client: 'sockjs', - }, - }; - - const plugin = new DevServerPlugin(devServerOptions); - plugin.apply(compiler); - const entries = await getEntries(compiler); - expect(entries[0]).toContain('&host=my.host&path=/custom/path&port=8080'); - }); }); diff --git a/test/server/utils/updateCompiler.test.js b/test/server/utils/updateCompiler.test.js index eb3f91fd5f..2891d01548 100644 --- a/test/server/utils/updateCompiler.test.js +++ b/test/server/utils/updateCompiler.test.js @@ -43,7 +43,7 @@ describe('updateCompiler', () => { expect(compiler.hooks.entryOption.taps.length).toBe(1); expect(tapsByHMR).toEqual(0); expect(tapsByProvidePlugin).toEqual(1); - expect(tapsByDevServerPlugin).toEqual(isWebpack5 ? 1 : 0); + expect(tapsByDevServerPlugin).toEqual(0); expect(compiler.options.plugins).toHaveLength(0); }); }); @@ -87,7 +87,7 @@ describe('updateCompiler', () => { expect(compiler.hooks.entryOption.taps.length).toBe(1); expect(tapsByHMR).toEqual(1); expect(tapsByProvidePlugin).toEqual(1); - expect(tapsByDevServerPlugin).toEqual(isWebpack5 ? 1 : 0); + expect(tapsByDevServerPlugin).toEqual(0); }); }); @@ -131,8 +131,8 @@ describe('updateCompiler', () => { expect(compiler.hooks.entryOption.taps.length).toBe(1); expect(tapsByHMR).toEqual(1); - expect(tapsByProvidePlugin).toEqual(1); - expect(tapsByDevServerPlugin).toEqual(isWebpack5 ? 1 : 0); + expect(tapsByProvidePlugin).toEqual(isWebpack5 ? 4 : 1); + expect(tapsByDevServerPlugin).toEqual(0); expect(compiler.options.plugins).toContainEqual( new webpack.HotModuleReplacementPlugin() ); @@ -181,7 +181,7 @@ describe('updateCompiler', () => { expect(compiler.hooks.entryOption.taps.length).toBe(1); expect(tapsByHMR).toEqual(1); expect(tapsByProvidePlugin).toEqual(1); - expect(tapsByDevServerPlugin).toEqual(isWebpack5 ? 1 : 0); + expect(tapsByDevServerPlugin).toEqual(0); }); }); });