Skip to content

Commit

Permalink
fix: handle 0 value of the port option property
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 15, 2021
1 parent 772f6aa commit ed67f66
Show file tree
Hide file tree
Showing 16 changed files with 994 additions and 1,062 deletions.
2 changes: 1 addition & 1 deletion lib/Server.js
Expand Up @@ -74,7 +74,7 @@ class Server {
}

static async getFreePort(port) {
if (port && port !== "auto") {
if (typeof port !== "undefined" && port !== null && port !== "auto") {
return port;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/options.json
Expand Up @@ -554,7 +554,9 @@
"Port": {
"anyOf": [
{
"type": "number"
"type": "number",
"minimum": 0,
"maximum": 65535
},
{
"type": "string",
Expand Down
18 changes: 14 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Expand Up @@ -517,26 +517,36 @@ exports[`options validate should throw an error on the "port" option with '' val
- options.port should be a non-empty string."
`;

exports[`options validate should throw an error on the "port" option with '-1' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be >= 0 and <= 65535."
`;

exports[`options validate should throw an error on the "port" option with '65536' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be >= 0 and <= 65535."
`;

exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be one of these:
number | non-empty string | \\"auto\\"
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
-> Allows to specify a port to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* options.port should be a number.
* options.port should be a number (should be >= 0 and <= 65535).
* options.port should be a non-empty string.
* options.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be one of these:
number | non-empty string | \\"auto\\"
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
-> Allows to specify a port to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* options.port should be a number.
* options.port should be a number (should be >= 0 and <= 65535).
* options.port should be a non-empty string.
* options.port should be \\"auto\\"."
`;
Expand Down
18 changes: 14 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Expand Up @@ -517,26 +517,36 @@ exports[`options validate should throw an error on the "port" option with '' val
- options.port should be a non-empty string."
`;

exports[`options validate should throw an error on the "port" option with '-1' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be >= 0 and <= 65535."
`;

exports[`options validate should throw an error on the "port" option with '65536' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be >= 0 and <= 65535."
`;

exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be one of these:
number | non-empty string | \\"auto\\"
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
-> Allows to specify a port to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* options.port should be a number.
* options.port should be a number (should be >= 0 and <= 65535).
* options.port should be a non-empty string.
* options.port should be \\"auto\\"."
`;

exports[`options validate should throw an error on the "port" option with 'null' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.port should be one of these:
number | non-empty string | \\"auto\\"
number (should be >= 0 and <= 65535) | non-empty string | \\"auto\\"
-> Allows to specify a port to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverport
Details:
* options.port should be a number.
* options.port should be a number (should be >= 0 and <= 65535).
* options.port should be a non-empty string.
* options.port should be \\"auto\\"."
`;
Expand Down
265 changes: 0 additions & 265 deletions test/e2e/__snapshots__/host-and-port.test.js.snap.webpack4

This file was deleted.

0 comments on commit ed67f66

Please sign in to comment.