diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack4 b/test/e2e/__snapshots__/api.test.js.snap.webpack4 index d53956a485..75dcaaba94 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack4 @@ -110,6 +110,19 @@ exports[`API Server.getFreePort should return the port when the port is undefine exports[`API Server.getFreePort should throw the error when the port isn't found 1`] = `"busy"`; +exports[`API WEBPACK_SERVE environment variable should be present: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`API WEBPACK_SERVE environment variable should be present: page errors 1`] = `Array []`; + +exports[`API WEBPACK_SERVE environment variable should be present: response status 1`] = `200`; + exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack5 b/test/e2e/__snapshots__/api.test.js.snap.webpack5 index d53956a485..75dcaaba94 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack5 @@ -110,6 +110,19 @@ exports[`API Server.getFreePort should return the port when the port is undefine exports[`API Server.getFreePort should throw the error when the port isn't found 1`] = `"busy"`; +exports[`API WEBPACK_SERVE environment variable should be present: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", +] +`; + +exports[`API WEBPACK_SERVE environment variable should be present: page errors 1`] = `Array []`; + +exports[`API WEBPACK_SERVE environment variable should be present: response status 1`] = `200`; + exports[`API deprecated API should log warning when the "port" and "host" options from options different from arguments ('listen' method): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/api.test.js b/test/e2e/api.test.js index 740b1a3d7f..41d268240e 100644 --- a/test/e2e/api.test.js +++ b/test/e2e/api.test.js @@ -9,6 +9,68 @@ const runBrowser = require("../helpers/run-browser"); const port = require("../ports-map").api; describe("API", () => { + describe("WEBPACK_SERVE environment variable", () => { + const OLD_ENV = process.env; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + // this is important - it clears the cache + jest.resetModules(); + + process.env = { ...OLD_ENV }; + + delete process.env.WEBPACK_SERVE; + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + process.env = OLD_ENV; + }); + + it("should be present", async () => { + expect(process.env.WEBPACK_SERVE).toBeUndefined(); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const WebpackDevServer = require("../../lib/Server"); + + const compiler = webpack(config); + server = new WebpackDevServer({ port }, compiler); + + await server.start(); + + expect(process.env.WEBPACK_SERVE).toBe(true); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + describe("latest async API", () => { it(`should work with async API`, async () => { const compiler = webpack(config); diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 10b46c4d0a..7cff5256e9 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -161,29 +161,4 @@ describe("Server", () => { await server.stop(); }); }); - - describe("WEBPACK_SERVE environment variable", () => { - const OLD_ENV = process.env; - - beforeEach(() => { - // this is important - it clears the cache - jest.resetModules(); - - process.env = { ...OLD_ENV }; - - delete process.env.WEBPACK_SERVE; - }); - - afterEach(() => { - process.env = OLD_ENV; - }); - - it("should be present", () => { - expect(process.env.WEBPACK_SERVE).toBeUndefined(); - - require("../../lib/Server"); - - expect(process.env.WEBPACK_SERVE).toBe(true); - }); - }); });