Skip to content

Commit 04483f4

Browse files
knagaitsevhiroppy
authored andcommitted
feat(server): serverMode 'ws' option (#2082)
* feat(server): server mode ws string option * test(server): rearrange bad host test * test(server): added mock server implementation tests * test(server): remove bad host test temporarily * test(server): re added bad host test
1 parent aa31d87 commit 04483f4

File tree

4 files changed

+528
-245
lines changed

4 files changed

+528
-245
lines changed

lib/utils/getSocketServerImplementation.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function getSocketServerImplementation(options) {
99
if (options.serverMode === 'sockjs') {
1010
// eslint-disable-next-line global-require
1111
ServerImplementation = require('../servers/SockJSServer');
12+
} else if (options.serverMode === 'ws') {
13+
// eslint-disable-next-line global-require
14+
ServerImplementation = require('../servers/WebsocketServer');
1215
} else {
1316
try {
1417
// eslint-disable-next-line global-require, import/no-dynamic-require
@@ -29,7 +32,7 @@ function getSocketServerImplementation(options) {
2932

3033
if (!serverImplFound) {
3134
throw new Error(
32-
"serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
35+
"serverMode must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
3336
'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
3437
'via require.resolve(...), or the class itself which extends BaseServer'
3538
);
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,91 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`serverMode option with a bad host header results in an error 1`] = `
3+
exports[`serverMode option passed to server with a bad host header results in an error 1`] = `
44
Array [
55
"open",
66
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
77
"close",
88
]
99
`;
1010

11-
exports[`serverMode option without a header results in an error 1`] = `
11+
exports[`serverMode option passed to server without a header results in an error 1`] = `
1212
Array [
1313
"open",
1414
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
1515
"close",
1616
]
1717
`;
18+
19+
exports[`serverMode option server should close client with bad headers 1`] = `
20+
Array [
21+
Array [
22+
[Function],
23+
],
24+
]
25+
`;
26+
27+
exports[`serverMode option server should close client with bad headers 2`] = `
28+
Array [
29+
Array [
30+
Object {
31+
"foo": "bar",
32+
},
33+
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
34+
],
35+
]
36+
`;
37+
38+
exports[`serverMode option server should close client with bad headers 3`] = `
39+
Array [
40+
Array [
41+
Object {
42+
"foo": "bar",
43+
},
44+
],
45+
]
46+
`;
47+
48+
exports[`serverMode option server should use server implementation correctly 1`] = `
49+
Array [
50+
Object {
51+
"foo": "bar",
52+
},
53+
]
54+
`;
55+
56+
exports[`serverMode option server should use server implementation correctly 2`] = `
57+
Array [
58+
Array [
59+
[Function],
60+
],
61+
]
62+
`;
63+
64+
exports[`serverMode option server should use server implementation correctly 3`] = `
65+
Array [
66+
Object {
67+
"foo": "bar",
68+
},
69+
"{\\"type\\":\\"liveReload\\"}",
70+
]
71+
`;
72+
73+
exports[`serverMode option server should use server implementation correctly 4`] = `
74+
Array [
75+
Object {
76+
"foo": "bar",
77+
},
78+
"{\\"type\\":\\"ok\\"}",
79+
]
80+
`;
81+
82+
exports[`serverMode option server should use server implementation correctly 5`] = `
83+
Array [
84+
Array [
85+
Object {
86+
"foo": "bar",
87+
},
88+
[Function],
89+
],
90+
]
91+
`;

0 commit comments

Comments
 (0)