Skip to content

Commit

Permalink
feat: output more information on errors (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 6, 2021
1 parent 8ad78f8 commit 7df9e44
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"memfs": "^3.2.2",
"mime-types": "^2.1.31",
"range-parser": "^1.2.1",
"schema-utils": "^3.0.0"
"schema-utils": "^3.1.0"
},
"devDependencies": {
"@babel/cli": "^7.14.5",
Expand Down
12 changes: 11 additions & 1 deletion src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"properties": {
"mimeTypes": {
"description": "Allows a user to register custom mime types or extension mappings.",
"link": "https://github.com/webpack/webpack-dev-middleware#mimetypes",
"type": "object"
},
"writeToDisk": {
"description": "Allows to write generated files on disk.",
"link": "https://github.com/webpack/webpack-dev-middleware#writetodisk",
"anyOf": [
{
"type": "boolean"
Expand All @@ -18,6 +20,7 @@
},
"methods": {
"description": "Allows to pass the list of HTTP request methods accepted by the middleware.",
"link": "https://github.com/webpack/webpack-dev-middleware#methods",
"type": "array",
"items": {
"type": "string",
Expand All @@ -32,10 +35,13 @@
{
"instanceof": "Function"
}
]
],
"description": "Allows to pass custom HTTP headers on each request",
"link": "https://github.com/webpack/webpack-dev-middleware#headers"
},
"publicPath": {
"description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
"link": "https://github.com/webpack/webpack-dev-middleware#publicpath",
"anyOf": [
{
"enum": ["auto"]
Expand All @@ -50,6 +56,7 @@
},
"stats": {
"description": "Stats options object or preset name.",
"link": "https://github.com/webpack/webpack-dev-middleware#stats",
"anyOf": [
{
"enum": [
Expand All @@ -74,14 +81,17 @@
},
"serverSideRender": {
"description": "Instructs the module to enable or disable the server-side rendering mode.",
"link": "https://github.com/webpack/webpack-dev-middleware#serversiderender",
"type": "boolean"
},
"outputFileSystem": {
"description": "Set the default file system which will be used by webpack as primary destination of generated files.",
"link": "https://github.com/webpack/webpack-dev-middleware#outputfilesystem",
"type": "object"
},
"index": {
"description": "Allows to serve an index of the directory.",
"link": "https://github.com/webpack/webpack-dev-middleware#index",
"anyOf": [
{
"type": "boolean"
Expand Down
27 changes: 21 additions & 6 deletions test/__snapshots__/validation-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`validation should throw an error on the "headers" option with "1" value
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -14,6 +16,8 @@ exports[`validation should throw an error on the "headers" option with "true" va
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -25,6 +29,7 @@ exports[`validation should throw an error on the "index" option with "{}" value
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -35,6 +40,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -44,35 +50,40 @@ exports[`validation should throw an error on the "methods" option with "{}" valu
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "methods" option with "true" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.mimeTypes should be an object:
object { … }
-> Allows a user to register custom mime types or extension mappings."
-> Allows a user to register custom mime types or extension mappings.
-> Read more at https://github.com/webpack/webpack-dev-middleware#mimetypes"
`;

exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.outputFileSystem should be an object:
object { … }
-> Set the default file system which will be used by webpack as primary destination of generated files."
-> Set the default file system which will be used by webpack as primary destination of generated files.
-> Read more at https://github.com/webpack/webpack-dev-middleware#outputfilesystem"
`;

exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.publicPath should be one of these:
\\"auto\\" | string | function
-> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.
-> Read more at https://github.com/webpack/webpack-dev-middleware#publicpath
Details:
* options.publicPath should be \\"auto\\".
* options.publicPath should be a string.
Expand All @@ -82,20 +93,23 @@ exports[`validation should throw an error on the "publicPath" option with "false
exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "stats" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\" | boolean | object { … }
-> Stats options object or preset name.
-> Read more at https://github.com/webpack/webpack-dev-middleware#stats
Details:
* options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\"
Expand All @@ -109,6 +123,7 @@ exports[`validation should throw an error on the "writeToDisk" option with "{}"
- options.writeToDisk should be one of these:
boolean | function
-> Allows to write generated files on disk.
-> Read more at https://github.com/webpack/webpack-dev-middleware#writetodisk
Details:
* options.writeToDisk should be a boolean.
* options.writeToDisk should be an instance of function."
Expand Down
27 changes: 21 additions & 6 deletions test/__snapshots__/validation-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`validation should throw an error on the "headers" option with "1" value
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -14,6 +16,8 @@ exports[`validation should throw an error on the "headers" option with "true" va
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.headers should be one of these:
object { … } | function
-> Allows to pass custom HTTP headers on each request
-> Read more at https://github.com/webpack/webpack-dev-middleware#headers
Details:
* options.headers should be an object:
object { … }
Expand All @@ -25,6 +29,7 @@ exports[`validation should throw an error on the "index" option with "{}" value
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -35,6 +40,7 @@ exports[`validation should throw an error on the "index" option with "0" value 1
- options.index should be one of these:
boolean | string
-> Allows to serve an index of the directory.
-> Read more at https://github.com/webpack/webpack-dev-middleware#index
Details:
* options.index should be a boolean.
* options.index should be a string."
Expand All @@ -44,35 +50,40 @@ exports[`validation should throw an error on the "methods" option with "{}" valu
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "methods" option with "true" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.methods should be an array:
[string, ...]
-> Allows to pass the list of HTTP request methods accepted by the middleware."
-> Allows to pass the list of HTTP request methods accepted by the middleware.
-> Read more at https://github.com/webpack/webpack-dev-middleware#methods"
`;

exports[`validation should throw an error on the "mimeTypes" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.mimeTypes should be an object:
object { … }
-> Allows a user to register custom mime types or extension mappings."
-> Allows a user to register custom mime types or extension mappings.
-> Read more at https://github.com/webpack/webpack-dev-middleware#mimetypes"
`;

exports[`validation should throw an error on the "outputFileSystem" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.outputFileSystem should be an object:
object { … }
-> Set the default file system which will be used by webpack as primary destination of generated files."
-> Set the default file system which will be used by webpack as primary destination of generated files.
-> Read more at https://github.com/webpack/webpack-dev-middleware#outputfilesystem"
`;

exports[`validation should throw an error on the "publicPath" option with "false" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.publicPath should be one of these:
\\"auto\\" | string | function
-> The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.
-> Read more at https://github.com/webpack/webpack-dev-middleware#publicpath
Details:
* options.publicPath should be \\"auto\\".
* options.publicPath should be a string.
Expand All @@ -82,20 +93,23 @@ exports[`validation should throw an error on the "publicPath" option with "false
exports[`validation should throw an error on the "serverSideRender" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "serverSideRender" option with "foo" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.serverSideRender should be a boolean.
-> Instructs the module to enable or disable the server-side rendering mode."
-> Instructs the module to enable or disable the server-side rendering mode.
-> Read more at https://github.com/webpack/webpack-dev-middleware#serversiderender"
`;

exports[`validation should throw an error on the "stats" option with "0" value 1`] = `
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
- options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\" | boolean | object { … }
-> Stats options object or preset name.
-> Read more at https://github.com/webpack/webpack-dev-middleware#stats
Details:
* options.stats should be one of these:
\\"none\\" | \\"summary\\" | \\"errors-only\\" | \\"errors-warnings\\" | \\"minimal\\" | \\"normal\\" | \\"detailed\\" | \\"verbose\\"
Expand All @@ -109,6 +123,7 @@ exports[`validation should throw an error on the "writeToDisk" option with "{}"
- options.writeToDisk should be one of these:
boolean | function
-> Allows to write generated files on disk.
-> Read more at https://github.com/webpack/webpack-dev-middleware#writetodisk
Details:
* options.writeToDisk should be a boolean.
* options.writeToDisk should be an instance of function."
Expand Down

0 comments on commit 7df9e44

Please sign in to comment.