Skip to content

Commit f6aa6f7

Browse files
fix: schema for web socket server type (#3913)
1 parent 30956dd commit f6aa6f7

5 files changed

+80
-10
lines changed

bin/cli-flags.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,30 @@ module.exports = {
297297
"web-socket-server": {
298298
configs: [
299299
{
300-
type: "enum",
301-
values: [false, "sockjs", "ws"],
302-
multiple: false,
303300
description:
304301
"Allows to set web socket server and options (by default 'ws').",
302+
multiple: false,
305303
path: "webSocketServer",
304+
type: "enum",
305+
values: [false],
306306
},
307307
{
308-
type: "string",
308+
description:
309+
"Allows to set web socket server and options (by default 'ws').",
309310
multiple: false,
311+
path: "webSocketServer",
312+
type: "enum",
313+
values: ["sockjs", "ws"],
314+
},
315+
{
310316
description:
311317
"Allows to set web socket server and options (by default 'ws').",
318+
multiple: false,
312319
path: "webSocketServer",
320+
type: "string",
313321
},
314322
],
323+
315324
description:
316325
"Allows to set web socket server and options (by default 'ws').",
317326
simpleType: "string",

lib/options.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,18 @@
790790
"description": "Allows to set web socket server and options (by default 'ws').",
791791
"link": "https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver"
792792
},
793+
"WebSocketServerType": {
794+
"enum": ["sockjs", "ws"]
795+
},
793796
"WebSocketServerEnum": {
794-
"enum": [false, "sockjs", "ws"]
797+
"anyOf": [
798+
{
799+
"enum": [false]
800+
},
801+
{
802+
"$ref": "#/definitions/WebSocketServerType"
803+
}
804+
]
795805
},
796806
"WebSocketServerFunction": {
797807
"instanceof": "Function"
@@ -805,7 +815,7 @@
805815
"type": {
806816
"anyOf": [
807817
{
808-
"$ref": "#/definitions/WebSocketServerEnum"
818+
"$ref": "#/definitions/WebSocketServerType"
809819
},
810820
{
811821
"$ref": "#/definitions/WebSocketServerString"

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,22 @@ exports[`options validate should throw an error on the "webSocketServer" option
721721
object { type?, options? }"
722722
`;
723723

724+
exports[`options validate should throw an error on the "webSocketServer" option with '{"type":false}' value 1`] = `
725+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
726+
- options.webSocketServer should be one of these:
727+
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? }
728+
-> Allows to set web socket server and options (by default 'ws').
729+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
730+
Details:
731+
* options.webSocketServer.type should be one of these:
732+
\\"sockjs\\" | \\"ws\\" | non-empty string | function
733+
Details:
734+
* options.webSocketServer.type should be one of these:
735+
\\"sockjs\\" | \\"ws\\"
736+
* options.webSocketServer.type should be a non-empty string.
737+
* options.webSocketServer.type should be an instance of function."
738+
`;
739+
724740
exports[`options validate should throw an error on the "webSocketServer" option with '{"type":true}' value 1`] = `
725741
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
726742
- options.webSocketServer should be one of these:
@@ -729,10 +745,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
729745
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
730746
Details:
731747
* options.webSocketServer.type should be one of these:
732-
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function
748+
\\"sockjs\\" | \\"ws\\" | non-empty string | function
733749
Details:
734750
* options.webSocketServer.type should be one of these:
735-
false | \\"sockjs\\" | \\"ws\\"
751+
\\"sockjs\\" | \\"ws\\"
736752
* options.webSocketServer.type should be a non-empty string.
737753
* options.webSocketServer.type should be an instance of function."
738754
`;
@@ -746,6 +762,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
746762
Details:
747763
* options.webSocketServer should be one of these:
748764
false | \\"sockjs\\" | \\"ws\\"
765+
Details:
766+
* options.webSocketServer should be false.
767+
* options.webSocketServer should be one of these:
768+
\\"sockjs\\" | \\"ws\\"
749769
* options.webSocketServer should be a non-empty string.
750770
* options.webSocketServer should be an instance of function.
751771
* options.webSocketServer should be an object:
@@ -761,6 +781,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
761781
Details:
762782
* options.webSocketServer should be one of these:
763783
false | \\"sockjs\\" | \\"ws\\"
784+
Details:
785+
* options.webSocketServer should be false.
786+
* options.webSocketServer should be one of these:
787+
\\"sockjs\\" | \\"ws\\"
764788
* options.webSocketServer should be a non-empty string.
765789
* options.webSocketServer should be an instance of function.
766790
* options.webSocketServer should be an object:

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,22 @@ exports[`options validate should throw an error on the "webSocketServer" option
721721
object { type?, options? }"
722722
`;
723723

724+
exports[`options validate should throw an error on the "webSocketServer" option with '{"type":false}' value 1`] = `
725+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
726+
- options.webSocketServer should be one of these:
727+
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? }
728+
-> Allows to set web socket server and options (by default 'ws').
729+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
730+
Details:
731+
* options.webSocketServer.type should be one of these:
732+
\\"sockjs\\" | \\"ws\\" | non-empty string | function
733+
Details:
734+
* options.webSocketServer.type should be one of these:
735+
\\"sockjs\\" | \\"ws\\"
736+
* options.webSocketServer.type should be a non-empty string.
737+
* options.webSocketServer.type should be an instance of function."
738+
`;
739+
724740
exports[`options validate should throw an error on the "webSocketServer" option with '{"type":true}' value 1`] = `
725741
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
726742
- options.webSocketServer should be one of these:
@@ -729,10 +745,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
729745
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
730746
Details:
731747
* options.webSocketServer.type should be one of these:
732-
false | \\"sockjs\\" | \\"ws\\" | non-empty string | function
748+
\\"sockjs\\" | \\"ws\\" | non-empty string | function
733749
Details:
734750
* options.webSocketServer.type should be one of these:
735-
false | \\"sockjs\\" | \\"ws\\"
751+
\\"sockjs\\" | \\"ws\\"
736752
* options.webSocketServer.type should be a non-empty string.
737753
* options.webSocketServer.type should be an instance of function."
738754
`;
@@ -746,6 +762,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
746762
Details:
747763
* options.webSocketServer should be one of these:
748764
false | \\"sockjs\\" | \\"ws\\"
765+
Details:
766+
* options.webSocketServer should be false.
767+
* options.webSocketServer should be one of these:
768+
\\"sockjs\\" | \\"ws\\"
749769
* options.webSocketServer should be a non-empty string.
750770
* options.webSocketServer should be an instance of function.
751771
* options.webSocketServer should be an object:
@@ -761,6 +781,10 @@ exports[`options validate should throw an error on the "webSocketServer" option
761781
Details:
762782
* options.webSocketServer should be one of these:
763783
false | \\"sockjs\\" | \\"ws\\"
784+
Details:
785+
* options.webSocketServer should be false.
786+
* options.webSocketServer should be one of these:
787+
\\"sockjs\\" | \\"ws\\"
764788
* options.webSocketServer should be a non-empty string.
765789
* options.webSocketServer should be an instance of function.
766790
* options.webSocketServer should be an object:

test/validate-options.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ const tests = {
448448
failure: [
449449
null,
450450
true,
451+
{
452+
type: false,
453+
},
451454
{
452455
notAnOption: true,
453456
},

0 commit comments

Comments
 (0)