diff --git a/.cspell.json b/.cspell.json
index 77c778432f..1976882978 100644
--- a/.cspell.json
+++ b/.cspell.json
@@ -2,6 +2,7 @@
"version": "0.2",
"language": "en,en-gb",
"words": [
+ "apos",
"camelcase",
"tapable",
"sockjs",
@@ -64,7 +65,13 @@
"omnibox",
"swiftshader",
"hoge",
- "subsubcomain"
+ "subsubcomain",
+ "noselect",
+ "commitlint",
+ "eslintcache",
+ "hono",
+ "privkey",
+ "geomanist"
],
"ignorePaths": [
"CHANGELOG.md",
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 8505d9a5fd..2db9dc995b 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -8,3 +8,7 @@ updates:
timezone: Europe/Berlin
open-pull-requests-limit: 10
versioning-strategy: lockfile-only
+ groups:
+ dependencies:
+ patterns:
+ - "*"
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
index 24a35a06ad..8caf799d12 100644
--- a/.github/workflows/dependency-review.yml
+++ b/.github/workflows/dependency-review.yml
@@ -9,6 +9,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: "Dependency Review"
- uses: actions/dependency-review-action@v3
+ uses: actions/dependency-review-action@v4
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index 9642a61189..24289f5388 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -69,7 +69,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
- node-version: [18.x, 20.x, 21.x]
+ node-version: [18.x, 20.x, 22.x, 24.x]
shard: ["1/4", "2/4", "3/4", "4/4"]
webpack-version: [latest]
@@ -120,6 +120,6 @@ jobs:
if: matrix.node-version != '18.x'
- name: Submit coverage data to codecov
- uses: codecov/codecov-action@v3
+ uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 389040450b..de3b694aec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,4 +20,5 @@ test/fixtures/static-config/public/assets/non-exist.txt
test/fixtures/watch-files-config/public/assets/non-exist.txt
test/fixtures/reload-config/main.css
test/fixtures/reload-config-2/main.css
+test/fixtures/worker-config-dev-server-false/public
!/test/fixtures/static-config/public/node_modules
diff --git a/.husky/commit-msg b/.husky/commit-msg
index fd2bf708ee..dbce4f4cf4 100755
--- a/.husky/commit-msg
+++ b/.husky/commit-msg
@@ -1 +1 @@
-npx --no-install commitlint --edit $1
+commitlint --edit $1
diff --git a/.husky/pre-commit b/.husky/pre-commit
index 2312dc587f..c27d8893a9 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1 +1 @@
-npx lint-staged
+lint-staged
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b8c907652..066cd4a0ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,61 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+### [5.2.2](https://github.com/webpack/webpack-dev-server/compare/v5.2.1...v5.2.2) (2025-06-03)
+
+
+### Bug Fixes
+
+* "Overlay enabled" false positive ([18e72ee](https://github.com/webpack/webpack-dev-server/commit/18e72ee3e57a6e7598a6c068c0ff7c7bb6a857f1))
+* do not crush when error is null for runtime errors ([#5447](https://github.com/webpack/webpack-dev-server/issues/5447)) ([309991f](https://github.com/webpack/webpack-dev-server/commit/309991f947baa0354140b9930a9654ac792e20c4))
+* remove unnecessary header `X_TEST` ([#5451](https://github.com/webpack/webpack-dev-server/issues/5451)) ([64a6124](https://github.com/webpack/webpack-dev-server/commit/64a6124bf1b4d158bb42a4341dd03121ae3759fa))
+* respect the `allowedHosts` option for cross-origin header check ([#5510](https://github.com/webpack/webpack-dev-server/issues/5510)) ([03d1214](https://github.com/webpack/webpack-dev-server/commit/03d12141bf7be09dfb14e91e5c834ee63bd9a9a2))
+
+## [5.2.1](https://github.com/webpack/webpack-dev-server/compare/v5.2.0...v6.0.0) (2025-03-26)
+
+### Security
+
+* cross-origin requests are not allowed unless allowed by `Access-Control-Allow-Origin` header
+* requests with an IP addresses in the `Origin` header are not allowed to connect to WebSocket server unless configured by `allowedHosts` or it different from the `Host` header
+
+The above changes may make the dev server not work if you relied on such behavior, but unfortunately they carry security risks, so they were considered as fixes.
+
+### Bug Fixes
+
+* prevent overlay for errors caught by React error boundaries ([#5431](https://github.com/webpack/webpack-dev-server/issues/5431)) ([8c1abc9](https://github.com/webpack/webpack-dev-server/commit/8c1abc903ab444d9ce99e567b9a6c603e1ec06be))
+* take the first network found instead of the last one, this restores the same behavior as 5.0.4 ([#5411](https://github.com/webpack/webpack-dev-server/issues/5411)) ([ffd0b86](https://github.com/webpack/webpack-dev-server/commit/ffd0b86b790d372f90e17aea92cfd9def83fee96))
+
+## [5.2.0](https://github.com/webpack/webpack-dev-server/compare/v5.1.0...v5.2.0) (2024-12-11)
+
+
+### Features
+
+* added `getClientEntry` and `getClientHotEntry` methods to get clients entries ([dc642a8](https://github.com/webpack/webpack-dev-server/commit/dc642a832d45c23c5c7a08fbf29995e0db7e0d95))
+
+
+### Bug Fixes
+
+* speed up initial client bundling ([145b5d0](https://github.com/webpack/webpack-dev-server/commit/145b5d01610a16468fc32719a20366682b0e8572))
+
+## [5.1.0](https://github.com/webpack/webpack-dev-server/compare/v5.0.4...v5.1.0) (2024-09-03)
+
+
+### Features
+
+* add visual progress indicators ([a8f40b7](https://github.com/webpack/webpack-dev-server/commit/a8f40b74e6439a8281b9fe8868eb9db7e4c5de50))
+* added the `app` option to be `Function` (by default only with `connect` compatibility frameworks) ([3096148](https://github.com/webpack/webpack-dev-server/commit/3096148746c906105c4424352f5b5ad1bff0fd4f))
+* allow the `server` option to be `Function` ([#5275](https://github.com/webpack/webpack-dev-server/issues/5275)) ([02a1c6d](https://github.com/webpack/webpack-dev-server/commit/02a1c6d788f5fc47c11cc7d910fd1b5e17aed886))
+* http2 support for `connect` and `connect` compatibility frameworks which support HTTP2 ([#5267](https://github.com/webpack/webpack-dev-server/issues/5267)) ([6509a3f](https://github.com/webpack/webpack-dev-server/commit/6509a3fd3eb5decb61f60a9f2db97d76f71ecb99))
+
+
+### Bug Fixes
+
+* check the `platform` property to determinate the target ([#5269](https://github.com/webpack/webpack-dev-server/issues/5269)) ([c3b532c](https://github.com/webpack/webpack-dev-server/commit/c3b532c6360317319793dcda22c76fbfc05fbdcf))
+* ipv6 output ([#5270](https://github.com/webpack/webpack-dev-server/issues/5270)) ([06005e7](https://github.com/webpack/webpack-dev-server/commit/06005e7cb99e4c412b968ed3fb786acfb8c2e037))
+* replace `rimraf` with `rm` ([#5162](https://github.com/webpack/webpack-dev-server/issues/5162)) ([1a1561f](https://github.com/webpack/webpack-dev-server/commit/1a1561f09bdfa7a98434d7d9cd62e323b887dfbf))
+* replace default gateway ([#5255](https://github.com/webpack/webpack-dev-server/issues/5255)) ([f5f0902](https://github.com/webpack/webpack-dev-server/commit/f5f09024ff4fe6625aa94bcd69439462d74013f0))
+* support `devServer: false` ([#5272](https://github.com/webpack/webpack-dev-server/issues/5272)) ([8b341cb](https://github.com/webpack/webpack-dev-server/commit/8b341cb8c1dc01cef62c70959620cd0cbd87fee7))
+
### [5.0.4](https://github.com/webpack/webpack-dev-server/compare/v5.0.3...v5.0.4) (2024-03-19)
diff --git a/README.md b/README.md
index 37221aaa30..e8ceea5f5f 100644
--- a/README.md
+++ b/README.md
@@ -190,7 +190,7 @@ CLI documentation: https://webpack.js.org/api/cli/.
Made with ♥ by the webpack team.
```
-> **Note**
+> [!NOTE]
>
> _Detailed documentation for above options is available on this [link](https://webpack.js.org/configuration/dev-server/)._
diff --git a/client-src/index.js b/client-src/index.js
index 4523ef845c..c9ea5d1233 100644
--- a/client-src/index.js
+++ b/client-src/index.js
@@ -1,14 +1,12 @@
/* global __resourceQuery, __webpack_hash__ */
///
import webpackHotLog from "webpack/hot/log.js";
-import stripAnsi from "./utils/stripAnsi.js";
-import parseURL from "./utils/parseURL.js";
+import hotEmitter from "webpack/hot/emitter.js";
import socket from "./socket.js";
import { formatProblem, createOverlay } from "./overlay.js";
-import { log, logEnabledFeatures, setLogLevel } from "./utils/log.js";
+import { log, setLogLevel } from "./utils/log.js";
import sendMessage from "./utils/sendMessage.js";
-import reloadApp from "./utils/reloadApp.js";
-import createSocketURL from "./utils/createSocketURL.js";
+import { isProgressSupported, defineProgressElement } from "./progress.js";
/**
* @typedef {Object} OverlayOptions
@@ -47,13 +45,11 @@ const decodeOverlayOptions = (overlayOptions) => {
);
// eslint-disable-next-line no-new-func
- const overlayFilterFunction = new Function(
+ overlayOptions[property] = new Function(
"message",
`var callback = ${overlayFilterFunctionString}
return callback(message)`,
);
-
- overlayOptions[property] = overlayFilterFunction;
}
});
}
@@ -68,13 +64,75 @@ const status = {
currentHash: __webpack_hash__,
};
-/** @type {Options} */
-const options = {
- hot: false,
- liveReload: false,
- progress: false,
- overlay: false,
+/**
+ * @returns {string}
+ */
+const getCurrentScriptSource = () => {
+ // `document.currentScript` is the most accurate way to find the current script,
+ // but is not supported in all browsers.
+ if (document.currentScript) {
+ return document.currentScript.getAttribute("src");
+ }
+
+ // Fallback to getting all scripts running in the document.
+ const scriptElements = document.scripts || [];
+ const scriptElementsWithSrc = Array.prototype.filter.call(
+ scriptElements,
+ (element) => element.getAttribute("src"),
+ );
+
+ if (scriptElementsWithSrc.length > 0) {
+ const currentScript =
+ scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
+
+ return currentScript.getAttribute("src");
+ }
+
+ // Fail as there was no script to use.
+ throw new Error("[webpack-dev-server] Failed to get current script source.");
};
+
+/**
+ * @param {string} resourceQuery
+ * @returns {{ [key: string]: string | boolean }}
+ */
+const parseURL = (resourceQuery) => {
+ /** @type {{ [key: string]: string }} */
+ let result = {};
+
+ if (typeof resourceQuery === "string" && resourceQuery !== "") {
+ const searchParams = resourceQuery.slice(1).split("&");
+
+ for (let i = 0; i < searchParams.length; i++) {
+ const pair = searchParams[i].split("=");
+
+ result[pair[0]] = decodeURIComponent(pair[1]);
+ }
+ } else {
+ // Else, get the url from the ',
+ ),
+ ).toBe(true);
+ expect(consoleMessages.map((message) => message.text())).toEqual([
+ "[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
+ "[HMR] Waiting for update signal from WDS...",
+ "Hey.",
+ ]);
+ expect(pageErrors).toHaveLength(0);
+ });
+ });
+ }
+});
diff --git a/test/e2e/bonjour.test.js b/test/e2e/bonjour.test.js
index bd4c2c15fe..e0911f14b5 100644
--- a/test/e2e/bonjour.test.js
+++ b/test/e2e/bonjour.test.js
@@ -71,7 +71,7 @@ describe("bonjour option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -144,7 +144,7 @@ describe("bonjour option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`https://127.0.0.1:${port}/`, {
+ const response = await page.goto(`https://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -226,7 +226,7 @@ describe("bonjour option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -312,7 +312,7 @@ describe("bonjour option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`https://127.0.0.1:${port}/`, {
+ const response = await page.goto(`https://localhost:${port}/`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/built-in-routes.test.js b/test/e2e/built-in-routes.test.js
index bf9eff0fe0..d5dd08f212 100644
--- a/test/e2e/built-in-routes.test.js
+++ b/test/e2e/built-in-routes.test.js
@@ -43,7 +43,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/__webpack_dev_server__/sockjs.bundle.js`,
+ `http://localhost:${port}/__webpack_dev_server__/sockjs.bundle.js`,
{
waitUntil: "networkidle0",
},
@@ -77,7 +77,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/__webpack_dev_server__/sockjs.bundle.js`,
+ `http://localhost:${port}/__webpack_dev_server__/sockjs.bundle.js`,
{
waitUntil: "networkidle0",
},
@@ -106,7 +106,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/webpack-dev-server/invalidate`,
+ `http://localhost:${port}/webpack-dev-server/invalidate`,
{
waitUntil: "networkidle0",
},
@@ -133,7 +133,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/webpack-dev-server/`,
+ `http://localhost:${port}/webpack-dev-server/`,
{
waitUntil: "networkidle0",
},
@@ -169,7 +169,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/webpack-dev-server/`,
+ `http://localhost:${port}/webpack-dev-server/`,
{
waitUntil: "networkidle0",
},
@@ -199,7 +199,7 @@ describe("Built in routes", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -228,7 +228,7 @@ describe("Built in routes", () => {
interceptedRequest.continue({ method: "HEAD" });
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -279,7 +279,7 @@ describe("Built in routes", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/webpack-dev-server/`,
+ `http://localhost:${port}/webpack-dev-server/`,
{
waitUntil: "networkidle0",
},
diff --git a/test/e2e/client-reconnect.test.js b/test/e2e/client-reconnect.test.js
index 0e382a2b5a..1269743c74 100644
--- a/test/e2e/client-reconnect.test.js
+++ b/test/e2e/client-reconnect.test.js
@@ -41,7 +41,7 @@ describe("client.reconnect option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -107,7 +107,7 @@ describe("client.reconnect option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -172,7 +172,7 @@ describe("client.reconnect option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/client.test.js b/test/e2e/client.test.js
index e74d9cb9c2..bd8b24e4b4 100644
--- a/test/e2e/client.test.js
+++ b/test/e2e/client.test.js
@@ -51,7 +51,7 @@ describe("client option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/ws`, {
+ const response = await page.goto(`http://localhost:${port}/ws`, {
waitUntil: "networkidle0",
});
@@ -120,7 +120,7 @@ describe("client option", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/foo/test/bar`,
+ `http://localhost:${port}/foo/test/bar`,
{
waitUntil: "networkidle0",
},
@@ -177,7 +177,7 @@ describe("client option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -193,6 +193,60 @@ describe("client option", () => {
});
});
+ describe("override client entry", () => {
+ let compiler;
+ let server;
+ let page;
+ let browser;
+
+ class OverrideServer extends Server {
+ // eslint-disable-next-line class-methods-use-this
+ getClientEntry() {
+ return require.resolve(
+ "../fixtures/custom-client/CustomClientEntry.js",
+ );
+ }
+ // eslint-disable-next-line class-methods-use-this
+ getClientHotEntry() {
+ return require.resolve(
+ "../fixtures/custom-client/CustomClientHotEntry.js",
+ );
+ }
+ }
+
+ beforeEach(async () => {
+ compiler = webpack(config);
+
+ server = new OverrideServer(
+ {
+ port,
+ },
+ compiler,
+ );
+
+ await server.start();
+
+ ({ page, browser } = await runBrowser());
+ });
+
+ afterEach(async () => {
+ await browser.close();
+ await server.stop();
+ });
+
+ it("should disable client entry", async () => {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
+ waitUntil: "networkidle0",
+ });
+
+ expect(response.status()).toMatchSnapshot("response status");
+
+ const content = await response.text();
+ expect(content).toContain("CustomClientEntry.js");
+ expect(content).toContain("CustomClientHotEntry.js");
+ });
+ });
+
describe("webSocketTransport", () => {
const clientModes = [
{
diff --git a/test/e2e/compress.test.js b/test/e2e/compress.test.js
index 0493658f45..4436292e8f 100644
--- a/test/e2e/compress.test.js
+++ b/test/e2e/compress.test.js
@@ -42,7 +42,7 @@ describe("compress option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -101,7 +101,7 @@ describe("compress option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -160,7 +160,7 @@ describe("compress option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/cross-origin-request.test.js b/test/e2e/cross-origin-request.test.js
new file mode 100644
index 0000000000..65de9cf3f2
--- /dev/null
+++ b/test/e2e/cross-origin-request.test.js
@@ -0,0 +1,224 @@
+"use strict";
+
+const webpack = require("webpack");
+const Server = require("../../lib/Server");
+const config = require("../fixtures/client-config/webpack.config");
+const runBrowser = require("../helpers/run-browser");
+const [port1, port2] = require("../ports-map")["cross-origin-request"];
+
+describe("cross-origin requests", () => {
+ const devServerPort = port1;
+ const htmlServerPort = port2;
+ const htmlServerHost = "127.0.0.1";
+
+ it("should return 403 for cross-origin no-cors non-module script tag requests", async () => {
+ const compiler = webpack(config);
+ const devServerOptions = {
+ port: devServerPort,
+ allowedHosts: "auto",
+ };
+ const server = new Server(devServerOptions, compiler);
+
+ await server.start();
+
+ // Start a separate server for serving the HTML file
+ const http = require("http");
+ const htmlServer = http.createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ res.end(`
+
+
+
+
+
+
+ `);
+ });
+ htmlServer.listen(htmlServerPort, htmlServerHost);
+
+ const { page, browser } = await runBrowser();
+
+ try {
+ const pageErrors = [];
+
+ page.on("pageerror", (error) => {
+ pageErrors.push(error);
+ });
+
+ const scriptTagRequest = page.waitForResponse(
+ `http://localhost:${devServerPort}/main.js`,
+ );
+
+ await page.goto(`http://${htmlServerHost}:${htmlServerPort}`);
+
+ const response = await scriptTagRequest;
+
+ expect(response.status()).toBe(403);
+ } catch (error) {
+ throw error;
+ } finally {
+ await browser.close();
+ await server.stop();
+ htmlServer.close();
+ }
+ });
+
+ it("should return 200 for cross-origin cors non-module script tag requests", async () => {
+ const compiler = webpack(config);
+ const devServerOptions = {
+ port: devServerPort,
+ allowedHosts: "auto",
+ headers: {
+ "Access-Control-Allow-Origin": "*",
+ },
+ };
+ const server = new Server(devServerOptions, compiler);
+
+ await server.start();
+
+ // Start a separate server for serving the HTML file
+ const http = require("http");
+ const htmlServer = http.createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ res.end(`
+
+
+
+
+
+
+ `);
+ });
+ htmlServer.listen(htmlServerPort, htmlServerHost);
+
+ const { page, browser } = await runBrowser();
+
+ try {
+ const pageErrors = [];
+
+ page.on("pageerror", (error) => {
+ pageErrors.push(error);
+ });
+
+ const scriptTagRequest = page.waitForResponse(
+ `http://localhost:${devServerPort}/main.js`,
+ );
+
+ await page.goto(`http://${htmlServerHost}:${htmlServerPort}`);
+
+ const response = await scriptTagRequest;
+
+ expect(response.status()).toBe(200);
+ } catch (error) {
+ throw error;
+ } finally {
+ await browser.close();
+ await server.stop();
+ htmlServer.close();
+ }
+ });
+
+ it("should return 200 for cross-origin no-cors non-module script tag requests with the 'allowedHost' option and 'all' value", async () => {
+ const compiler = webpack(config);
+ const devServerOptions = {
+ port: devServerPort,
+ allowedHosts: "all",
+ };
+ const server = new Server(devServerOptions, compiler);
+
+ await server.start();
+
+ // Start a separate server for serving the HTML file
+ const http = require("http");
+ const htmlServer = http.createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ res.end(`
+
+
+
+
+
+
+ `);
+ });
+ htmlServer.listen(htmlServerPort, htmlServerHost);
+
+ const { page, browser } = await runBrowser();
+
+ try {
+ const pageErrors = [];
+
+ page.on("pageerror", (error) => {
+ pageErrors.push(error);
+ });
+
+ const scriptTagRequest = page.waitForResponse(
+ `http://localhost:${devServerPort}/main.js`,
+ );
+
+ await page.goto(`http://${htmlServerHost}:${htmlServerPort}`);
+
+ const response = await scriptTagRequest;
+
+ expect(response.status()).toBe(200);
+ } catch (error) {
+ throw error;
+ } finally {
+ await browser.close();
+ await server.stop();
+ htmlServer.close();
+ }
+ });
+
+ it("should return 200 for cross-origin no-cors non-module script tag requests with the `allowedHost` option and the `localhost` value", async () => {
+ const compiler = webpack(config);
+ const devServerOptions = {
+ port: devServerPort,
+ allowedHosts: ["localhost"],
+ };
+ const server = new Server(devServerOptions, compiler);
+
+ await server.start();
+
+ // Start a separate server for serving the HTML file
+ const http = require("http");
+ const htmlServer = http.createServer((req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html" });
+ res.end(`
+
+
+
+
+
+
+ `);
+ });
+ htmlServer.listen(htmlServerPort, htmlServerHost);
+
+ const { page, browser } = await runBrowser();
+
+ try {
+ const pageErrors = [];
+
+ page.on("pageerror", (error) => {
+ pageErrors.push(error);
+ });
+
+ const scriptTagRequest = page.waitForResponse(
+ `http://localhost:${devServerPort}/main.js`,
+ );
+
+ await page.goto(`http://${htmlServerHost}:${htmlServerPort}`);
+
+ const response = await scriptTagRequest;
+
+ expect(response.status()).toBe(200);
+ } catch (error) {
+ throw error;
+ } finally {
+ await browser.close();
+ await server.stop();
+ htmlServer.close();
+ }
+ });
+});
diff --git a/test/e2e/entry.test.js b/test/e2e/entry.test.js
index 7505ec3eb2..ff07fbc01a 100644
--- a/test/e2e/entry.test.js
+++ b/test/e2e/entry.test.js
@@ -55,7 +55,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -94,7 +94,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -138,7 +138,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -177,7 +177,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -219,7 +219,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -269,11 +269,11 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/test.html`, {
+ await page.goto(`http://localhost:${port}/test.html`, {
waitUntil: "networkidle0",
});
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` });
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/runtime.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/foo.js` });
await waitForConsoleLogFinished(consoleMessages);
expect(consoleMessages).toMatchSnapshot("console messages");
@@ -320,11 +320,11 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/test.html`, {
+ await page.goto(`http://localhost:${port}/test.html`, {
waitUntil: "networkidle0",
});
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/runtime.js` });
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/runtime.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/bar.js` });
await waitForConsoleLogFinished(consoleMessages);
expect(consoleMessages).toMatchSnapshot("console messages");
@@ -369,11 +369,11 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/test.html`, {
+ await page.goto(`http://localhost:${port}/test.html`, {
waitUntil: "networkidle0",
});
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/bar.js` });
- await page.addScriptTag({ url: `http://127.0.0.1:${port}/foo.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/bar.js` });
+ await page.addScriptTag({ url: `http://localhost:${port}/foo.js` });
await waitForConsoleLogFinished(consoleMessages);
expect(consoleMessages).toMatchSnapshot("console messages");
@@ -417,7 +417,7 @@ describe("entry", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/headers.test.js b/test/e2e/headers.test.js
index 2df4734496..d176cc7730 100644
--- a/test/e2e/headers.test.js
+++ b/test/e2e/headers.test.js
@@ -49,7 +49,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -117,7 +117,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -180,7 +180,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -241,7 +241,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -309,7 +309,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -375,7 +375,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -437,7 +437,7 @@ describe("headers option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/history-api-fallback.test.js b/test/e2e/history-api-fallback.test.js
index f1fe2b6ba7..cf8874189d 100644
--- a/test/e2e/history-api-fallback.test.js
+++ b/test/e2e/history-api-fallback.test.js
@@ -51,7 +51,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -114,7 +114,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -181,7 +181,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -210,7 +210,7 @@ describe("historyApiFallback option", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/random-file.txt`,
+ `http://localhost:${port}/random-file.txt`,
{
waitUntil: "networkidle2",
},
@@ -276,7 +276,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/index.html`, {
+ const response = await page.goto(`http://localhost:${port}/index.html`, {
waitUntil: "networkidle0",
});
@@ -352,7 +352,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -380,7 +380,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/acme`, {
+ const response = await page.goto(`http://localhost:${port}/acme`, {
waitUntil: "networkidle0",
});
@@ -408,7 +408,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/other`, {
+ const response = await page.goto(`http://localhost:${port}/other`, {
waitUntil: "networkidle0",
});
@@ -476,7 +476,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -552,7 +552,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -625,7 +625,7 @@ describe("historyApiFallback option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo`, {
+ const response = await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
@@ -645,7 +645,7 @@ describe("historyApiFallback option", () => {
});
it("should perform HEAD request in same way as GET", async () => {
- await page.goto(`http://127.0.0.1:${port}/foo`, {
+ await page.goto(`http://localhost:${port}/foo`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/host.test.js b/test/e2e/host.test.js
index 3217127115..227e298b37 100644
--- a/test/e2e/host.test.js
+++ b/test/e2e/host.test.js
@@ -1,28 +1,53 @@
"use strict";
+const http = require("http");
const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const port = require("../ports-map").host;
-const ipv4 = Server.internalIPSync("v4");
-const ipv6 = Server.internalIPSync("v6");
-// macos requires root for using ip v6
-const isMacOS = process.platform === "darwin";
+const ipv4 = Server.findIp("v4", false);
+const ipv6 = Server.findIp("v6", false);
-function getAddress(host, hostname) {
+async function getAddress(host, hostname) {
let address;
if (
typeof host === "undefined" ||
- (typeof host === "string" && host === "")
+ (typeof host === "string" && (host === "" || host === "::"))
) {
address = "::";
- } else if (typeof host === "string" && host === "0.0.0.0") {
+ } else if (host === "0.0.0.0") {
address = "0.0.0.0";
- } else if (typeof host === "string" && host === "localhost") {
- address = parseFloat(process.versions.node) >= 18 ? "::1" : "127.0.0.1";
+ } else if (host === "::1") {
+ address = "::1";
+ } else if (host === "localhost") {
+ // It can be `127.0.0.1` or `::1` on different OS
+ const server = http.createServer((req, res) => {
+ res.statusCode = 200;
+ res.setHeader("Content-Type", "text/plain");
+ res.end("Hello World\n");
+ });
+
+ await new Promise((resolve) => {
+ server.listen({ host: "localhost", port: 23100 }, resolve);
+ });
+
+ address = server.address().address;
+
+ await new Promise((resolve, reject) => {
+ server.close((err) => {
+ if (err) {
+ reject(err);
+ return;
+ }
+
+ resolve();
+ });
+ });
+ } else if (host === "local-ipv6") {
+ address = "::";
} else {
address = hostname;
}
@@ -37,56 +62,59 @@ describe("host", () => {
undefined,
"0.0.0.0",
"::",
- "localhost",
"::1",
+ "localhost",
"127.0.0.1",
"local-ip",
"local-ipv4",
"local-ipv6",
];
- for (let host of hosts) {
+ for (const host of hosts) {
it(`should work using "${host}" host and port as number`, async () => {
const compiler = webpack(config);
-
- if (!ipv6 || isMacOS) {
- if (host === "::") {
- host = "127.0.0.1";
- } else if (host === "::1") {
- host = "127.0.0.1";
- } else if (host === "local-ipv6") {
- host = "127.0.0.1";
- }
- }
-
const devServerOptions = { port };
if (host !== "") {
devServerOptions.host = host;
}
+ if (
+ host === "" ||
+ typeof host === "undefined" ||
+ host === "0.0.0.0" ||
+ host === "::" ||
+ host === "local-ipv6"
+ ) {
+ devServerOptions.allowedHosts = "all";
+ }
+
const server = new Server(devServerOptions, compiler);
let hostname = host;
- if (hostname === "0.0.0.0") {
- hostname = "127.0.0.1";
- } else if (
- hostname === "" ||
- typeof hostname === "undefined" ||
- hostname === "::" ||
- hostname === "::1"
- ) {
+ if (hostname === "" || typeof hostname === "undefined") {
+ // If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "0.0.0.0") {
+ hostname = ipv4;
+ } else if (hostname === "::") {
+ // In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0).
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = ipv4;
} else if (hostname === "local-ipv6") {
- hostname = `[${ipv6}]`;
+ // For test env where network ipv6 doesn't work
+ hostname = ipv6 ? `[${ipv6}]` : "[::1]";
}
await server.start();
- expect(server.server.address()).toMatchObject(getAddress(host, hostname));
+ expect(server.server.address()).toMatchObject(
+ await getAddress(host, hostname),
+ );
const { page, browser } = await runBrowser();
@@ -121,45 +149,48 @@ describe("host", () => {
it(`should work using "${host}" host and port as string`, async () => {
const compiler = webpack(config);
-
- if (!ipv6 || isMacOS) {
- if (host === "::") {
- host = "127.0.0.1";
- } else if (host === "::1") {
- host = "127.0.0.1";
- } else if (host === "local-ipv6") {
- host = "127.0.0.1";
- }
- }
-
const devServerOptions = { port: `${port}` };
if (host !== "") {
devServerOptions.host = host;
}
+ if (
+ host === "" ||
+ typeof host === "undefined" ||
+ host === "0.0.0.0" ||
+ host === "::" ||
+ host === "local-ipv6"
+ ) {
+ devServerOptions.allowedHosts = "all";
+ }
+
const server = new Server(devServerOptions, compiler);
let hostname = host;
- if (hostname === "0.0.0.0") {
- hostname = "127.0.0.1";
- } else if (
- hostname === "" ||
- typeof hostname === "undefined" ||
- hostname === "::" ||
- hostname === "::1"
- ) {
+ if (hostname === "" || typeof hostname === "undefined") {
+ // If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "0.0.0.0") {
+ hostname = ipv4;
+ } else if (hostname === "::") {
+ // In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0).
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = ipv4;
} else if (hostname === "local-ipv6") {
- hostname = `[${ipv6}]`;
+ // For test env where network ipv6 doesn't work
+ hostname = ipv6 ? `[${ipv6}]` : "[::1]";
}
await server.start();
- expect(server.server.address()).toMatchObject(getAddress(host, hostname));
+ expect(server.server.address()).toMatchObject(
+ await getAddress(host, hostname),
+ );
const { page, browser } = await runBrowser();
@@ -197,44 +228,48 @@ describe("host", () => {
process.env.WEBPACK_DEV_SERVER_BASE_PORT = port;
- if (!ipv6 || isMacOS) {
- if (host === "::") {
- host = "127.0.0.1";
- } else if (host === "::1") {
- host = "127.0.0.1";
- } else if (host === "local-ipv6") {
- host = "127.0.0.1";
- }
- }
-
const devServerOptions = { port: "auto" };
if (host !== "") {
devServerOptions.host = host;
}
+ if (
+ host === "" ||
+ typeof host === "undefined" ||
+ host === "0.0.0.0" ||
+ host === "::" ||
+ host === "local-ipv6"
+ ) {
+ devServerOptions.allowedHosts = "all";
+ }
+
const server = new Server(devServerOptions, compiler);
let hostname = host;
- if (hostname === "0.0.0.0") {
- hostname = "127.0.0.1";
- } else if (
- hostname === "" ||
- typeof hostname === "undefined" ||
- hostname === "::" ||
- hostname === "::1"
- ) {
+ if (hostname === "" || typeof hostname === "undefined") {
+ // If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "0.0.0.0") {
+ hostname = ipv4;
+ } else if (hostname === "::") {
+ // In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0).
+ hostname = ipv6 ? `[${ipv6}]` : ipv4;
+ } else if (hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = ipv4;
} else if (hostname === "local-ipv6") {
- hostname = `[${ipv6}]`;
+ // For test env where network ipv6 doesn't work
+ hostname = ipv6 ? `[${ipv6}]` : "[::1]";
}
await server.start();
- expect(server.server.address()).toMatchObject(getAddress(host, hostname));
+ expect(server.server.address()).toMatchObject(
+ await getAddress(host, hostname),
+ );
const address = server.server.address();
const { page, browser } = await runBrowser();
diff --git a/test/e2e/hot-and-live-reload.test.js b/test/e2e/hot-and-live-reload.test.js
index e700eb7b65..c53694e60b 100644
--- a/test/e2e/hot-and-live-reload.test.js
+++ b/test/e2e/hot-and-live-reload.test.js
@@ -354,11 +354,11 @@ describe("hot and live reload", () => {
if (webSocketTransport === "ws") {
const ws = new WebSocket(
- `ws://127.0.0.1:${devServerOptions.port}/ws`,
+ `ws://localhost:${devServerOptions.port}/ws`,
{
headers: {
- host: `127.0.0.1:${devServerOptions.port}`,
- origin: `http://127.0.0.1:${devServerOptions.port}`,
+ host: `localhost:${devServerOptions.port}`,
+ origin: `http://localhost:${devServerOptions.port}`,
},
},
);
@@ -400,7 +400,7 @@ describe("hot and live reload", () => {
});
} else {
const sockjs = new SockJS(
- `http://127.0.0.1:${devServerOptions.port}/ws`,
+ `http://localhost:${devServerOptions.port}/ws`,
);
let opened = false;
@@ -624,7 +624,7 @@ describe("simple hot config HMR plugin", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -691,7 +691,7 @@ describe("simple hot config HMR plugin with already added HMR plugin", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -822,7 +822,7 @@ describe("multi compiler hot config HMR plugin", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -885,7 +885,7 @@ describe("hot disabled HMR plugin", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/`, {
+ const response = await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/ipc.test.js b/test/e2e/ipc.test.js
index debe2e1503..a29f7acf2e 100644
--- a/test/e2e/ipc.test.js
+++ b/test/e2e/ipc.test.js
@@ -19,7 +19,7 @@ describe("web socket server URL", () => {
const websocketURLProtocol = webSocketServer === "ws" ? "ws" : "http";
it(`should work with the "ipc" option using "true" value ("${webSocketServer}")`, async () => {
- const devServerHost = "127.0.0.1";
+ const devServerHost = "localhost";
const proxyHost = devServerHost;
const proxyPort = port1;
@@ -123,7 +123,7 @@ describe("web socket server URL", () => {
const pipeName = `webpack-dev-server.${process.pid}-1.sock`;
const ipc = path.join(pipePrefix, pipeName);
- const devServerHost = "127.0.0.1";
+ const devServerHost = "localhost";
const proxyHost = devServerHost;
const proxyPort = port1;
@@ -241,7 +241,7 @@ describe("web socket server URL", () => {
});
});
- const devServerHost = "127.0.0.1";
+ const devServerHost = "localhost";
const proxyHost = devServerHost;
const proxyPort = port1;
diff --git a/test/e2e/lazy-compilation.test.js b/test/e2e/lazy-compilation.test.js
index faa76eb3d1..e3c2db45f9 100644
--- a/test/e2e/lazy-compilation.test.js
+++ b/test/e2e/lazy-compilation.test.js
@@ -29,7 +29,7 @@ describe("lazy compilation", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/test.html`, {
+ await page.goto(`http://localhost:${port}/test.html`, {
waitUntil: "domcontentloaded",
});
await new Promise((resolve) => {
@@ -72,7 +72,7 @@ describe("lazy compilation", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/test-one.html`, {
+ await page.goto(`http://localhost:${port}/test-one.html`, {
waitUntil: "domcontentloaded",
});
await new Promise((resolve) => {
@@ -86,7 +86,7 @@ describe("lazy compilation", () => {
}, 100);
});
- await page.goto(`http://127.0.0.1:${port}/test-two.html`, {
+ await page.goto(`http://localhost:${port}/test-two.html`, {
waitUntil: "domcontentloaded",
});
await new Promise((resolve) => {
diff --git a/test/e2e/mime-types.test.js b/test/e2e/mime-types.test.js
index d55064ede2..ee71894d70 100644
--- a/test/e2e/mime-types.test.js
+++ b/test/e2e/mime-types.test.js
@@ -52,7 +52,7 @@ describe("mimeTypes option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -115,7 +115,7 @@ describe("mimeTypes option", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/file.custom`, {
+ const response = await page.goto(`http://localhost:${port}/file.custom`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/module-federation.test.js b/test/e2e/module-federation.test.js
index 2e471dab91..3bbf7a9e4a 100644
--- a/test/e2e/module-federation.test.js
+++ b/test/e2e/module-federation.test.js
@@ -45,7 +45,7 @@ describe("Module federation", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -103,7 +103,7 @@ describe("Module federation", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -135,7 +135,7 @@ describe("Module federation", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/foo.js`, {
+ const response = await page.goto(`http://localhost:${port}/foo.js`, {
waitUntil: "networkidle0",
});
@@ -193,7 +193,7 @@ describe("Module federation", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
@@ -252,7 +252,7 @@ describe("Module federation", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/remoteEntry.js`,
+ `http://localhost:${port}/remoteEntry.js`,
{
waitUntil: "networkidle0",
},
@@ -278,7 +278,7 @@ describe("Module federation", () => {
pageErrors.push(error);
});
- const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
+ const response = await page.goto(`http://localhost:${port}/main.js`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/multi-compiler.test.js b/test/e2e/multi-compiler.test.js
index da60f8e053..6142094f93 100644
--- a/test/e2e/multi-compiler.test.js
+++ b/test/e2e/multi-compiler.test.js
@@ -34,7 +34,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/`, {
+ await page.goto(`http://localhost:${port}/`, {
waitUntil: "networkidle0",
});
@@ -72,7 +72,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/one-main.html`, {
+ await page.goto(`http://localhost:${port}/one-main.html`, {
waitUntil: "networkidle0",
});
@@ -82,7 +82,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/two-main.html`, {
+ await page.goto(`http://localhost:${port}/two-main.html`, {
waitUntil: "networkidle0",
});
@@ -140,7 +140,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/one-main.html`, {
+ await page.goto(`http://localhost:${port}/one-main.html`, {
waitUntil: "networkidle0",
});
@@ -154,7 +154,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/two-main.html`, {
+ await page.goto(`http://localhost:${port}/two-main.html`, {
waitUntil: "networkidle0",
});
@@ -219,7 +219,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/one-main.html`, {
+ await page.goto(`http://localhost:${port}/one-main.html`, {
waitUntil: "networkidle0",
});
@@ -233,7 +233,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/two-main.html`, {
+ await page.goto(`http://localhost:${port}/two-main.html`, {
waitUntil: "networkidle0",
});
@@ -290,7 +290,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/one-main.html`, {
+ await page.goto(`http://localhost:${port}/one-main.html`, {
waitUntil: "networkidle0",
});
@@ -304,7 +304,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/two-main.html`, {
+ await page.goto(`http://localhost:${port}/two-main.html`, {
waitUntil: "networkidle0",
});
@@ -361,7 +361,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/one-main.html`, {
+ await page.goto(`http://localhost:${port}/one-main.html`, {
waitUntil: "networkidle0",
});
@@ -375,7 +375,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/two-main.html`, {
+ await page.goto(`http://localhost:${port}/two-main.html`, {
waitUntil: "networkidle0",
});
@@ -411,7 +411,7 @@ describe("multi compiler", () => {
const consoleMessages = [];
try {
const serverResponse = await page.goto(
- `http://127.0.0.1:${port}/server.js`,
+ `http://localhost:${port}/server.js`,
{
waitUntil: "networkidle0",
},
@@ -430,7 +430,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
} catch (error) {
@@ -470,7 +470,7 @@ describe("multi compiler", () => {
try {
const serverResponse = await page.goto(
- `http://127.0.0.1:${port}/server.js`,
+ `http://localhost:${port}/server.js`,
{
waitUntil: "networkidle0",
},
@@ -500,7 +500,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
@@ -545,7 +545,7 @@ describe("multi compiler", () => {
try {
const serverResponse = await page.goto(
- `http://127.0.0.1:${port}/server.js`,
+ `http://localhost:${port}/server.js`,
{
waitUntil: "networkidle0",
},
@@ -575,7 +575,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
@@ -624,7 +624,7 @@ describe("multi compiler", () => {
try {
const serverResponse = await page.goto(
- `http://127.0.0.1:${port}/server.js`,
+ `http://localhost:${port}/server.js`,
{
waitUntil: "networkidle0",
},
@@ -646,7 +646,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
@@ -663,7 +663,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
@@ -713,7 +713,7 @@ describe("multi compiler", () => {
try {
const serverResponse = await page.goto(
- `http://127.0.0.1:${port}/server.js`,
+ `http://localhost:${port}/server.js`,
{
waitUntil: "networkidle0",
},
@@ -735,7 +735,7 @@ describe("multi compiler", () => {
pageErrors.push(error);
});
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
@@ -752,7 +752,7 @@ describe("multi compiler", () => {
pageErrors = [];
consoleMessages = [];
- await page.goto(`http://127.0.0.1:${port}/browser.html`, {
+ await page.goto(`http://localhost:${port}/browser.html`, {
waitUntil: "networkidle0",
});
diff --git a/test/e2e/on-listening.test.js b/test/e2e/on-listening.test.js
index 6e97561b14..1e2be08a9d 100644
--- a/test/e2e/on-listening.test.js
+++ b/test/e2e/on-listening.test.js
@@ -26,12 +26,18 @@ describe("onListening option", () => {
onListeningIsRunning = true;
- devServer.app.get("/listening/some/path", (_, response) => {
- response.send("listening");
- });
-
- devServer.app.post("/listening/some/path", (_, response) => {
- response.send("listening POST");
+ devServer.app.use("/listening/some/path", (req, res, next) => {
+ if (req.method === "GET") {
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
+ res.end("listening");
+ return;
+ } else if (req.method === "POST") {
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
+ res.end("listening POST");
+ return;
+ }
+
+ return next();
});
},
port,
@@ -62,7 +68,7 @@ describe("onListening option", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/listening/some/path`,
+ `http://localhost:${port}/listening/some/path`,
{
waitUntil: "networkidle0",
},
@@ -102,7 +108,7 @@ describe("onListening option", () => {
});
const response = await page.goto(
- `http://127.0.0.1:${port}/listening/some/path`,
+ `http://localhost:${port}/listening/some/path`,
{
waitUntil: "networkidle0",
},
diff --git a/test/e2e/options-middleware.test.js b/test/e2e/options-middleware.test.js
index 613c39f735..9f8f2cef2f 100644
--- a/test/e2e/options-middleware.test.js
+++ b/test/e2e/options-middleware.test.js
@@ -65,7 +65,7 @@ describe("handle options-request correctly", () => {
await server.start();
const { page, browser } = await runBrowser();
- const prefixUrl = "http://127.0.0.1";
+ const prefixUrl = "http://localhost";
const htmlUrl = `${prefixUrl}:${portForServer}/test.html`;
const appUrl = `${prefixUrl}:${portForApp}`;
diff --git a/test/e2e/overlay.test.js b/test/e2e/overlay.test.js
index 7e1efb1122..023b9a331a 100644
--- a/test/e2e/overlay.test.js
+++ b/test/e2e/overlay.test.js
@@ -1978,10 +1978,16 @@ describe("overlay", () => {
}),
).toMatchSnapshot("page html");
expect(
- await prettier.format(overlayHtml, {
- parser: "html",
- plugins: [prettierHTML, prettierCSS],
- }),
+ await prettier.format(
+ overlayHtml.replace(
+ /