Skip to content

Commit f8f5fd5

Browse files
committed
test: updates
1 parent d5597ea commit f8f5fd5

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

lib/Server.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,15 @@ class Server {
726726
}
727727

728728
listen(port, hostname, fn) {
729-
this.hostname = hostname;
729+
if (hostname === 'local-ip') {
730+
this.hostname = internalIp.v4.sync() || internalIp.v6.sync();
731+
} else if (hostname === 'local-ipv4') {
732+
this.hostname = internalIp.v4.sync();
733+
} else if (hostname === 'local-ipv6') {
734+
this.hostname = internalIp.v6.sync();
735+
} else {
736+
this.hostname = hostname;
737+
}
730738

731739
if (typeof port !== 'undefined' && port !== this.options.port) {
732740
this.logger.warn(
@@ -739,8 +747,7 @@ class Server {
739747
// eslint-disable-next-line no-shadow
740748
.then((port) => {
741749
this.port = port;
742-
743-
return this.server.listen(port, hostname, (err) => {
750+
return this.server.listen(port, this.hostname, (err) => {
744751
if (this.options.hot || this.options.liveReload) {
745752
this.createSocketServer();
746753
}

test/cli/__snapshots__/cli.test.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ exports[`CLI --host <IPv4>: stderr 1`] = `
1717
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
1818
`;
1919
20+
exports[`CLI --host <local-ip>: stderr 1`] = `
21+
"<i> [webpack-dev-server] Project is running at http://<network-ip-v4>:<port>/ (IPv4)
22+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
23+
`;
24+
25+
exports[`CLI --host <local-ipv4>: stderr 1`] = `
26+
"<i> [webpack-dev-server] Project is running at http://<network-ip-v4>:<port>/ (IPv4)
27+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
28+
`;
29+
2030
exports[`CLI --host 0.0.0.0 (IPv4): stderr 1`] = `
2131
"<i> [webpack-dev-server] Project is running at:
2232
<i> [webpack-dev-server] Local: http://localhost:<port>/

test/cli/cli.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,36 @@ describe('CLI', () => {
188188
.catch(done);
189189
});
190190

191+
it('--host <local-ip>', (done) => {
192+
testBin('--host local-ip')
193+
.then((output) => {
194+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
195+
196+
done();
197+
})
198+
.catch(done);
199+
});
200+
201+
it('--host <local-ipv4>', (done) => {
202+
testBin('--host local-ipv4')
203+
.then((output) => {
204+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
205+
206+
done();
207+
})
208+
.catch(done);
209+
});
210+
211+
it.skip('--host <local-ipv6>', (done) => {
212+
testBin('--host local-ipv6')
213+
.then((output) => {
214+
expect(normalizeStderr(output.stderr)).toMatchSnapshot('stderr');
215+
216+
done();
217+
})
218+
.catch(done);
219+
});
220+
191221
it('--host localhost --port 9999', (done) => {
192222
testBin('--host localhost --port 9999')
193223
.then((output) => {

0 commit comments

Comments
 (0)