diff --git a/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack4 b/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack4 new file mode 100644 index 0000000000..afb6ba0b6a --- /dev/null +++ b/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack4 @@ -0,0 +1,100 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: console messages 1`] = `Array []`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: directory list 1`] = ` +"

Assets Report:

Compilation: unnamed[0]

Compilation: named

Compilation: other

" +`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: page errors 1`] = `Array []`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: directory list 1`] = ` +"

Assets Report:

Compilation: unnamed

" +`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: response headers content-type 1`] = `"application/javascript; charset=utf-8"`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to magic async html: 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[`Built in routes with simple config should handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; + +exports[`Built in routes with simple config should handle GET request to magic async html: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: directory list 1`] = `""`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: response headers content-type 1`] = `"application/javascript; charset=utf-8"`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: response status 1`] = `200`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: response headers content-type 1`] = `"application/javascript"`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: response status 1`] = `200`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: response headers content-type 1`] = `"application/javascript"`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: response status 1`] = `200`; diff --git a/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack5 b/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack5 new file mode 100644 index 0000000000..afb6ba0b6a --- /dev/null +++ b/test/e2e/__snapshots__/built-in-routes.test.js.snap.webpack5 @@ -0,0 +1,100 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: console messages 1`] = `Array []`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: directory list 1`] = ` +"

Assets Report:

Compilation: unnamed[0]

Compilation: named

Compilation: other

" +`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: page errors 1`] = `Array []`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with multi config should handle GET request to directory index and list all middleware directories: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: directory list 1`] = ` +"

Assets Report:

Compilation: unnamed

" +`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with simple config should handle GET request to directory index and list all middleware directories: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to invalidate endpoint: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: response headers content-type 1`] = `"application/javascript; charset=utf-8"`; + +exports[`Built in routes with simple config should handle GET request to magic async chunk: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle GET request to magic async html: 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[`Built in routes with simple config should handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; + +exports[`Built in routes with simple config should handle GET request to magic async html: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: directory list 1`] = `""`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: response headers content-type 1`] = `"text/html"`; + +exports[`Built in routes with simple config should handle HEAD request to directory index: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: response headers content-type 1`] = `"application/javascript; charset=utf-8"`; + +exports[`Built in routes with simple config should handle HEAD request to magic async chunk: response status 1`] = `200`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; + +exports[`Built in routes with simple config should handle HEAD request to magic async html: response status 1`] = `200`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: response headers content-type 1`] = `"application/javascript"`; + +exports[`Built in routes with simple config should handles GET request to sockjs bundle: response status 1`] = `200`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: console messages 1`] = `Array []`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: page errors 1`] = `Array []`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: response headers content-type 1`] = `"application/javascript"`; + +exports[`Built in routes with simple config should handles HEAD request to sockjs bundle: response status 1`] = `200`; diff --git a/test/e2e/built-in-routes.test.js b/test/e2e/built-in-routes.test.js new file mode 100644 index 0000000000..461a589bfc --- /dev/null +++ b/test/e2e/built-in-routes.test.js @@ -0,0 +1,374 @@ +"use strict"; + +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/client-config/webpack.config"); +const multiConfig = require("../fixtures/multi-public-path-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map")["universal-compiler"]; + +describe("Built in routes", () => { + describe("with simple config", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + server = new Server({ port }, compiler); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handles GET request to sockjs bundle", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/__webpack_dev_server__/sockjs.bundle.js`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handles HEAD request to sockjs bundle", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "HEAD" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/__webpack_dev_server__/sockjs.bundle.js`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle GET request to invalidate endpoint", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/webpack-dev-server/invalidate`, + { + waitUntil: "networkidle0", + } + ); + + expect(response.headers()["content-type"]).not.toEqual("text/html"); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle GET request to directory index and list all middleware directories", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/webpack-dev-server/`, + { + waitUntil: "networkidle0", + } + ); + + const bodyHandle = await page.$("body"); + const htmlContent = await page.evaluate( + (body) => body.innerHTML, + bodyHandle + ); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(htmlContent).toMatchSnapshot("directory list"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle HEAD request to directory index", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "HEAD" }); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/webpack-dev-server/`, + { + waitUntil: "networkidle0", + } + ); + + const bodyHandle = await page.$("body"); + const htmlContent = await page.evaluate( + (body) => body.innerHTML, + bodyHandle + ); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(htmlContent).toMatchSnapshot("directory list"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + + it("should handle GET request to magic async html", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + }); + + it("should handle HEAD request to magic async html", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "HEAD" }); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + }); + + it("should handle GET request to magic async chunk", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main.js`, { + waitUntil: "networkidle0", + }); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + }); + + it("should handle HEAD request to magic async chunk", async () => { + await page.setRequestInterception(true); + + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }) + .on("request", (interceptedRequest) => { + interceptedRequest.continue({ method: "HEAD" }); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main.js`, { + waitUntil: "networkidle0", + }); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + }); + }); + + describe("with multi config", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(multiConfig); + server = new Server({ port }, compiler); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + await server.stop(); + }); + + it("should handle GET request to directory index and list all middleware directories", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto( + `http://127.0.0.1:${port}/webpack-dev-server/`, + { + waitUntil: "networkidle0", + } + ); + + const bodyHandle = await page.$("body"); + const htmlContent = await page.evaluate( + (body) => body.innerHTML, + bodyHandle + ); + + expect(response.headers()["content-type"]).toMatchSnapshot( + "response headers content-type" + ); + + expect(response.status()).toMatchSnapshot("response status"); + + expect(htmlContent).toMatchSnapshot("directory list"); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); +}); diff --git a/test/server/__snapshots__/built-in-routes.test.js.snap.webpack4 b/test/server/__snapshots__/built-in-routes.test.js.snap.webpack4 deleted file mode 100644 index 116822b6f2..0000000000 --- a/test/server/__snapshots__/built-in-routes.test.js.snap.webpack4 +++ /dev/null @@ -1,19 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`routes util multi config should handle GET request to directory index and list all middleware directories 1`] = ` -"

Assets Report:

Compilation: unnamed[0]

Compilation: named

Compilation: other

" -`; - -exports[`routes util simple config should handle GET request to directory index 1`] = ` -"

Assets Report:

Compilation: unnamed

" -`; diff --git a/test/server/__snapshots__/built-in-routes.test.js.snap.webpack5 b/test/server/__snapshots__/built-in-routes.test.js.snap.webpack5 deleted file mode 100644 index 116822b6f2..0000000000 --- a/test/server/__snapshots__/built-in-routes.test.js.snap.webpack5 +++ /dev/null @@ -1,19 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`routes util multi config should handle GET request to directory index and list all middleware directories 1`] = ` -"

Assets Report:

Compilation: unnamed[0]

Compilation: named

Compilation: other

" -`; - -exports[`routes util simple config should handle GET request to directory index 1`] = ` -"

Assets Report:

Compilation: unnamed

" -`; diff --git a/test/server/built-in-routes.test.js b/test/server/built-in-routes.test.js deleted file mode 100644 index c818e08840..0000000000 --- a/test/server/built-in-routes.test.js +++ /dev/null @@ -1,145 +0,0 @@ -"use strict"; - -const webpack = require("webpack"); -const request = require("supertest"); -const Server = require("../../lib/Server"); -const config = require("../fixtures/simple-config/webpack.config"); -const multiConfig = require("../fixtures/multi-public-path-config/webpack.config"); -const port = require("../ports-map").routes; - -describe("routes util", () => { - let server; - let req; - - describe("simple config", () => { - beforeAll(async () => { - const compiler = webpack(config); - - server = new Server( - { - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("should handles GET request to sockjs bundle", async () => { - const response = await req.get( - "/__webpack_dev_server__/sockjs.bundle.js" - ); - - expect(response.headers["content-type"]).toEqual( - "application/javascript" - ); - expect(response.statusCode).toEqual(200); - }); - - it("should handle HEAD request to sockjs bundle", async () => { - const response = await req.head( - "/__webpack_dev_server__/sockjs.bundle.js" - ); - - expect(response.headers["content-type"]).toEqual( - "application/javascript" - ); - expect(response.statusCode).toEqual(200); - }); - - it("should handle GET request to invalidate endpoint", async () => { - const response = await req.get("/webpack-dev-server/invalidate"); - - expect(response.headers["content-type"]).not.toEqual("text/html"); - expect(response.statusCode).toEqual(200); - }); - - it("should handle GET request to live html", async () => { - const response = await req.get("/webpack-dev-server/"); - - expect(response.headers["content-type"]).toEqual("text/html"); - expect(response.statusCode).toEqual(200); - }); - - it("should handle HEAD request to live html", async () => { - const response = await req.head("/webpack-dev-server/"); - - expect(response.headers["content-type"]).toEqual("text/html"); - expect(response.statusCode).toEqual(200); - }); - - it("should handle GET request to directory index", async () => { - const response = await req.get("/webpack-dev-server"); - - expect(response.headers["content-type"]).toEqual("text/html"); - expect(response.statusCode).toEqual(200); - expect(response.text).toMatchSnapshot(); - }); - - it("should handle HEAD request to directory index", async () => { - const response = await req.head("/webpack-dev-server"); - - expect(response.headers["content-type"]).toEqual("text/html"); - expect(response.statusCode).toEqual(200); - }); - - it("should handle GET request to magic async html", async () => { - const response = await req.get("/main"); - - expect(response.statusCode).toEqual(200); - }); - - it("should handle HEAD request to magic async html", async () => { - const response = await req.head("/main"); - - expect(response.statusCode).toEqual(200); - }); - - it("should handle GET request to main async chunk", async () => { - const response = await req.get("/main.js"); - - expect(response.statusCode).toEqual(200); - }); - - it("should handle HEAD request to main async chunk", async () => { - const response = await req.head("/main.js"); - - expect(response.statusCode).toEqual(200); - }); - }); - - describe("multi config", () => { - beforeAll(async () => { - const compiler = webpack(multiConfig); - - server = new Server( - { - port, - }, - compiler - ); - - await server.start(); - - req = request(server.app); - }); - - afterAll(async () => { - await server.stop(); - }); - - it("should handle GET request to directory index and list all middleware directories", async () => { - const response = await req.get("/webpack-dev-server"); - - expect(response.headers["content-type"]).toEqual("text/html"); - expect(response.statusCode).toEqual(200); - expect(response.text).toMatchSnapshot(); - }); - }); -});