Skip to content

Commit

Permalink
fix: output description on errors for nested properties (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Apr 8, 2021
1 parent acd7c1e commit 23331e2
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"minItems": 1
}
]
],
"description": "The bundled files will be available in the browser under this path."
},
"serveIndex": {
"anyOf": [
Expand All @@ -38,7 +39,8 @@
"type": "object",
"additionalProperties": true
}
]
],
"description": "Tells dev-server to use serveIndex middleware when enabled."
},
"watch": {
"anyOf": [
Expand Down Expand Up @@ -84,7 +86,8 @@
},
"minItems": 1
}
]
],
"description": "Open specified route in browser."
},
"app": {
"anyOf": [
Expand All @@ -100,7 +103,8 @@
},
"minItems": 1
}
]
],
"description": "Open specified browser."
}
}
},
Expand Down
61 changes: 61 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,43 @@ exports[`options validate should throw an error on the "open" option with '[]' v
- configuration.open should be an non-empty array."
`;

exports[`options validate should throw an error on the "open" option with '{"app":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open should be one of these:
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
-> Tells dev-server to open the browser after server had been started. Set it to true to open your default browser. https://webpack.js.org/configuration/dev-server/#devserveropen
Details:
* configuration.open.app should be one of these:
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> Open specified browser.
Details:
* configuration.open.app should be a non-empty string.
* configuration.open.app should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

exports[`options validate should throw an error on the "open" option with '{"foo":"bar"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open has an unknown property 'foo'. These properties are valid:
object { target?, app? }"
`;

exports[`options validate should throw an error on the "open" option with '{"target":90}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open should be one of these:
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
-> Tells dev-server to open the browser after server had been started. Set it to true to open your default browser. https://webpack.js.org/configuration/dev-server/#devserveropen
Details:
* configuration.open.target should be one of these:
boolean | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> Open specified route in browser.
Details:
* configuration.open.target should be a boolean.
* configuration.open.target should be a non-empty string.
* configuration.open.target should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

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:
Expand Down Expand Up @@ -272,6 +303,36 @@ exports[`options validate should throw an error on the "static" option with '' v
- configuration.static should be an non-empty string."
`;

exports[`options validate should throw an error on the "static" option with '{"publicPath":false}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
boolean | non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? } | [non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }, ...] (should not have fewer than 1 item)
-> It is possible to configure advanced options for serving static files from directory. See the Express documentation for the possible options. https://webpack.js.org/configuration/dev-server/#devserverstatic
Details:
* configuration.static.publicPath should be one of these:
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> The bundled files will be available in the browser under this path.
Details:
* configuration.static.publicPath should be a non-empty string.
* configuration.static.publicPath should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

exports[`options validate should throw an error on the "static" option with '{"serveIndex":"true"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
boolean | non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? } | [non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }, ...] (should not have fewer than 1 item)
-> It is possible to configure advanced options for serving static files from directory. See the Express documentation for the possible options. https://webpack.js.org/configuration/dev-server/#devserverstatic
Details:
* configuration.static.serveIndex should be one of these:
boolean | object { … }
-> Tells dev-server to use serveIndex middleware when enabled.
Details:
* configuration.static.serveIndex should be a boolean.
* configuration.static.serveIndex should be an object:
object { … }"
`;

exports[`options validate should throw an error on the "static" option with '0' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
Expand Down
61 changes: 61 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,43 @@ exports[`options validate should throw an error on the "open" option with '[]' v
- configuration.open should be an non-empty array."
`;

exports[`options validate should throw an error on the "open" option with '{"app":true}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open should be one of these:
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
-> Tells dev-server to open the browser after server had been started. Set it to true to open your default browser. https://webpack.js.org/configuration/dev-server/#devserveropen
Details:
* configuration.open.app should be one of these:
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> Open specified browser.
Details:
* configuration.open.app should be a non-empty string.
* configuration.open.app should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

exports[`options validate should throw an error on the "open" option with '{"foo":"bar"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open has an unknown property 'foo'. These properties are valid:
object { target?, app? }"
`;

exports[`options validate should throw an error on the "open" option with '{"target":90}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.open should be one of these:
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
-> Tells dev-server to open the browser after server had been started. Set it to true to open your default browser. https://webpack.js.org/configuration/dev-server/#devserveropen
Details:
* configuration.open.target should be one of these:
boolean | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> Open specified route in browser.
Details:
* configuration.open.target should be a boolean.
* configuration.open.target should be a non-empty string.
* configuration.open.target should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

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:
Expand Down Expand Up @@ -272,6 +303,36 @@ exports[`options validate should throw an error on the "static" option with '' v
- configuration.static should be an non-empty string."
`;

exports[`options validate should throw an error on the "static" option with '{"publicPath":false}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
boolean | non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? } | [non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }, ...] (should not have fewer than 1 item)
-> It is possible to configure advanced options for serving static files from directory. See the Express documentation for the possible options. https://webpack.js.org/configuration/dev-server/#devserverstatic
Details:
* configuration.static.publicPath should be one of these:
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
-> The bundled files will be available in the browser under this path.
Details:
* configuration.static.publicPath should be a non-empty string.
* configuration.static.publicPath should be an array:
[non-empty string, ...] (should not have fewer than 1 item)"
`;

exports[`options validate should throw an error on the "static" option with '{"serveIndex":"true"}' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
boolean | non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? } | [non-empty string | object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }, ...] (should not have fewer than 1 item)
-> It is possible to configure advanced options for serving static files from directory. See the Express documentation for the possible options. https://webpack.js.org/configuration/dev-server/#devserverstatic
Details:
* configuration.static.serveIndex should be one of these:
boolean | object { … }
-> Tells dev-server to use serveIndex middleware when enabled.
Details:
* configuration.static.serveIndex should be a boolean.
* configuration.static.serveIndex should be an object:
object { … }"
`;

exports[`options validate should throw an error on the "static" option with '0' value 1`] = `
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
- configuration.static should be one of these:
Expand Down
14 changes: 12 additions & 2 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const tests = {
{ target: ['foo', 'bar'], app: ['google-chrome', '--incognito'] },
{},
],
failure: ['', [], { foo: 'bar' }],
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
},
port: {
success: ['', 0, null],
Expand Down Expand Up @@ -267,7 +267,17 @@ const tests = {
},
],
],
failure: [0, null, ''],
failure: [
0,
null,
'',
{
publicPath: false,
},
{
serveIndex: 'true',
},
],
},
transportMode: {
success: [
Expand Down

0 comments on commit 23331e2

Please sign in to comment.