diff --git a/README.md b/README.md index 8e75cacbae..0d3ff793fd 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ Options: --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. --web-socket-server Allows to set web socket server and options (by default 'ws'). + --no-web-socket-server Negative 'web-socket-server' option. Global options: --color Enable colors on console. diff --git a/bin/cli-flags.js b/bin/cli-flags.js index b91f9a9eff..af058c1253 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -298,7 +298,7 @@ module.exports = { configs: [ { type: 'enum', - values: ['sockjs', 'ws'], + values: [false, 'sockjs', 'ws'], multiple: false, description: "Allows to set web socket server and options (by default 'ws').", diff --git a/lib/Server.js b/lib/Server.js index 2072b8bd90..bba37b1e80 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -671,11 +671,7 @@ class Server { } createWebSocketServer() { - this.webSocketServerImplementation = - this.getWebSocketServerImplementation(); - // eslint-disable-next-line new-cap - this.webSocketServer = new this.webSocketServerImplementation(this); - + this.webSocketServer = new (this.getWebSocketServerImplementation())(this); this.webSocketServer.implementation.on('connection', (client, request) => { const headers = // eslint-disable-next-line no-nested-ternary @@ -1037,8 +1033,14 @@ class Server { fs.chmodSync(this.options.ipc, READ_WRITE); } - if (Boolean(this.options.hot) || this.options.liveReload) { - this.createWebSocketServer(); + if (this.options.webSocketServer) { + try { + this.createWebSocketServer(); + } catch (webSocketServerError) { + fn.call(this.server, webSocketServerError); + + return; + } } if (this.options.bonjour) { diff --git a/lib/options.json b/lib/options.json index 7111f153eb..b35816ecb9 100644 --- a/lib/options.json +++ b/lib/options.json @@ -635,7 +635,7 @@ "link": "https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver" }, "WebSocketServerEnum": { - "enum": ["sockjs", "ws"] + "enum": [false, "sockjs", "ws"] }, "WebSocketServerFunction": { "instanceof": "Function" diff --git a/lib/utils/DevServerPlugin.js b/lib/utils/DevServerPlugin.js index 7d417ef8d9..35ffdfe96c 100644 --- a/lib/utils/DevServerPlugin.js +++ b/lib/utils/DevServerPlugin.js @@ -18,6 +18,7 @@ class DevServerPlugin { let clientImplementationFound = true; const isKnownWebSocketServerImplementation = + this.options.webSocketServer && typeof this.options.webSocketServer.type === 'string' && (this.options.webSocketServer.type === 'ws' || this.options.webSocketServer.type === 'sockjs'); @@ -29,6 +30,8 @@ class DevServerPlugin { clientTransport = this.options.client.webSocketTransport; } else if (isKnownWebSocketServerImplementation) { clientTransport = this.options.webSocketServer.type; + } else { + clientTransport = 'ws'; } } else { clientTransport = 'ws'; @@ -186,8 +189,10 @@ class DevServerPlugin { * @returns {string} */ getClientEntry() { - const webSocketURL = this.getWebSocketURL(); /** @type {string} */ + const webSocketURL = this.options.webSocketServer + ? this.getWebSocketURL() + : ''; return `${require.resolve('../../client/index.js')}?${webSocketURL}`; } @@ -243,11 +248,8 @@ class DevServerPlugin { const additionalEntries = []; - if ( - this.options.client && - this.isWebTarget(compiler.options) && - (Boolean(this.options.hot) || this.options.liveReload) - ) { + // TODO maybe empty empty client + if (this.options.client && this.isWebTarget(compiler.options)) { const clientEntry = this.getClientEntry(); additionalEntries.push(clientEntry); diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index aa46b9c167..1861e50a23 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -409,6 +409,11 @@ function normalizeOptions(compiler, options, logger, cacheDir) { type: defaultWebSocketServerType, options: defaultWebSocketServerOptions, }; + } else if ( + typeof options.webSocketServer === 'boolean' && + !options.webSocketServer + ) { + options.webSocketServer = false; } else if ( typeof options.webSocketServer === 'string' || typeof options.webSocketServer === 'function' diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 5b3294c6ea..69740b58e3 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -666,43 +666,43 @@ exports[`options validate should throw an error on the "webSocketServer" option 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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 + false | \\"sockjs\\" | \\"ws\\" | non-empty string | function Details: * options.webSocketServer.type should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"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 'false' value 1`] = ` +exports[`options validate should throw an error on the "webSocketServer" option with 'null' 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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"sockjs\\" | \\"ws\\" * options.webSocketServer should be a non-empty string. * options.webSocketServer should be an instance of function. * options.webSocketServer should be an object: object { type?, options? }" `; -exports[`options validate should throw an error on the "webSocketServer" option with 'null' value 1`] = ` +exports[`options validate should throw an error on the "webSocketServer" option with '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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"sockjs\\" | \\"ws\\" * options.webSocketServer should be a non-empty string. * options.webSocketServer should be an instance of function. * options.webSocketServer should be an object: diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 5b3294c6ea..69740b58e3 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -666,43 +666,43 @@ exports[`options validate should throw an error on the "webSocketServer" option 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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 + false | \\"sockjs\\" | \\"ws\\" | non-empty string | function Details: * options.webSocketServer.type should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"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 'false' value 1`] = ` +exports[`options validate should throw an error on the "webSocketServer" option with 'null' 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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"sockjs\\" | \\"ws\\" * options.webSocketServer should be a non-empty string. * options.webSocketServer should be an instance of function. * options.webSocketServer should be an object: object { type?, options? }" `; -exports[`options validate should throw an error on the "webSocketServer" option with 'null' value 1`] = ` +exports[`options validate should throw an error on the "webSocketServer" option with '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: - \\"sockjs\\" | \\"ws\\" | non-empty string | function | object { type?, options? } + 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 should be one of these: - \\"sockjs\\" | \\"ws\\" + false | \\"sockjs\\" | \\"ws\\" * options.webSocketServer should be a non-empty string. * options.webSocketServer should be an instance of function. * options.webSocketServer should be an object: diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack4 b/test/cli/__snapshots__/basic.test.js.snap.webpack4 index ae483ab8a3..38fc8bc38b 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack4 @@ -61,6 +61,7 @@ Options: --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. --web-socket-server Allows to set web socket server and options (by default 'ws'). + --no-web-socket-server Negative 'web-socket-server' option. --compress Enables gzip compression for everything served. --no-compress Disables gzip compression for everything served. --history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API. diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack5 b/test/cli/__snapshots__/basic.test.js.snap.webpack5 index f06d6a70a4..f6e4b254cb 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack5 @@ -104,6 +104,7 @@ Options: --watch-files Allows to configure list of globs/directories/files to watch for file changes. --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. --web-socket-server Allows to set web socket server and options (by default 'ws'). + --no-web-socket-server Negative 'web-socket-server' option. Global options: --color Enable colors on console. diff --git a/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack4 b/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack4 index d81f2b3e33..95ac031672 100644 --- a/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack4 @@ -1,14 +1,26 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): page errors 1`] = `Array []`; -exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): page errors 1`] = `Array []`; -exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): page errors 1`] = `Array []`; @@ -47,6 +59,17 @@ Array [ exports[`hot and live reload should work and allow to disable live reload using the "webpack-dev-server-live-reload=false" (default): page errors 1`] = `Array []`; +exports[`hot and live reload should work and do nothing when web socket server disabled (default): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "WebSocket connection to 'ws://localhost:8095/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "[webpack-dev-server] JSHandle@object", + "[webpack-dev-server] Disconnected!", +] +`; + +exports[`hot and live reload should work and do nothing when web socket server disabled (default): page errors 1`] = `Array []`; + exports[`hot and live reload should work and refresh content using hot module replacement (default): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack5 b/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack5 index d81f2b3e33..95ac031672 100644 --- a/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack5 @@ -1,14 +1,26 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (default): page errors 1`] = `Array []`; -exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (sockjs): page errors 1`] = `Array []`; -exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): console messages 1`] = `Array []`; +exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): console messages 1`] = ` +Array [ + "[webpack-dev-server] App updated. Recompiling...", +] +`; exports[`hot and live reload should not refresh content when hot and no live reload disabled (ws): page errors 1`] = `Array []`; @@ -47,6 +59,17 @@ Array [ exports[`hot and live reload should work and allow to disable live reload using the "webpack-dev-server-live-reload=false" (default): page errors 1`] = `Array []`; +exports[`hot and live reload should work and do nothing when web socket server disabled (default): console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "WebSocket connection to 'ws://localhost:8095/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "[webpack-dev-server] JSHandle@object", + "[webpack-dev-server] Disconnected!", +] +`; + +exports[`hot and live reload should work and do nothing when web socket server disabled (default): page errors 1`] = `Array []`; + exports[`hot and live reload should work and refresh content using hot module replacement (default): console messages 1`] = ` Array [ "[HMR] Waiting for update signal from WDS...", diff --git a/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack4 b/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack4 index 444381b68f..2a34f9a5ed 100644 --- a/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack4 @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`web socket server and transport should throw an error on wrong path 1`] = `"When you use custom web socket implementation you must explicitly specify client.webSocketTransport. client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class "`; +exports[`web socket server and transport should throw an error on wrong path 1`] = `"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) via require.resolve(...), or the class itself which extends BaseServer"`; exports[`web socket server and transport should use "sockjs" transport and "sockjs" web socket server 1`] = ` Array [ diff --git a/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack5 b/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack5 index 444381b68f..2a34f9a5ed 100644 --- a/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/web-socket-server-and-transport.test.js.snap.webpack5 @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`web socket server and transport should throw an error on wrong path 1`] = `"When you use custom web socket implementation you must explicitly specify client.webSocketTransport. client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class "`; +exports[`web socket server and transport should throw an error on wrong path 1`] = `"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) via require.resolve(...), or the class itself which extends BaseServer"`; exports[`web socket server and transport should use "sockjs" transport and "sockjs" web socket server 1`] = ` Array [ diff --git a/test/e2e/hot-and-live-reload.test.js b/test/e2e/hot-and-live-reload.test.js index 613590fc2e..1d3a6681f6 100644 --- a/test/e2e/hot-and-live-reload.test.js +++ b/test/e2e/hot-and-live-reload.test.js @@ -28,6 +28,12 @@ describe('hot and live reload', () => { { title: 'should work and refresh content using hot module replacement', }, + { + title: 'should work and do nothing when web socket server disabled', + options: { + webSocketServer: false, + }, + }, // Default web socket serve ("ws") { title: @@ -45,7 +51,6 @@ describe('hot and live reload', () => { }, { title: 'should not refresh content when hot and no live reload disabled', - noWebSocketServer: true, options: { hot: false, liveReload: false, @@ -93,7 +98,6 @@ describe('hot and live reload', () => { }, { title: 'should not refresh content when hot and no live reload disabled', - noWebSocketServer: true, options: { webSocketServer: 'ws', hot: false, @@ -150,7 +154,6 @@ describe('hot and live reload', () => { }, { title: 'should not refresh content when hot and no live reload disabled', - noWebSocketServer: true, options: { allowedHosts: 'all', @@ -281,10 +284,11 @@ describe('hot and live reload', () => { const webpackOptions = { ...reloadConfig, ...mode.webpackOptions }; const compiler = webpack(webpackOptions); + const testDevServerOptions = mode.options || {}; const devServerOptions = { host: '0.0.0.0', port, - ...mode.options, + ...testDevServerOptions, }; const server = new Server(devServerOptions, compiler); @@ -315,23 +319,24 @@ describe('hot and live reload', () => { }); const hot = - mode.options && typeof mode.options.hot !== 'undefined' - ? mode.options.hot + typeof testDevServerOptions.hot !== 'undefined' + ? testDevServerOptions.hot : true; const liveReload = - mode.options && typeof mode.options.liveReload !== 'undefined' - ? mode.options.liveReload + typeof testDevServerOptions.liveReload !== 'undefined' + ? testDevServerOptions.liveReload : true; + const webSocketServerLaunched = + testDevServerOptions.webSocketServer !== false; await new Promise((resolve) => { - const webSocketServer = - mode.options && typeof mode.options.webSocketServer !== 'undefined' - ? mode.options.webSocketServer + const webSocketTransport = + typeof testDevServerOptions.webSocketServer !== 'undefined' && + testDevServerOptions.webSocketServer !== false + ? testDevServerOptions.webSocketServer : 'ws'; - const webSocketServerLaunched = hot || liveReload; - - if (webSocketServer === 'ws') { + if (webSocketTransport === 'ws') { const ws = new WebSocket( `ws://127.0.0.1:${devServerOptions.port}/ws`, { @@ -347,13 +352,13 @@ describe('hot and live reload', () => { let errored = false; ws.on('error', (error) => { - if (webSocketServerLaunched) { + if (!webSocketServerLaunched && /404/.test(error)) { errored = true; - } else if (!webSocketServerLaunched && /404/.test(error)) { + } else { errored = true; - - ws.close(); } + + ws.close(); }); ws.on('open', () => { @@ -371,7 +376,7 @@ describe('hot and live reload', () => { }); ws.on('close', () => { - if (webSocketServerLaunched && opened && received && !errored) { + if (opened && received && !errored) { resolve(); } else if (!webSocketServerLaunched && errored) { resolve(); @@ -405,13 +410,9 @@ describe('hot and live reload', () => { }; sockjs.onclose = (event) => { - if (webSocketServerLaunched && opened && received && !errored) { + if (opened && received && !errored) { resolve(); - } else if ( - !webSocketServerLaunched && - event && - event.reason === 'Cannot connect to server' - ) { + } else if (event && event.reason === 'Cannot connect to server') { resolve(); } }; @@ -485,6 +486,7 @@ describe('hot and live reload', () => { } if ( + webSocketServerLaunched && allowToHotModuleReplacement && ((hot && liveReload) || (hot && !liveReload)) ) { @@ -495,12 +497,12 @@ describe('hot and live reload', () => { ); expect(doneHotUpdate).toBe(true); - } else if (liveReload && allowToLiveReload) { + } else if (webSocketServerLaunched && liveReload && allowToLiveReload) { await page.waitForNavigation({ waitUntil: 'networkidle0', }); } else { - if (!mode.noWebSocketServer) { + if (webSocketServerLaunched) { await new Promise((resolve) => { const interval = setInterval(() => { if (consoleMessages.includes(INVALID_MESSAGE)) { diff --git a/test/e2e/web-socket-server-and-transport.test.js b/test/e2e/web-socket-server-and-transport.test.js index 919e346870..d248b4d773 100644 --- a/test/e2e/web-socket-server-and-transport.test.js +++ b/test/e2e/web-socket-server-and-transport.test.js @@ -463,6 +463,8 @@ describe('web socket server and transport', () => { }); it('should throw an error on wrong path', async () => { + expect.assertions(1); + const compiler = webpack(defaultConfig); const devServerOptions = { port, @@ -472,24 +474,27 @@ describe('web socket server and transport', () => { }; const server = new Server(devServerOptions, compiler); - await expect( - async () => - new Promise((resolve, reject) => { - server.listen( - devServerOptions.port, - devServerOptions.host, - (error) => { - if (error) { - reject(error); - - return; - } - - resolve(); - } - ); - }) - ).rejects.toThrowErrorMatchingSnapshot(); + try { + await new Promise((resolve, reject) => { + server.listen(devServerOptions.port, devServerOptions.host, (error) => { + if (error) { + reject(error); + + return; + } + + resolve(); + }); + }); + } catch (error) { + expect(error.message).toMatchSnapshot(); + } + + await new Promise((resolve) => { + server.close(() => { + resolve(); + }); + }); }); it('should use "sockjs" transport, when web socket server is not specify', async () => { diff --git a/test/validate-options.test.js b/test/validate-options.test.js index beba527756..27203b8e0f 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -331,6 +331,7 @@ const tests = { }, webSocketServer: { success: [ + false, 'ws', 'sockjs', { @@ -352,7 +353,7 @@ const tests = { ], failure: [ null, - false, + true, { notAnOption: true, },