Skip to content

Commit 23331e2

Browse files
authored
fix: output description on errors for nested properties (#3166)
1 parent acd7c1e commit 23331e2

File tree

4 files changed

+142
-6
lines changed

4 files changed

+142
-6
lines changed

lib/options.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"minItems": 1
2929
}
30-
]
30+
],
31+
"description": "The bundled files will be available in the browser under this path."
3132
},
3233
"serveIndex": {
3334
"anyOf": [
@@ -38,7 +39,8 @@
3839
"type": "object",
3940
"additionalProperties": true
4041
}
41-
]
42+
],
43+
"description": "Tells dev-server to use serveIndex middleware when enabled."
4244
},
4345
"watch": {
4446
"anyOf": [
@@ -84,7 +86,8 @@
8486
},
8587
"minItems": 1
8688
}
87-
]
89+
],
90+
"description": "Open specified route in browser."
8891
},
8992
"app": {
9093
"anyOf": [
@@ -100,7 +103,8 @@
100103
},
101104
"minItems": 1
102105
}
103-
]
106+
],
107+
"description": "Open specified browser."
104108
}
105109
}
106110
},

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

+61
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,43 @@ exports[`options validate should throw an error on the "open" option with '[]' v
215215
- configuration.open should be an non-empty array."
216216
`;
217217

218+
exports[`options validate should throw an error on the "open" option with '{"app":true}' value 1`] = `
219+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
220+
- configuration.open should be one of these:
221+
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
222+
-> 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
223+
Details:
224+
* configuration.open.app should be one of these:
225+
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
226+
-> Open specified browser.
227+
Details:
228+
* configuration.open.app should be a non-empty string.
229+
* configuration.open.app should be an array:
230+
[non-empty string, ...] (should not have fewer than 1 item)"
231+
`;
232+
218233
exports[`options validate should throw an error on the "open" option with '{"foo":"bar"}' value 1`] = `
219234
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
220235
- configuration.open has an unknown property 'foo'. These properties are valid:
221236
object { target?, app? }"
222237
`;
223238

239+
exports[`options validate should throw an error on the "open" option with '{"target":90}' value 1`] = `
240+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
241+
- configuration.open should be one of these:
242+
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
243+
-> 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
244+
Details:
245+
* configuration.open.target should be one of these:
246+
boolean | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
247+
-> Open specified route in browser.
248+
Details:
249+
* configuration.open.target should be a boolean.
250+
* configuration.open.target should be a non-empty string.
251+
* configuration.open.target should be an array:
252+
[non-empty string, ...] (should not have fewer than 1 item)"
253+
`;
254+
224255
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
225256
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
226257
- configuration.port should be one of these:
@@ -272,6 +303,36 @@ exports[`options validate should throw an error on the "static" option with '' v
272303
- configuration.static should be an non-empty string."
273304
`;
274305

306+
exports[`options validate should throw an error on the "static" option with '{"publicPath":false}' value 1`] = `
307+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
308+
- configuration.static should be one of these:
309+
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)
310+
-> 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
311+
Details:
312+
* configuration.static.publicPath should be one of these:
313+
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
314+
-> The bundled files will be available in the browser under this path.
315+
Details:
316+
* configuration.static.publicPath should be a non-empty string.
317+
* configuration.static.publicPath should be an array:
318+
[non-empty string, ...] (should not have fewer than 1 item)"
319+
`;
320+
321+
exports[`options validate should throw an error on the "static" option with '{"serveIndex":"true"}' value 1`] = `
322+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
323+
- configuration.static should be one of these:
324+
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)
325+
-> 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
326+
Details:
327+
* configuration.static.serveIndex should be one of these:
328+
boolean | object { … }
329+
-> Tells dev-server to use serveIndex middleware when enabled.
330+
Details:
331+
* configuration.static.serveIndex should be a boolean.
332+
* configuration.static.serveIndex should be an object:
333+
object { … }"
334+
`;
335+
275336
exports[`options validate should throw an error on the "static" option with '0' value 1`] = `
276337
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
277338
- configuration.static should be one of these:

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

+61
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,43 @@ exports[`options validate should throw an error on the "open" option with '[]' v
215215
- configuration.open should be an non-empty array."
216216
`;
217217

218+
exports[`options validate should throw an error on the "open" option with '{"app":true}' value 1`] = `
219+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
220+
- configuration.open should be one of these:
221+
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
222+
-> 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
223+
Details:
224+
* configuration.open.app should be one of these:
225+
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
226+
-> Open specified browser.
227+
Details:
228+
* configuration.open.app should be a non-empty string.
229+
* configuration.open.app should be an array:
230+
[non-empty string, ...] (should not have fewer than 1 item)"
231+
`;
232+
218233
exports[`options validate should throw an error on the "open" option with '{"foo":"bar"}' value 1`] = `
219234
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
220235
- configuration.open has an unknown property 'foo'. These properties are valid:
221236
object { target?, app? }"
222237
`;
223238

239+
exports[`options validate should throw an error on the "open" option with '{"target":90}' value 1`] = `
240+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
241+
- configuration.open should be one of these:
242+
boolean | non-empty string | object { target?, app? } | [non-empty string | object { target?, app? }, ...] (should not have fewer than 1 item)
243+
-> 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
244+
Details:
245+
* configuration.open.target should be one of these:
246+
boolean | non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
247+
-> Open specified route in browser.
248+
Details:
249+
* configuration.open.target should be a boolean.
250+
* configuration.open.target should be a non-empty string.
251+
* configuration.open.target should be an array:
252+
[non-empty string, ...] (should not have fewer than 1 item)"
253+
`;
254+
224255
exports[`options validate should throw an error on the "port" option with 'false' value 1`] = `
225256
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
226257
- configuration.port should be one of these:
@@ -272,6 +303,36 @@ exports[`options validate should throw an error on the "static" option with '' v
272303
- configuration.static should be an non-empty string."
273304
`;
274305

306+
exports[`options validate should throw an error on the "static" option with '{"publicPath":false}' value 1`] = `
307+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
308+
- configuration.static should be one of these:
309+
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)
310+
-> 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
311+
Details:
312+
* configuration.static.publicPath should be one of these:
313+
non-empty string | [non-empty string, ...] (should not have fewer than 1 item)
314+
-> The bundled files will be available in the browser under this path.
315+
Details:
316+
* configuration.static.publicPath should be a non-empty string.
317+
* configuration.static.publicPath should be an array:
318+
[non-empty string, ...] (should not have fewer than 1 item)"
319+
`;
320+
321+
exports[`options validate should throw an error on the "static" option with '{"serveIndex":"true"}' value 1`] = `
322+
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
323+
- configuration.static should be one of these:
324+
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)
325+
-> 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
326+
Details:
327+
* configuration.static.serveIndex should be one of these:
328+
boolean | object { … }
329+
-> Tells dev-server to use serveIndex middleware when enabled.
330+
Details:
331+
* configuration.static.serveIndex should be a boolean.
332+
* configuration.static.serveIndex should be an object:
333+
object { … }"
334+
`;
335+
275336
exports[`options validate should throw an error on the "static" option with '0' value 1`] = `
276337
"ValidationError: Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
277338
- configuration.static should be one of these:

test/validate-options.test.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const tests = {
220220
{ target: ['foo', 'bar'], app: ['google-chrome', '--incognito'] },
221221
{},
222222
],
223-
failure: ['', [], { foo: 'bar' }],
223+
failure: ['', [], { foo: 'bar' }, { target: 90 }, { app: true }],
224224
},
225225
port: {
226226
success: ['', 0, null],
@@ -267,7 +267,17 @@ const tests = {
267267
},
268268
],
269269
],
270-
failure: [0, null, ''],
270+
failure: [
271+
0,
272+
null,
273+
'',
274+
{
275+
publicPath: false,
276+
},
277+
{
278+
serveIndex: 'true',
279+
},
280+
],
271281
},
272282
transportMode: {
273283
success: [

0 commit comments

Comments
 (0)