Skip to content

Commit 1fafc69

Browse files
Merge remote-tracking branch 'origin/refactor-client-and-server-transport-mode-options' into refactor-client-and-server-transport-mode-options
2 parents c2a4403 + e57809e commit 1fafc69

File tree

7 files changed

+105
-18
lines changed

7 files changed

+105
-18
lines changed

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
"type": "string"
226226
},
227227
{
228-
"type": "null"
228+
"enum": ["auto"]
229229
}
230230
],
231231
"description": "Tells clients connected to devServer to use the provided path to connect."
@@ -492,7 +492,7 @@
492492
"type": "string"
493493
},
494494
{
495-
"type": "null"
495+
"enum": ["auto"]
496496
}
497497
],
498498
"description": "Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport"

lib/utils/findPort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function runPortFinder() {
1818
}
1919

2020
function findPort(port) {
21-
if (port) {
21+
if (port && port !== 'auto') {
2222
return Promise.resolve(port);
2323
}
2424

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
8282
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
8383
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
8484
- configuration.client.port should be one of these:
85-
number | string | null
86-
-> Tells clients connected to devServer to use the provided path to connect.
85+
number | string | \\"auto\\"
86+
-> Tells clients connected to devServer to use the provided port.
8787
Details:
8888
* configuration.client.port should be a number.
8989
* configuration.client.port should be a string.
90-
* configuration.client.port should be a null."
90+
* configuration.client.port should be \\"auto\\"."
9191
`;
9292

9393
exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
@@ -372,12 +372,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
372372
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
373373
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
374374
- configuration.port should be one of these:
375-
number | string | null
375+
number | string | \\"auto\\"
376376
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
377377
Details:
378378
* configuration.port should be a number.
379379
* configuration.port should be a string.
380-
* configuration.port should be a null."
380+
* configuration.port should be \\"auto\\"."
381+
`;
382+
383+
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
384+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
385+
- configuration.port should be one of these:
386+
number | string | \\"auto\\"
387+
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
388+
Details:
389+
* configuration.port should be a number.
390+
* configuration.port should be a string.
391+
* configuration.port should be \\"auto\\"."
381392
`;
382393

383394
exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
8282
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
8383
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
8484
- configuration.client.port should be one of these:
85-
number | string | null
86-
-> Tells clients connected to devServer to use the provided path to connect.
85+
number | string | \\"auto\\"
86+
-> Tells clients connected to devServer to use the provided port.
8787
Details:
8888
* configuration.client.port should be a number.
8989
* configuration.client.port should be a string.
90-
* configuration.client.port should be a null."
90+
* configuration.client.port should be \\"auto\\"."
9191
`;
9292

9393
exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
@@ -372,12 +372,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
372372
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
373373
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
374374
- configuration.port should be one of these:
375-
number | string | null
375+
number | string | \\"auto\\"
376376
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
377377
Details:
378378
* configuration.port should be a number.
379379
* configuration.port should be a string.
380-
* configuration.port should be a null."
380+
* configuration.port should be \\"auto\\"."
381+
`;
382+
383+
exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
384+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
385+
- configuration.port should be one of these:
386+
number | string | \\"auto\\"
387+
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
388+
Details:
389+
* configuration.port should be a number.
390+
* configuration.port should be a string.
391+
* configuration.port should be \\"auto\\"."
381392
`;
382393

383394
exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `

test/server/host-option.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require('path');
44
const request = require('supertest');
5+
const internalIp = require('internal-ip');
56
const config = require('../fixtures/simple-config/webpack.config');
67
const testServer = require('../helpers/test-server');
78
const port = require('../ports-map')['host-option'];
@@ -200,4 +201,68 @@ describe('host option', () => {
200201

201202
afterAll(testServer.close);
202203
});
204+
205+
describe('is local-ip', () => {
206+
beforeAll((done) => {
207+
server = testServer.start(
208+
config,
209+
{
210+
static: {
211+
directory: staticDirectory,
212+
watch: false,
213+
},
214+
host: 'local-ip',
215+
port,
216+
},
217+
done
218+
);
219+
req = request(server.app);
220+
});
221+
222+
it('server address', () => {
223+
const address = server.server.address();
224+
const networkIP = internalIp.v4.sync();
225+
226+
expect(address.address).toBe(networkIP);
227+
expect(address.port).toBe(port);
228+
});
229+
230+
it('Request to index', (done) => {
231+
req.get('/').expect(200, done);
232+
});
233+
234+
afterAll(testServer.close);
235+
});
236+
237+
describe('is local-ipv4', () => {
238+
beforeAll((done) => {
239+
server = testServer.start(
240+
config,
241+
{
242+
static: {
243+
directory: staticDirectory,
244+
watch: false,
245+
},
246+
host: 'local-ipv4',
247+
port,
248+
},
249+
done
250+
);
251+
req = request(server.app);
252+
});
253+
254+
it('server address', () => {
255+
const address = server.server.address();
256+
const networkIP = internalIp.v4.sync();
257+
258+
expect(address.address).toBe(networkIP);
259+
expect(address.port).toBe(port);
260+
});
261+
262+
it('Request to index', (done) => {
263+
req.get('/').expect(200, done);
264+
});
265+
266+
afterAll(testServer.close);
267+
});
203268
});

test/server/port-option.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('port', () => {
7878
afterAll(testServer.close);
7979
});
8080

81-
describe('is null', () => {
81+
describe('is auto', () => {
8282
beforeAll((done) => {
8383
server = testServer.start(
8484
config,
@@ -87,7 +87,7 @@ describe('port', () => {
8787
directory: staticDirectory,
8888
watch: false,
8989
},
90-
port: null,
90+
port: 'auto',
9191
},
9292
done
9393
);

test/validate-options.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const tests = {
6969
{
7070
host: '',
7171
path: '',
72-
port: null,
72+
port: 'auto',
7373
},
7474
{
7575
progress: false,
@@ -255,8 +255,8 @@ const tests = {
255255
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
256256
},
257257
port: {
258-
success: ['', 0, null],
259-
failure: [false],
258+
success: ['', 0, 'auto'],
259+
failure: [false, null],
260260
},
261261
proxy: {
262262
success: [

0 commit comments

Comments
 (0)