Skip to content

Commit

Permalink
feat(server): serverMode 'ws' option (#2082)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
knagaitsev authored and hiroppy committed Jul 5, 2019
1 parent aa31d87 commit 04483f4
Show file tree
Hide file tree
Showing 4 changed files with 528 additions and 245 deletions.
5 changes: 4 additions & 1 deletion lib/utils/getSocketServerImplementation.js
Expand Up @@ -9,6 +9,9 @@ function getSocketServerImplementation(options) {
if (options.serverMode === 'sockjs') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/SockJSServer');
} else if (options.serverMode === 'ws') {
// eslint-disable-next-line global-require
ServerImplementation = require('../servers/WebsocketServer');
} else {
try {
// eslint-disable-next-line global-require, import/no-dynamic-require
Expand All @@ -29,7 +32,7 @@ function getSocketServerImplementation(options) {

if (!serverImplFound) {
throw new Error(
"serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to " +
"serverMode must be a string denoting a default implementation (e.g. 'sockjs', 'ws'), a full path to " +
'a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) ' +
'via require.resolve(...), or the class itself which extends BaseServer'
);
Expand Down
78 changes: 76 additions & 2 deletions test/server/__snapshots__/serverMode-option.test.js.snap
@@ -1,17 +1,91 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`serverMode option with a bad host header results in an error 1`] = `
exports[`serverMode option passed to server with a bad host header results in an error 1`] = `
Array [
"open",
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
"close",
]
`;

exports[`serverMode option without a header results in an error 1`] = `
exports[`serverMode option passed to server without a header results in an error 1`] = `
Array [
"open",
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
"close",
]
`;

exports[`serverMode option server should close client with bad headers 1`] = `
Array [
Array [
[Function],
],
]
`;

exports[`serverMode option server should close client with bad headers 2`] = `
Array [
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"error\\",\\"data\\":\\"Invalid Host/Origin header\\"}",
],
]
`;

exports[`serverMode option server should close client with bad headers 3`] = `
Array [
Array [
Object {
"foo": "bar",
},
],
]
`;

exports[`serverMode option server should use server implementation correctly 1`] = `
Array [
Object {
"foo": "bar",
},
]
`;

exports[`serverMode option server should use server implementation correctly 2`] = `
Array [
Array [
[Function],
],
]
`;

exports[`serverMode option server should use server implementation correctly 3`] = `
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"liveReload\\"}",
]
`;

exports[`serverMode option server should use server implementation correctly 4`] = `
Array [
Object {
"foo": "bar",
},
"{\\"type\\":\\"ok\\"}",
]
`;

exports[`serverMode option server should use server implementation correctly 5`] = `
Array [
Array [
Object {
"foo": "bar",
},
[Function],
],
]
`;

0 comments on commit 04483f4

Please sign in to comment.