Skip to content

Commit 4eb1ab8

Browse files
test: fix todo (#3713)
1 parent 7c4ab53 commit 4eb1ab8

File tree

3 files changed

+262
-7
lines changed

3 files changed

+262
-7
lines changed

test/e2e/__snapshots__/host-and-port.test.js.snap.webpack4

+99
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`host and port should work using "::" host and "auto" port: console messages 1`] = `
4+
Array [
5+
"[HMR] Waiting for update signal from WDS...",
6+
"Hey.",
7+
"[webpack-dev-server] Hot Module Replacement enabled.",
8+
"[webpack-dev-server] Live Reloading enabled.",
9+
]
10+
`;
11+
12+
exports[`host and port should work using "::" host and "auto" port: page errors 1`] = `Array []`;
13+
14+
exports[`host and port should work using "::" host and port as number: console messages 1`] = `
15+
Array [
16+
"[HMR] Waiting for update signal from WDS...",
17+
"Hey.",
18+
"[webpack-dev-server] Hot Module Replacement enabled.",
19+
"[webpack-dev-server] Live Reloading enabled.",
20+
]
21+
`;
22+
23+
exports[`host and port should work using "::" host and port as number: page errors 1`] = `Array []`;
24+
25+
exports[`host and port should work using "::" host and port as string: console messages 1`] = `
26+
Array [
27+
"[HMR] Waiting for update signal from WDS...",
28+
"Hey.",
29+
"[webpack-dev-server] Hot Module Replacement enabled.",
30+
"[webpack-dev-server] Live Reloading enabled.",
31+
]
32+
`;
33+
34+
exports[`host and port should work using "::" host and port as string: page errors 1`] = `Array []`;
35+
36+
exports[`host and port should work using "::1" host and "auto" port: console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"Hey.",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
"[webpack-dev-server] Live Reloading enabled.",
42+
]
43+
`;
44+
45+
exports[`host and port should work using "::1" host and "auto" port: page errors 1`] = `Array []`;
46+
47+
exports[`host and port should work using "::1" host and port as number: console messages 1`] = `
48+
Array [
49+
"[HMR] Waiting for update signal from WDS...",
50+
"Hey.",
51+
"[webpack-dev-server] Hot Module Replacement enabled.",
52+
"[webpack-dev-server] Live Reloading enabled.",
53+
]
54+
`;
55+
56+
exports[`host and port should work using "::1" host and port as number: page errors 1`] = `Array []`;
57+
58+
exports[`host and port should work using "::1" host and port as string: console messages 1`] = `
59+
Array [
60+
"[HMR] Waiting for update signal from WDS...",
61+
"Hey.",
62+
"[webpack-dev-server] Hot Module Replacement enabled.",
63+
"[webpack-dev-server] Live Reloading enabled.",
64+
]
65+
`;
66+
67+
exports[`host and port should work using "::1" host and port as string: page errors 1`] = `Array []`;
68+
369
exports[`host and port should work using "0.0.0.0" host and "auto" port: console messages 1`] = `
470
Array [
571
"[HMR] Waiting for update signal from WDS...",
@@ -132,6 +198,39 @@ Array [
132198

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

201+
exports[`host and port should work using "local-ipv6" host and "auto" port: console messages 1`] = `
202+
Array [
203+
"[HMR] Waiting for update signal from WDS...",
204+
"Hey.",
205+
"[webpack-dev-server] Hot Module Replacement enabled.",
206+
"[webpack-dev-server] Live Reloading enabled.",
207+
]
208+
`;
209+
210+
exports[`host and port should work using "local-ipv6" host and "auto" port: page errors 1`] = `Array []`;
211+
212+
exports[`host and port should work using "local-ipv6" host and port as number: console messages 1`] = `
213+
Array [
214+
"[HMR] Waiting for update signal from WDS...",
215+
"Hey.",
216+
"[webpack-dev-server] Hot Module Replacement enabled.",
217+
"[webpack-dev-server] Live Reloading enabled.",
218+
]
219+
`;
220+
221+
exports[`host and port should work using "local-ipv6" host and port as number: page errors 1`] = `Array []`;
222+
223+
exports[`host and port should work using "local-ipv6" host and port as string: console messages 1`] = `
224+
Array [
225+
"[HMR] Waiting for update signal from WDS...",
226+
"Hey.",
227+
"[webpack-dev-server] Hot Module Replacement enabled.",
228+
"[webpack-dev-server] Live Reloading enabled.",
229+
]
230+
`;
231+
232+
exports[`host and port should work using "local-ipv6" host and port as string: page errors 1`] = `Array []`;
233+
135234
exports[`host and port should work using "localhost" host and "auto" port: console messages 1`] = `
136235
Array [
137236
"[HMR] Waiting for update signal from WDS...",

test/e2e/__snapshots__/host-and-port.test.js.snap.webpack5

+99
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`host and port should work using "::" host and "auto" port: console messages 1`] = `
4+
Array [
5+
"[HMR] Waiting for update signal from WDS...",
6+
"Hey.",
7+
"[webpack-dev-server] Hot Module Replacement enabled.",
8+
"[webpack-dev-server] Live Reloading enabled.",
9+
]
10+
`;
11+
12+
exports[`host and port should work using "::" host and "auto" port: page errors 1`] = `Array []`;
13+
14+
exports[`host and port should work using "::" host and port as number: console messages 1`] = `
15+
Array [
16+
"[HMR] Waiting for update signal from WDS...",
17+
"Hey.",
18+
"[webpack-dev-server] Hot Module Replacement enabled.",
19+
"[webpack-dev-server] Live Reloading enabled.",
20+
]
21+
`;
22+
23+
exports[`host and port should work using "::" host and port as number: page errors 1`] = `Array []`;
24+
25+
exports[`host and port should work using "::" host and port as string: console messages 1`] = `
26+
Array [
27+
"[HMR] Waiting for update signal from WDS...",
28+
"Hey.",
29+
"[webpack-dev-server] Hot Module Replacement enabled.",
30+
"[webpack-dev-server] Live Reloading enabled.",
31+
]
32+
`;
33+
34+
exports[`host and port should work using "::" host and port as string: page errors 1`] = `Array []`;
35+
36+
exports[`host and port should work using "::1" host and "auto" port: console messages 1`] = `
37+
Array [
38+
"[HMR] Waiting for update signal from WDS...",
39+
"Hey.",
40+
"[webpack-dev-server] Hot Module Replacement enabled.",
41+
"[webpack-dev-server] Live Reloading enabled.",
42+
]
43+
`;
44+
45+
exports[`host and port should work using "::1" host and "auto" port: page errors 1`] = `Array []`;
46+
47+
exports[`host and port should work using "::1" host and port as number: console messages 1`] = `
48+
Array [
49+
"[HMR] Waiting for update signal from WDS...",
50+
"Hey.",
51+
"[webpack-dev-server] Hot Module Replacement enabled.",
52+
"[webpack-dev-server] Live Reloading enabled.",
53+
]
54+
`;
55+
56+
exports[`host and port should work using "::1" host and port as number: page errors 1`] = `Array []`;
57+
58+
exports[`host and port should work using "::1" host and port as string: console messages 1`] = `
59+
Array [
60+
"[HMR] Waiting for update signal from WDS...",
61+
"Hey.",
62+
"[webpack-dev-server] Hot Module Replacement enabled.",
63+
"[webpack-dev-server] Live Reloading enabled.",
64+
]
65+
`;
66+
67+
exports[`host and port should work using "::1" host and port as string: page errors 1`] = `Array []`;
68+
369
exports[`host and port should work using "0.0.0.0" host and "auto" port: console messages 1`] = `
470
Array [
571
"[HMR] Waiting for update signal from WDS...",
@@ -132,6 +198,39 @@ Array [
132198

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

201+
exports[`host and port should work using "local-ipv6" host and "auto" port: console messages 1`] = `
202+
Array [
203+
"[HMR] Waiting for update signal from WDS...",
204+
"Hey.",
205+
"[webpack-dev-server] Hot Module Replacement enabled.",
206+
"[webpack-dev-server] Live Reloading enabled.",
207+
]
208+
`;
209+
210+
exports[`host and port should work using "local-ipv6" host and "auto" port: page errors 1`] = `Array []`;
211+
212+
exports[`host and port should work using "local-ipv6" host and port as number: console messages 1`] = `
213+
Array [
214+
"[HMR] Waiting for update signal from WDS...",
215+
"Hey.",
216+
"[webpack-dev-server] Hot Module Replacement enabled.",
217+
"[webpack-dev-server] Live Reloading enabled.",
218+
]
219+
`;
220+
221+
exports[`host and port should work using "local-ipv6" host and port as number: page errors 1`] = `Array []`;
222+
223+
exports[`host and port should work using "local-ipv6" host and port as string: console messages 1`] = `
224+
Array [
225+
"[HMR] Waiting for update signal from WDS...",
226+
"Hey.",
227+
"[webpack-dev-server] Hot Module Replacement enabled.",
228+
"[webpack-dev-server] Live Reloading enabled.",
229+
]
230+
`;
231+
232+
exports[`host and port should work using "local-ipv6" host and port as string: page errors 1`] = `Array []`;
233+
135234
exports[`host and port should work using "localhost" host and "auto" port: console messages 1`] = `
136235
Array [
137236
"[HMR] Waiting for update signal from WDS...",

test/e2e/host-and-port.test.js

+64-7
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,49 @@ const config = require("../fixtures/client-config/webpack.config");
77
const runBrowser = require("../helpers/run-browser");
88
const port = require("../ports-map")["host-and-port"];
99

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

14-
for (const host of hosts) {
15+
describe("host and port", () => {
16+
const hosts = [
17+
"0.0.0.0",
18+
"::",
19+
"localhost",
20+
"::1",
21+
"127.0.0.1",
22+
"local-ip",
23+
"local-ipv4",
24+
"local-ipv6",
25+
];
26+
27+
for (let host of hosts) {
1528
it(`should work using "${host}" host and port as number`, async () => {
1629
const compiler = webpack(config);
30+
31+
if (!ipv6 || isMacOS) {
32+
if (host === "::") {
33+
host = "127.0.0.1";
34+
} else if (host === "::1") {
35+
host = "127.0.0.1";
36+
} else if (host === "local-ipv6") {
37+
host = "127.0.0.1";
38+
}
39+
}
40+
1741
const server = new Server({ host, port }, compiler);
1842

1943
let hostname = host;
2044

2145
if (hostname === "0.0.0.0") {
2246
hostname = "127.0.0.1";
47+
} else if (hostname === "::" || hostname === "::1") {
48+
hostname = "[::1]";
2349
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
24-
hostname = internalIp.v4.sync();
50+
hostname = ipv4;
51+
} else if (hostname === "local-ipv6") {
52+
hostname = `[${ipv6}]`;
2553
}
2654

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

5684
it(`should work using "${host}" host and port as string`, async () => {
5785
const compiler = webpack(config);
86+
87+
if (!ipv6 || isMacOS) {
88+
if (host === "::") {
89+
host = "127.0.0.1";
90+
} else if (host === "::1") {
91+
host = "127.0.0.1";
92+
} else if (host === "local-ipv6") {
93+
host = "127.0.0.1";
94+
}
95+
}
96+
5897
const server = new Server({ host, port: `${port}` }, compiler);
5998

6099
let hostname = host;
61100

62101
if (hostname === "0.0.0.0") {
63102
hostname = "127.0.0.1";
103+
} else if (hostname === "::" || hostname === "::1") {
104+
hostname = "[::1]";
64105
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
65-
hostname = internalIp.v4.sync();
106+
hostname = ipv4;
107+
} else if (hostname === "local-ipv6") {
108+
hostname = `[${ipv6}]`;
66109
}
67110

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

100143
process.env.WEBPACK_DEV_SERVER_BASE_PORT = port;
101144

145+
if (!ipv6 || isMacOS) {
146+
if (host === "::") {
147+
host = "127.0.0.1";
148+
} else if (host === "::1") {
149+
host = "127.0.0.1";
150+
} else if (host === "local-ipv6") {
151+
host = "127.0.0.1";
152+
}
153+
}
154+
102155
const server = new Server({ host, port: "auto" }, compiler);
103156

104157
let hostname = host;
105158

106159
if (hostname === "0.0.0.0") {
107160
hostname = "127.0.0.1";
161+
} else if (hostname === "::" || hostname === "::1") {
162+
hostname = "[::1]";
108163
} else if (hostname === "local-ip" || hostname === "local-ipv4") {
109-
hostname = internalIp.v4.sync();
164+
hostname = ipv4;
165+
} else if (hostname === "local-ipv6") {
166+
hostname = `[${ipv6}]`;
110167
}
111168

112169
await server.start();

0 commit comments

Comments
 (0)