Skip to content

Commit

Permalink
fix: schema for web socket server type (#3913)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Oct 5, 2021
1 parent 30956dd commit f6aa6f7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
17 changes: 13 additions & 4 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,30 @@ module.exports = {
"web-socket-server": {
configs: [
{
type: "enum",
values: [false, "sockjs", "ws"],
multiple: false,
description:
"Allows to set web socket server and options (by default 'ws').",
multiple: false,
path: "webSocketServer",
type: "enum",
values: [false],
},
{
type: "string",
description:
"Allows to set web socket server and options (by default 'ws').",
multiple: false,
path: "webSocketServer",
type: "enum",
values: ["sockjs", "ws"],
},
{
description:
"Allows to set web socket server and options (by default 'ws').",
multiple: false,
path: "webSocketServer",
type: "string",
},
],

description:
"Allows to set web socket server and options (by default 'ws').",
simpleType: "string",
Expand Down
14 changes: 12 additions & 2 deletions lib/options.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ const tests = {
failure: [
null,
true,
{
type: false,
},
{
notAnOption: true,
},
Expand Down

0 comments on commit f6aa6f7

Please sign in to comment.