Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema for web socket server type #3913

Merged
merged 3 commits into from Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/options.json
Expand Up @@ -790,8 +790,18 @@
"description": "Allows to set web socket server and options (by default 'ws').",
"link": "https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver"
},
"WebSocketServerType": {
"enum": ["sockjs", "ws"]
},
"WebSocketServerEnum": {
"enum": [false, "sockjs", "ws"]
"anyOf": [
{
"enum": [false]
},
{
"$ref": "#/definitions/WebSocketServerType"
}
]
},
"WebSocketServerFunction": {
"instanceof": "Function"
Expand All @@ -805,7 +815,7 @@
"type": {
"anyOf": [
{
"$ref": "#/definitions/WebSocketServerEnum"
"$ref": "#/definitions/WebSocketServerType"
},
{
"$ref": "#/definitions/WebSocketServerString"
Expand Down
28 changes: 26 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Expand Up @@ -721,6 +721,22 @@ exports[`options validate should throw an error on the "webSocketServer" option
object { type?, options? }"
`;

exports[`options validate should throw an error on the "webSocketServer" option with '{"type":false}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? }
-> Allows to set web socket server and options (by default 'ws').
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
Details:
* options.webSocketServer.type should be one of these:
\\"sockjs\\" | \\"ws\\" | non-empty string | function
Details:
* options.webSocketServer.type should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer.type should be a non-empty string.
* options.webSocketServer.type should be an instance of function."
`;

exports[`options validate should throw an error on the "webSocketServer" option with '{"type":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
Expand All @@ -729,10 +745,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
Details:
* options.webSocketServer.type should be one of these:
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function
\\"sockjs\\" | \\"ws\\" | non-empty string | function
Details:
* options.webSocketServer.type should be one of these:
false | \\"sockjs\\" | \\"ws\\"
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer.type should be a non-empty string.
* options.webSocketServer.type should be an instance of function."
`;
Expand All @@ -746,6 +762,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
Details:
* options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\"
Details:
* options.webSocketServer should be false.
* options.webSocketServer should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer should be a non-empty string.
* options.webSocketServer should be an instance of function.
* options.webSocketServer should be an object:
Expand All @@ -761,6 +781,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
Details:
* options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\"
Details:
* options.webSocketServer should be false.
* options.webSocketServer should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer should be a non-empty string.
* options.webSocketServer should be an instance of function.
* options.webSocketServer should be an object:
Expand Down
28 changes: 26 additions & 2 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Expand Up @@ -721,6 +721,22 @@ exports[`options validate should throw an error on the "webSocketServer" option
object { type?, options? }"
`;

exports[`options validate should throw an error on the "webSocketServer" option with '{"type":false}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? }
-> Allows to set web socket server and options (by default 'ws').
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
Details:
* options.webSocketServer.type should be one of these:
\\"sockjs\\" | \\"ws\\" | non-empty string | function
Details:
* options.webSocketServer.type should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer.type should be a non-empty string.
* options.webSocketServer.type should be an instance of function."
`;

exports[`options validate should throw an error on the "webSocketServer" option with '{"type":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.webSocketServer should be one of these:
Expand All @@ -729,10 +745,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
Details:
* options.webSocketServer.type should be one of these:
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function
\\"sockjs\\" | \\"ws\\" | non-empty string | function
Details:
* options.webSocketServer.type should be one of these:
false | \\"sockjs\\" | \\"ws\\"
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer.type should be a non-empty string.
* options.webSocketServer.type should be an instance of function."
`;
Expand All @@ -746,6 +762,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
Details:
* options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\"
Details:
* options.webSocketServer should be false.
* options.webSocketServer should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer should be a non-empty string.
* options.webSocketServer should be an instance of function.
* options.webSocketServer should be an object:
Expand All @@ -761,6 +781,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
Details:
* options.webSocketServer should be one of these:
false | \\"sockjs\\" | \\"ws\\"
Details:
* options.webSocketServer should be false.
* options.webSocketServer should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.webSocketServer should be a non-empty string.
* options.webSocketServer should be an instance of function.
* options.webSocketServer should be an object:
Expand Down
3 changes: 3 additions & 0 deletions test/validate-options.test.js
Expand Up @@ -448,6 +448,9 @@ const tests = {
failure: [
null,
true,
{
type: false,
},
{
notAnOption: true,
},
Expand Down