Skip to content

test: fix todo #3713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions test/e2e/__snapshots__/host-and-port.test.js.snap.webpack4
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`host and port should work using "::" host and "auto" port: 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[`host and port should work using "::" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "::" host and port as number: 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[`host and port should work using "::" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "::" host and port as string: 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[`host and port should work using "::" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and "auto" port: 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[`host and port should work using "::1" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and port as number: 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[`host and port should work using "::1" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and port as string: 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[`host and port should work using "::1" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "0.0.0.0" host and "auto" port: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down Expand Up @@ -132,6 +198,39 @@ Array [

exports[`host and port should work using "local-ipv4" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and "auto" port: 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[`host and port should work using "local-ipv6" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and port as number: 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[`host and port should work using "local-ipv6" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and port as string: 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[`host and port should work using "local-ipv6" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "localhost" host and "auto" port: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
99 changes: 99 additions & 0 deletions test/e2e/__snapshots__/host-and-port.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`host and port should work using "::" host and "auto" port: 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[`host and port should work using "::" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "::" host and port as number: 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[`host and port should work using "::" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "::" host and port as string: 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[`host and port should work using "::" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and "auto" port: 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[`host and port should work using "::1" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and port as number: 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[`host and port should work using "::1" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "::1" host and port as string: 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[`host and port should work using "::1" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "0.0.0.0" host and "auto" port: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down Expand Up @@ -132,6 +198,39 @@ Array [

exports[`host and port should work using "local-ipv4" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and "auto" port: 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[`host and port should work using "local-ipv6" host and "auto" port: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and port as number: 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[`host and port should work using "local-ipv6" host and port as number: page errors 1`] = `Array []`;

exports[`host and port should work using "local-ipv6" host and port as string: 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[`host and port should work using "local-ipv6" host and port as string: page errors 1`] = `Array []`;

exports[`host and port should work using "localhost" host and "auto" port: console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
Expand Down
71 changes: 64 additions & 7 deletions test/e2e/host-and-port.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,49 @@ const config = require("../fixtures/client-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const port = require("../ports-map")["host-and-port"];

describe("host and port", () => {
// TODO: add "local-ipv6"
const hosts = ["0.0.0.0", "localhost", "127.0.0.1", "local-ip", "local-ipv4"];
const ipv4 = internalIp.v4.sync();
const ipv6 = internalIp.v6.sync();
// macos requires root for using ip v6
const isMacOS = process.platform === "darwin";

for (const host of hosts) {
describe("host and port", () => {
const hosts = [
"0.0.0.0",
"::",
"localhost",
"::1",
"127.0.0.1",
"local-ip",
"local-ipv4",
"local-ipv6",
];

for (let 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 server = new Server({ host, port }, compiler);

let hostname = host;

if (hostname === "0.0.0.0") {
hostname = "127.0.0.1";
} else if (hostname === "::" || hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = internalIp.v4.sync();
hostname = ipv4;
} else if (hostname === "local-ipv6") {
hostname = `[${ipv6}]`;
}

await server.start();
Expand Down Expand Up @@ -55,14 +83,29 @@ describe("host and port", () => {

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 server = new Server({ host, port: `${port}` }, compiler);

let hostname = host;

if (hostname === "0.0.0.0") {
hostname = "127.0.0.1";
} else if (hostname === "::" || hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = internalIp.v4.sync();
hostname = ipv4;
} else if (hostname === "local-ipv6") {
hostname = `[${ipv6}]`;
}

await server.start();
Expand Down Expand Up @@ -99,14 +142,28 @@ describe("host and port", () => {

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 server = new Server({ host, port: "auto" }, compiler);

let hostname = host;

if (hostname === "0.0.0.0") {
hostname = "127.0.0.1";
} else if (hostname === "::" || hostname === "::1") {
hostname = "[::1]";
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
hostname = internalIp.v4.sync();
hostname = ipv4;
} else if (hostname === "local-ipv6") {
hostname = `[${ipv6}]`;
}

await server.start();
Expand Down