diff --git a/client-src/utils/reloadApp.js b/client-src/utils/reloadApp.js index 83368e4010..adc976b20a 100644 --- a/client-src/utils/reloadApp.js +++ b/client-src/utils/reloadApp.js @@ -15,7 +15,7 @@ function reloadApp({ hot, liveReload }, status) { ? // eslint-disable-next-line camelcase __webpack_hash__ : status.previousHash || ""; - const isInitial = status.currentHash.indexOf(webpackHash) === 0; + const isInitial = status.currentHash.indexOf(webpackHash) >= 0; if (isInitial) { const isLegacyInitial = diff --git a/lib/Server.js b/lib/Server.js index 26c72599cb..edfc688a1e 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1150,26 +1150,18 @@ class Server { } setupHooks() { - const addHooks = (compiler) => { - compiler.hooks.invalid.tap("webpack-dev-server", () => { - if (this.webSocketServer) { - this.sendMessage(this.webSocketServer.clients, "invalid"); - } - }); - compiler.hooks.done.tap("webpack-dev-server", (stats) => { - if (this.webSocketServer) { - this.sendStats(this.webSocketServer.clients, this.getStats(stats)); - } - - this.stats = stats; - }); - }; + this.compiler.hooks.invalid.tap("webpack-dev-server", () => { + if (this.webSocketServer) { + this.sendMessage(this.webSocketServer.clients, "invalid"); + } + }); + this.compiler.hooks.done.tap("webpack-dev-server", (stats) => { + if (this.webSocketServer) { + this.sendStats(this.webSocketServer.clients, this.getStats(stats)); + } - if (this.compiler.compilers) { - this.compiler.compilers.forEach(addHooks); - } else { - addHooks(this.compiler); - } + this.stats = stats; + }); } setupHostHeaderCheck() { diff --git a/test/client/utils/reloadApp.test.js b/test/client/utils/reloadApp.test.js index d527df19ab..57b11e710c 100644 --- a/test/client/utils/reloadApp.test.js +++ b/test/client/utils/reloadApp.test.js @@ -86,7 +86,7 @@ describe("'reloadApp' function", () => { reloadApp( { hot: false, hotReload: true, liveReload: true }, - { isUnloading: false, currentHash: "other-mock-hash" } + { isUnloading: false, currentHash: "changed-mock" } ); setTimeout(() => { @@ -101,7 +101,7 @@ describe("'reloadApp' function", () => { test("should run liveReload when protocol is http:", (done) => { reloadApp( { hot: false, hotReload: true, liveReload: true }, - { isUnloading: false, currentHash: "other-mock-hash" } + { isUnloading: false, currentHash: "changed-mock" } ); setTimeout(() => { diff --git a/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4 b/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4 index 325028241c..5b7650e8a4 100644 --- a/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack4 @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Multi compiler should work with multiple compilers: console messages 1`] = ` +exports[`multi compiler should work with one web target configuration: console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", "Hey.", @@ -9,4 +9,94 @@ Array [ ] `; -exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`; +exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "one", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "two", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "one", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "two", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = ` +Array [ + "one", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = ` +Array [ + "two", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hello from the browser", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hello from the browser", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = ` +Array [ + "Hello from the browser", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`; diff --git a/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5 b/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5 index 325028241c..5b7650e8a4 100644 --- a/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/multi-compiler.test.js.snap.webpack5 @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Multi compiler should work with multiple compilers: console messages 1`] = ` +exports[`multi compiler should work with one web target configuration: console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", "Hey.", @@ -9,4 +9,94 @@ Array [ ] `; -exports[`Multi compiler should work with multiple compilers: page errors 1`] = `Array []`; +exports[`multi compiler should work with one web target configuration: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "one", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: console messages 2`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "two", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with hot and live reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only hot reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "one", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only hot reload: console messages 2`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "two", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only hot reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only hot reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only live reload: console messages 1`] = ` +Array [ + "one", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only live reload: console messages 2`] = ` +Array [ + "two", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with two web target configurations with only live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with two web target configurations with only live reload: page errors 2`] = `Array []`; + +exports[`multi compiler should work with universal configurations with hot and live reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hello from the browser", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with hot and live reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with universal configurations with only hot reload: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hello from the browser", + "[webpack-dev-server] Hot Module Replacement enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with only hot reload: page errors 1`] = `Array []`; + +exports[`multi compiler should work with universal configurations with only live reload: console messages 1`] = ` +Array [ + "Hello from the browser", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`multi compiler should work with universal configurations with only live reload: page errors 1`] = `Array []`; diff --git a/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack4 b/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack4 index dabed81dab..e22d538ee7 100644 --- a/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack4 @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`; +exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`; -exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`; +exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`; -exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`; +exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`; -exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`; +exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`; diff --git a/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack5 b/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack5 index dabed81dab..e22d538ee7 100644 --- a/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/universal-compiler.test.js.snap.webpack5 @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`; +exports[`universal compiler client bundle should have the inlined the client runtime: console messages 1`] = `Array []`; -exports[`Universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`; +exports[`universal compiler client bundle should have the inlined the client runtime: page errors 1`] = `Array []`; -exports[`Universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`; +exports[`universal compiler server bundle should NOT have the inlined the client runtime: console messages 1`] = `Array []`; -exports[`Universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`; +exports[`universal compiler server bundle should NOT have the inlined the client runtime: page errors 1`] = `Array []`; diff --git a/test/e2e/module-federation.test.js b/test/e2e/module-federation.test.js index 6f2e0249d5..b02dc155db 100644 --- a/test/e2e/module-federation.test.js +++ b/test/e2e/module-federation.test.js @@ -8,7 +8,7 @@ const objectEntryConfig = require("../fixtures/module-federation-config/webpack. const multiConfig = require("../fixtures/module-federation-config/webpack.multi.config"); const runBrowser = require("../helpers/run-browser"); const isWebpack5 = require("../helpers/isWebpack5"); -const port = require("../ports-map")["universal-compiler"]; +const port = require("../ports-map")["module-federation"]; const describeOnlyWebpack5 = isWebpack5 ? describe : describe.skip; diff --git a/test/e2e/multi-compiler.test.js b/test/e2e/multi-compiler.test.js index d596fbccc2..b4e5749afe 100644 --- a/test/e2e/multi-compiler.test.js +++ b/test/e2e/multi-compiler.test.js @@ -2,13 +2,15 @@ const webpack = require("webpack"); const Server = require("../../lib/Server"); -const config = require("../fixtures/multi-compiler-config/webpack.config"); +const oneWebTargetConfiguration = require("../fixtures/multi-compiler-one-configuration/webpack.config"); +const twoWebTargetConfiguration = require("../fixtures/multi-compiler-two-configurations/webpack.config"); +const universalConfiguration = require("../fixtures/universal-compiler-config/webpack.config"); const runBrowser = require("../helpers/run-browser"); const port = require("../ports-map")["multi-compiler"]; -describe("Multi compiler", () => { - it(`should work with multiple compilers`, async () => { - const compiler = webpack(config); +describe("multi compiler", () => { + it(`should work with one web target configuration`, async () => { + const compiler = webpack(oneWebTargetConfiguration); const devServerOptions = { port, }; @@ -23,7 +25,7 @@ describe("Multi compiler", () => { page .on("console", (message) => { - consoleMessages.push(message); + consoleMessages.push(message.text()); }) .on("pageerror", (error) => { pageErrors.push(error); @@ -33,12 +35,284 @@ describe("Multi compiler", () => { waitUntil: "networkidle0", }); - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - "console messages" + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + + it(`should work with two web target configurations with hot and live reload`, async () => { + const compiler = webpack(twoWebTargetConfiguration); + const devServerOptions = { + port, + }; + + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page: pageOne, browser } = await runBrowser(); + + let pageErrors = []; + let consoleMessages = []; + + pageOne + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await pageOne.goto(`http://127.0.0.1:${port}/one-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + pageErrors = []; + consoleMessages = []; + + await pageOne.goto(`http://127.0.0.1:${port}/two-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + + it(`should work with two web target configurations with only hot reload`, async () => { + const compiler = webpack(twoWebTargetConfiguration); + const devServerOptions = { + port, + hot: true, + liveReload: false, + }; + + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page: pageOne, browser } = await runBrowser(); + + let pageErrors = []; + let consoleMessages = []; + + pageOne + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await pageOne.goto(`http://127.0.0.1:${port}/one-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + pageErrors = []; + consoleMessages = []; + + await pageOne.goto(`http://127.0.0.1:${port}/two-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + + it(`should work with two web target configurations with only live reload`, async () => { + const compiler = webpack(twoWebTargetConfiguration); + const devServerOptions = { + port, + hot: false, + liveReload: true, + }; + + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page: pageOne, browser } = await runBrowser(); + + let pageErrors = []; + let consoleMessages = []; + + pageOne + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await pageOne.goto(`http://127.0.0.1:${port}/one-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + pageErrors = []; + consoleMessages = []; + + await pageOne.goto(`http://127.0.0.1:${port}/two-main`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + await browser.close(); + await server.stop(); + }); + + it("should work with universal configurations with hot and live reload", async () => { + const compiler = webpack(universalConfiguration); + const devServerOptions = { + port, + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + const pageErrors = []; + const consoleMessages = []; + + page + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await page.goto(`http://127.0.0.1:${port}/browser`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + const serverResponse = await page.goto( + `http://127.0.0.1:${port}/server.js`, + { + waitUntil: "networkidle0", + } ); + const serverResponseText = await serverResponse.text(); + + expect(serverResponseText).toContain("Hello from the server"); + expect(serverResponseText).not.toContain("WebsocketServer"); + + await browser.close(); + await server.stop(); + }); + + it("should work with universal configurations with only hot reload", async () => { + const compiler = webpack(universalConfiguration); + const devServerOptions = { + port, + hot: true, + liveReload: false, + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + const pageErrors = []; + const consoleMessages = []; + + page + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await page.goto(`http://127.0.0.1:${port}/browser`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); + expect(pageErrors).toMatchSnapshot("page errors"); + + const serverResponse = await page.goto( + `http://127.0.0.1:${port}/server.js`, + { + waitUntil: "networkidle0", + } + ); + + const serverResponseText = await serverResponse.text(); + + expect(serverResponseText).toContain("Hello from the server"); + expect(serverResponseText).not.toContain("WebsocketServer"); + + await browser.close(); + await server.stop(); + }); + + it("should work with universal configurations with only live reload", async () => { + const compiler = webpack(universalConfiguration); + const devServerOptions = { + port, + hot: false, + liveReload: true, + }; + const server = new Server(devServerOptions, compiler); + + await server.start(); + + const { page, browser } = await runBrowser(); + + const pageErrors = []; + const consoleMessages = []; + + page + .on("console", (message) => { + consoleMessages.push(message.text()); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + await page.goto(`http://127.0.0.1:${port}/browser`, { + waitUntil: "networkidle0", + }); + + expect(consoleMessages).toMatchSnapshot("console messages"); expect(pageErrors).toMatchSnapshot("page errors"); + const serverResponse = await page.goto( + `http://127.0.0.1:${port}/server.js`, + { + waitUntil: "networkidle0", + } + ); + + const serverResponseText = await serverResponse.text(); + + expect(serverResponseText).toContain("Hello from the server"); + expect(serverResponseText).not.toContain("WebsocketServer"); + await browser.close(); await server.stop(); }); diff --git a/test/e2e/universal-compiler.test.js b/test/e2e/universal-compiler.test.js deleted file mode 100644 index 5bbf9e91f7..0000000000 --- a/test/e2e/universal-compiler.test.js +++ /dev/null @@ -1,93 +0,0 @@ -"use strict"; - -const webpack = require("webpack"); -const Server = require("../../lib/Server"); -const config = require("../fixtures/universal-compiler-config/webpack.config"); -const runBrowser = require("../helpers/run-browser"); -const port = require("../ports-map")["universal-compiler"]; - -describe("Universal compiler", () => { - it("client bundle should have the inlined the client runtime", async () => { - const compiler = webpack(config); - const devServerOptions = { - port, - }; - const server = new Server(devServerOptions, compiler); - - await server.start(); - - const { page, browser } = await runBrowser(); - - const pageErrors = []; - const consoleMessages = []; - - page - .on("console", (message) => { - consoleMessages.push(message); - }) - .on("pageerror", (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`http://127.0.0.1:${port}/client.js`, { - waitUntil: "networkidle0", - }); - - const responseText = await response.text(); - - expect(responseText).toContain("Hello from the client"); - expect(responseText).toContain("WebsocketClient"); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - "console messages" - ); - - expect(pageErrors).toMatchSnapshot("page errors"); - - await browser.close(); - await server.stop(); - }); - - it("server bundle should NOT have the inlined the client runtime", async () => { - // we wouldn't normally request a server bundle - // but we'll do it here to check the contents - const compiler = webpack(config); - const devServerOptions = { - port, - }; - const server = new Server(devServerOptions, compiler); - - await server.start(); - - const { page, browser } = await runBrowser(); - - const pageErrors = []; - const consoleMessages = []; - - page - .on("console", (message) => { - consoleMessages.push(message); - }) - .on("pageerror", (error) => { - pageErrors.push(error); - }); - - const response = await page.goto(`http://127.0.0.1:${port}/server.js`, { - waitUntil: "networkidle0", - }); - - const responseText = await response.text(); - - expect(responseText).toContain("Hello from the server"); - expect(responseText).not.toContain("WebsocketServer"); - - expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( - "console messages" - ); - - expect(pageErrors).toMatchSnapshot("page errors"); - - await browser.close(); - await server.stop(); - }); -}); diff --git a/test/fixtures/multi-compiler-2-config/webpack.config.js b/test/fixtures/multi-compiler-2-config/webpack.config.js deleted file mode 100644 index e27f4b8aa2..0000000000 --- a/test/fixtures/multi-compiler-2-config/webpack.config.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; - -module.exports = [ - { - mode: "development", - context: __dirname, - entry: "./foo.js", - output: { - path: "/", - }, - node: false, - infrastructureLogging: { - level: "warn", - }, - }, - { - mode: "development", - context: __dirname, - entry: "./foo.js", - output: { - path: "/", - }, - node: false, - infrastructureLogging: { - level: "warn", - }, - }, -]; diff --git a/test/fixtures/multi-compiler-config/foo.js b/test/fixtures/multi-compiler-config/foo.js deleted file mode 100644 index 3c915dbcb8..0000000000 --- a/test/fixtures/multi-compiler-config/foo.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; - -console.log("Hey."); diff --git a/test/fixtures/multi-compiler-2-config/foo.js b/test/fixtures/multi-compiler-one-configuration/foo.js similarity index 100% rename from test/fixtures/multi-compiler-2-config/foo.js rename to test/fixtures/multi-compiler-one-configuration/foo.js diff --git a/test/fixtures/multi-compiler-config/webpack.config.js b/test/fixtures/multi-compiler-one-configuration/webpack.config.js similarity index 96% rename from test/fixtures/multi-compiler-config/webpack.config.js rename to test/fixtures/multi-compiler-one-configuration/webpack.config.js index d366a2837d..7f2a435195 100644 --- a/test/fixtures/multi-compiler-config/webpack.config.js +++ b/test/fixtures/multi-compiler-one-configuration/webpack.config.js @@ -6,6 +6,7 @@ const isWebpack5 = webpack.version.startsWith("5"); module.exports = [ { + target: "web", mode: "development", context: __dirname, stats: "none", diff --git a/test/fixtures/multi-compiler-two-configurations/one.js b/test/fixtures/multi-compiler-two-configurations/one.js new file mode 100644 index 0000000000..e767ff32f1 --- /dev/null +++ b/test/fixtures/multi-compiler-two-configurations/one.js @@ -0,0 +1,3 @@ +"use strict"; + +console.log("one"); diff --git a/test/fixtures/multi-compiler-two-configurations/two.js b/test/fixtures/multi-compiler-two-configurations/two.js new file mode 100644 index 0000000000..83bf26e4bb --- /dev/null +++ b/test/fixtures/multi-compiler-two-configurations/two.js @@ -0,0 +1,3 @@ +"use strict"; + +console.log("two"); diff --git a/test/fixtures/multi-compiler-two-configurations/webpack.config.js b/test/fixtures/multi-compiler-two-configurations/webpack.config.js new file mode 100644 index 0000000000..2d26011084 --- /dev/null +++ b/test/fixtures/multi-compiler-two-configurations/webpack.config.js @@ -0,0 +1,52 @@ +"use strict"; + +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + +module.exports = [ + { + target: "web", + name: "one", + mode: "development", + context: __dirname, + entry: "./one.js", + stats: "none", + output: { + path: "/", + filename: "one-[name].js", + }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, + }, + { + target: "web", + name: "two", + mode: "development", + context: __dirname, + entry: "./two.js", + stats: "none", + output: { + path: "/", + filename: "two-[name].js", + }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, + }, +]; diff --git a/test/fixtures/universal-compiler-config/browser.js b/test/fixtures/universal-compiler-config/browser.js new file mode 100644 index 0000000000..ddcebf29c7 --- /dev/null +++ b/test/fixtures/universal-compiler-config/browser.js @@ -0,0 +1,3 @@ +"use strict"; + +console.log("Hello from the browser"); diff --git a/test/fixtures/universal-compiler-config/client.js b/test/fixtures/universal-compiler-config/client.js deleted file mode 100644 index 3cc4ed1dcb..0000000000 --- a/test/fixtures/universal-compiler-config/client.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; - -console.log("Hello from the client"); diff --git a/test/fixtures/universal-compiler-config/webpack.config.js b/test/fixtures/universal-compiler-config/webpack.config.js index 9846adc095..04159afcc6 100644 --- a/test/fixtures/universal-compiler-config/webpack.config.js +++ b/test/fixtures/universal-compiler-config/webpack.config.js @@ -1,18 +1,29 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = [ { mode: "development", context: __dirname, stats: "none", - entry: "./client.js", + entry: "./browser.js", output: { path: "/", - filename: "client.js", - }, - infrastructureLogging: { - level: "warn", + filename: "browser.js", }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }, { mode: "development", @@ -24,8 +35,15 @@ module.exports = [ path: "/", filename: "server.js", }, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }, ]; diff --git a/test/ports-map.js b/test/ports-map.js index 3f03908cb3..8a30d151e4 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -18,7 +18,6 @@ const listOfTests = { // integration tests "module-federation": 1, "multi-compiler": 1, - "universal-compiler": 1, // unit tests bonjour: 1, "client-option": 1, diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 8b85ae785c..db2a5b0ec8 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -679,7 +679,7 @@ describe("Server", () => { let webpackConfig; if (item.multiCompiler) { - webpackConfig = require("../fixtures/multi-compiler-config/webpack.config"); + webpackConfig = require("../fixtures/multi-compiler-one-configuration/webpack.config"); if (Array.isArray(item.webpackConfig)) { // eslint-disable-next-line no-shadow diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index 300abd3d25..2dc0dca68a 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index 300abd3d25..2dc0dca68a 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8125&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", diff --git a/test/server/hot-option.test.js b/test/server/hot-option.test.js index 66d3381a81..e42ab0405c 100644 --- a/test/server/hot-option.test.js +++ b/test/server/hot-option.test.js @@ -4,7 +4,7 @@ const webpack = require("webpack"); const request = require("supertest"); const Server = require("../../lib/Server"); const config = require("../fixtures/client-config/webpack.config"); -const multiCompilerConfig = require("../fixtures/multi-compiler-config/webpack.config"); +const multiCompilerConfig = require("../fixtures/multi-compiler-one-configuration/webpack.config"); const port = require("../ports-map")["hot-option"]; describe("hot option", () => {