Skip to content

Commit

Permalink
feat: add port "auto" and remove port: null (#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed May 15, 2021
1 parent 670966f commit 437c8d3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/options.json
Expand Up @@ -174,7 +174,7 @@
"type": "string"
},
{
"type": "null"
"enum": ["auto"]
}
],
"description": "Tells clients connected to devServer to use the provided port."
Expand Down Expand Up @@ -424,7 +424,7 @@
"type": "string"
},
{
"type": "null"
"enum": ["auto"]
}
],
"description": "Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport"
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/findPort.js
Expand Up @@ -18,7 +18,7 @@ function runPortFinder() {
}

function findPort(port) {
if (port) {
if (port && port !== 'auto') {
return Promise.resolve(port);
}

Expand Down
19 changes: 15 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Expand Up @@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.client.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Tells clients connected to devServer to use the provided port.
Details:
* configuration.client.port should be a number.
* configuration.client.port should be a string.
* configuration.client.port should be a null."
* configuration.client.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
Expand Down Expand Up @@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be a null."
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `
Expand Down
19 changes: 15 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Expand Up @@ -82,12 +82,12 @@ exports[`options validate should throw an error on the "client" option with '{"p
exports[`options validate should throw an error on the "client" option with '{"port":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.client.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Tells clients connected to devServer to use the provided port.
Details:
* configuration.client.port should be a number.
* configuration.client.port should be a string.
* configuration.client.port should be a null."
* configuration.client.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "client" option with '{"progress":""}' value 1`] = `
Expand Down Expand Up @@ -361,12 +361,23 @@ exports[`options validate should throw an error on the "open" option with '{"tar
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | null
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be a null."
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.port should be one of these:
number | string | \\"auto\\"
-> Specify a port number to listen for requests on. https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* configuration.port should be a number.
* configuration.port should be a string.
* configuration.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "proxy" option with '[]' value 1`] = `
Expand Down
4 changes: 2 additions & 2 deletions test/server/port-option.test.js
Expand Up @@ -78,7 +78,7 @@ describe('port', () => {
afterAll(testServer.close);
});

describe('is null', () => {
describe('is auto', () => {
beforeAll((done) => {
server = testServer.start(
config,
Expand All @@ -87,7 +87,7 @@ describe('port', () => {
directory: staticDirectory,
watch: false,
},
port: null,
port: 'auto',
},
done
);
Expand Down
6 changes: 3 additions & 3 deletions test/validate-options.test.js
Expand Up @@ -70,7 +70,7 @@ const tests = {
{
host: '',
path: '',
port: null,
port: 'auto',
},
{
progress: false,
Expand Down Expand Up @@ -247,8 +247,8 @@ const tests = {
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
},
port: {
success: ['', 0, null],
failure: [false],
success: ['', 0, 'auto'],
failure: [false, null],
},
proxy: {
success: [
Expand Down

0 comments on commit 437c8d3

Please sign in to comment.