Skip to content

Commit

Permalink
fix: schema for the host option (#3549)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jul 21, 2021
1 parent 0c07404 commit 7200d31
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
9 changes: 8 additions & 1 deletion bin/cli-flags.js
Expand Up @@ -349,10 +349,17 @@ module.exports = {
host: {
configs: [
{
type: "string",
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "enum",
values: ["local-ip", "local-ipv4", "local-ipv6"],
},
{
description: "Allows to specify a hostname to use.",
multiple: false,
path: "host",
type: "string",
},
],
description: "Allows to specify a hostname to use.",
Expand Down
13 changes: 10 additions & 3 deletions lib/options.json
Expand Up @@ -283,10 +283,17 @@
"link": "https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback"
},
"Host": {
"type": "string",
"minLength": 1,
"description": "Allows to specify a hostname to use.",
"link": "https://webpack.js.org/configuration/dev-server/#devserverhost"
"link": "https://webpack.js.org/configuration/dev-server/#devserverhost",
"anyOf": [
{
"enum": ["local-ip", "local-ipv4", "local-ipv6"]
},
{
"type": "string",
"minLength": 1
}
]
},
"Hot": {
"anyOf": [
Expand Down
22 changes: 15 additions & 7 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Expand Up @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
- options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" 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.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" 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.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down
22 changes: 15 additions & 7 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Expand Up @@ -258,23 +258,31 @@ exports[`options validate should throw an error on the "historyApiFallback" opti

exports[`options validate should throw an error on the "host" option with '' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.host should be a non-empty string.
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
- options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" 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.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "host" 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.host should be a non-empty string.
- options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\" | non-empty string
-> Allows to specify a hostname to use.
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost"
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverhost
Details:
* options.host should be one of these:
\\"local-ip\\" | \\"local-ipv4\\" | \\"local-ipv6\\"
* options.host should be a non-empty string."
`;

exports[`options validate should throw an error on the "hot" option with '' value 1`] = `
Expand Down

0 comments on commit 7200d31

Please sign in to comment.