Skip to content

Commit

Permalink
fix: improve schema for watch options
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 3, 2022
1 parent c2fee3b commit a01150b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 11 deletions.
67 changes: 60 additions & 7 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,7 @@
}
},
{
"type": "object",
"description": "Options for watch.",
"link": "https://github.com/paulmillr/chokidar#api"
"$ref": "#/definitions/WatchOptionsChokidar"
}
],
"description": "Watches for files in static content directory.",
Expand Down Expand Up @@ -1064,10 +1062,7 @@
"description": "Path(s) of globs/directories/files to watch for file changes."
},
"options": {
"type": "object",
"description": "Configure advanced options for watching. See the chokidar documentation for the possible options.",
"link": "https://github.com/paulmillr/chokidar#api",
"additionalProperties": true
"$ref": "#/definitions/WatchOptionsChokidar"
}
},
"additionalProperties": false
Expand All @@ -1076,6 +1071,64 @@
"type": "string",
"minLength": 1
},
"WatchOptionsChokidar": {
"type": "object",
"additionalProperties": false,
"description": "Configure advanced options for watching. See the chokidar documentation for the possible options.",
"link": "https://github.com/paulmillr/chokidar#api",
"properties": {
"persistent": {
"type": "boolean"
},
"ignored": {
"type": "string"
},
"ignoreInitial": {
"type": "boolean"
},
"followSymlinks": {
"type": "boolean"
},
"cwd": {
"type": "string"
},
"disableGlobbing": {
"type": "boolean"
},
"usePolling": {
"type": "boolean"
},
"interval": {
"type": "number"
},
"binaryInterval": {
"type": "number"
},
"alwaysStat": {
"type": "boolean"
},
"depth": {
"type": "number"
},
"awaitWriteFinish": {
"type": "object",
"additionalProperties": true
},
"ignorePermissionErrors": {
"type": "boolean"
},
"atomic": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "number"
}
]
}
}
},
"WebSocketServer": {
"anyOf": [
{
Expand Down
24 changes: 20 additions & 4 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,14 @@ exports[`options validate should throw an error on the "static" option with '{"s
object { … }"
`;

exports[`options validate should throw an error on the "static" option with '{"watch":{"invalid":true}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.static.watch has an unknown property 'invalid'. These properties are valid:
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
-> Read more at https://github.com/paulmillr/chokidar#api"
`;

exports[`options validate should throw an error on the "static" option with '{"watch":10}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.static should be one of these:
Expand All @@ -789,14 +797,14 @@ exports[`options validate should throw an error on the "static" option with '{"w
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverstatic
Details:
* options.static.watch should be one of these:
boolean | object { }
boolean | object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
-> Watches for files in static content directory.
-> Read more at https://webpack.js.org/configuration/dev-server/#watch
Details:
* options.static.watch should be a boolean.
* options.static.watch should be an object:
object { }
-> Options for watch.
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
-> Read more at https://github.com/paulmillr/chokidar#api"
`;

Expand Down Expand Up @@ -830,10 +838,18 @@ exports[`options validate should throw an error on the "static" option with 'nul
object { directory?, staticOptions?, publicPath?, serveIndex?, watch? }"
`;

exports[`options validate should throw an error on the "watchFiles" option with '{"options":{"invalid":true}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.watchFiles.options has an unknown property 'invalid'. These properties are valid:
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
-> Read more at https://github.com/paulmillr/chokidar#api"
`;

exports[`options validate should throw an error on the "watchFiles" option with '{"options":false}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.watchFiles.options should be an object:
object { }
object { persistent?, ignored?, ignoreInitial?, followSymlinks?, cwd?, disableGlobbing?, usePolling?, interval?, binaryInterval?, alwaysStat?, depth?, awaitWriteFinish?, ignorePermissionErrors?, atomic? }
-> Configure advanced options for watching. See the chokidar documentation for the possible options.
-> Read more at https://github.com/paulmillr/chokidar#api"
`;
Expand Down
17 changes: 17 additions & 0 deletions test/validate-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,15 @@ const tests = {
serveIndex: {},
watch: {},
},
{
directory: "path",
staticOptions: {},
publicPath: ["/public1/", "/public2/"],
watch: {
ignored: "*.txt",
usePolling: true,
},
},
[
"path1",
{
Expand Down Expand Up @@ -512,6 +521,9 @@ const tests = {
{
watch: 10,
},
{
watch: { invalid: true },
},
],
},
setupMiddlewares: {
Expand Down Expand Up @@ -571,6 +583,11 @@ const tests = {
{
options: false,
},
{
options: {
invalid: true,
},
},
],
},
};
Expand Down

0 comments on commit a01150b

Please sign in to comment.