diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index f34e415160..4ab436d6a0 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -20,7 +20,6 @@ const webpack = require('webpack'); const options = require('./options'); const Server = require('../lib/Server'); -const addEntries = require('../lib/utils/addEntries'); const colors = require('../lib/utils/colors'); const createConfig = require('../lib/utils/createConfig'); const createDomain = require('../lib/utils/createDomain'); @@ -140,8 +139,6 @@ function processOptions(config) { function startDevServer(config, options) { const log = createLogger(options); - addEntries(config, options); - let compiler; try { diff --git a/test/Server.test.js b/test/Server.test.js index b2aa5fe21d..1c4a17bb78 100644 --- a/test/Server.test.js +++ b/test/Server.test.js @@ -1,5 +1,6 @@ 'use strict'; +const { relative, sep } = require('path'); const webpack = require('webpack'); const request = require('supertest'); const Server = require('../lib/Server'); @@ -7,6 +8,64 @@ const config = require('./fixtures/simple-config/webpack.config'); const helper = require('./helper'); describe('Server', () => { + describe('addEntries', () => { + it('add hot option', () => { + return new Promise((res) => { + // eslint-disable-next-line + const Server = require('../lib/Server'); + const compiler = webpack(config); + const server = new Server(compiler, { + hot: true, + }); + + expect( + server.middleware.context.compiler.options.entry.map((p) => { + return relative('.', p).split(sep); + }) + ).toMatchSnapshot(); + expect( + server.middleware.context.compiler.options.plugins + ).toMatchSnapshot(); + + compiler.hooks.done.tap('webpack-dev-server', () => { + server.close(() => { + res(); + }); + }); + + compiler.run(() => {}); + }); + }); + + it('add hotOnly option', () => { + return new Promise((res) => { + // eslint-disable-next-line + const Server = require('../lib/Server'); + const compiler = webpack(config); + const server = new Server(compiler, { + hotOnly: true, + }); + + expect( + server.middleware.context.compiler.options.entry.map((p) => { + return relative('.', p).split(sep); + }) + ).toMatchSnapshot(); + expect( + server.middleware.context.compiler.options.plugins + ).toMatchSnapshot(); + + compiler.hooks.done.tap('webpack-dev-server', () => { + server.close(() => { + res(); + }); + }); + + compiler.run(() => {}); + }); + }); + }); + // issue: https://github.com/webpack/webpack-dev-server/issues/1724 describe('express.static.mine.types', () => { beforeEach(() => { diff --git a/test/__snapshots__/Server.test.js.snap b/test/__snapshots__/Server.test.js.snap index 53f30e0c38..afd2139df5 100644 --- a/test/__snapshots__/Server.test.js.snap +++ b/test/__snapshots__/Server.test.js.snap @@ -1,5 +1,65 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Server addEntries add hot option 1`] = ` +Array [ + Array [ + "client", + "index.js?http:", + "localhost", + ], + Array [ + "node_modules", + "webpack", + "hot", + "dev-server.js", + ], + Array [ + "foo.js", + ], +] +`; + +exports[`Server addEntries add hot option 2`] = ` +Array [ + HotModuleReplacementPlugin { + "fullBuildTimeout": 200, + "multiStep": undefined, + "options": Object {}, + "requestTimeout": 10000, + }, +] +`; + +exports[`Server addEntries add hotOnly option 1`] = ` +Array [ + Array [ + "client", + "index.js?http:", + "localhost", + ], + Array [ + "node_modules", + "webpack", + "hot", + "only-dev-server.js", + ], + Array [ + "foo.js", + ], +] +`; + +exports[`Server addEntries add hotOnly option 2`] = ` +Array [ + HotModuleReplacementPlugin { + "fullBuildTimeout": 200, + "multiStep": undefined, + "options": Object {}, + "requestTimeout": 10000, + }, +] +`; + exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 1`] = ` Array [ "errors",