Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/utils/getSocketServerImplementation.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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],
],
]
`;
Loading