From 5edad76bb099713210b2a8c5c29d22371df7371e Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 9 Oct 2021 19:25:37 +0530 Subject: [PATCH] feat: added `client.reconnect` option (#3912) --- README.md | 2 + bin/cli-flags.js | 23 +++ client-src/index.js | 13 +- client-src/socket.js | 9 +- lib/Server.js | 16 ++ lib/options.json | 16 ++ .../validate-options.test.js.snap.webpack4 | 30 +++- .../validate-options.test.js.snap.webpack5 | 30 +++- .../__snapshots__/basic.test.js.snap.webpack4 | 2 + .../__snapshots__/basic.test.js.snap.webpack5 | 2 + test/cli/client-option.test.js | 27 +++ .../__snapshots__/index.test.js.snap.webpack4 | 3 + .../__snapshots__/index.test.js.snap.webpack5 | 3 + test/client/index.test.js | 1 + .../allowed-hosts.test.js.snap.webpack4 | 4 + .../allowed-hosts.test.js.snap.webpack5 | 4 + .../client-reconnect.test.js.snap.webpack4 | 39 ++++ .../client-reconnect.test.js.snap.webpack5 | 39 ++++ ...and-client-transport.test.js.snap.webpack4 | 1 + ...and-client-transport.test.js.snap.webpack5 | 1 + ...socket-communication.test.js.snap.webpack4 | 4 + ...socket-communication.test.js.snap.webpack5 | 4 + test/e2e/client-reconnect.test.js | 170 ++++++++++++++++++ test/ports-map.js | 1 + .../Server.test.js.snap.webpack4 | 55 +++++- .../Server.test.js.snap.webpack5 | 55 +++++- test/validate-options.test.js | 12 ++ 27 files changed, 543 insertions(+), 23 deletions(-) create mode 100644 test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack4 create mode 100644 test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 create mode 100644 test/e2e/client-reconnect.test.js diff --git a/README.md b/README.md index 6b84460521..ebfa2e5c26 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,8 @@ Options: --client-logging Allows to specify options for client script in the browser or disable client script. --client-progress Prints compilation progress in percentage in the browser. --no-client-progress Does not print compilation progress in percentage in the browser. + --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. + --no-client-reconnect Tells dev-server to not to try to connect the client. --client-overlay Enables a full-screen overlay in the browser when there are compiler errors or warnings. --no-client-overlay Disables a full-screen overlay in the browser when there are compiler errors or warnings. --client-overlay-errors Enables a full-screen overlay in the browser when there are compiler errors. diff --git a/bin/cli-flags.js b/bin/cli-flags.js index f755b96309..bbef95350b 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -174,6 +174,29 @@ module.exports = { simpleType: "boolean", multiple: false, }, + "client-reconnect": { + configs: [ + { + type: "boolean", + multiple: false, + description: + "Tells dev-server the number of times it should try to reconnect the client.", + path: "client.reconnect", + }, + { + type: "number", + multiple: false, + description: + "Tells dev-server the number of times it should try to reconnect the client.", + path: "client.reconnect", + }, + ], + description: + "Tells dev-server the number of times it should try to reconnect the client.", + negatedDescription: "Tells dev-server to not to try to connect the client.", + simpleType: "string", + multiple: false, + }, "client-web-socket-url": { configs: [ { diff --git a/client-src/index.js b/client-src/index.js index 3cbacd742b..cd46010dcc 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -41,6 +41,10 @@ if (parsedResourceQuery.logging) { options.logging = parsedResourceQuery.logging; } +if (typeof parsedResourceQuery.reconnect !== "undefined") { + options.reconnect = Number(parsedResourceQuery.reconnect); +} + function setAllLogLevel(level) { // This is needed because the HMR logger operate separately from dev server logger webpackHotLog.setLogLevel( @@ -98,6 +102,13 @@ const onSocketMessage = { options.overlay = value; }, + reconnect(value) { + if (parsedResourceQuery.reconnect === "false") { + return; + } + + options.reconnect = value; + }, progress(progress) { options.progress = progress; }, @@ -215,4 +226,4 @@ const onSocketMessage = { const socketURL = createSocketURL(parsedResourceQuery); -socket(socketURL, onSocketMessage); +socket(socketURL, onSocketMessage, options.reconnect); diff --git a/client-src/socket.js b/client-src/socket.js index 9268d68a2f..a4bc8f8255 100644 --- a/client-src/socket.js +++ b/client-src/socket.js @@ -1,6 +1,7 @@ /* global __webpack_dev_server_client__ */ import WebSocketClient from "./clients/WebSocketClient.js"; +import { log } from "./utils/log.js"; // this WebsocketClient is here as a default fallback, in case the client is not injected /* eslint-disable camelcase */ @@ -15,13 +16,15 @@ const Client = /* eslint-enable camelcase */ let retries = 0; +let maxRetries = 10; let client = null; -const socket = function initSocket(url, handlers) { +const socket = function initSocket(url, handlers, reconnect) { client = new Client(url); client.onOpen(() => { retries = 0; + maxRetries = reconnect; }); client.onClose(() => { @@ -33,7 +36,7 @@ const socket = function initSocket(url, handlers) { client = null; // After 10 retries stop trying, to prevent logspam. - if (retries <= 10) { + if (retries < maxRetries) { // Exponentially increase timeout to reconnect. // Respectfully copied from the package `got`. // eslint-disable-next-line no-mixed-operators, no-restricted-properties @@ -41,6 +44,8 @@ const socket = function initSocket(url, handlers) { retries += 1; + log.info("Trying to reconnect..."); + setTimeout(() => { socket(url, handlers); }, retryInMs); diff --git a/lib/Server.js b/lib/Server.js index 43e9896fa3..2046a05463 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -258,6 +258,10 @@ class Server { searchParams.set("logging", this.options.client.logging); } + if (typeof this.options.client.reconnect !== "undefined") { + searchParams.set("reconnect", this.options.client.reconnect); + } + webSocketURL = searchParams.toString(); } @@ -474,6 +478,14 @@ class Server { }; } + if (typeof options.client.reconnect === "undefined") { + options.client.reconnect = 10; + } else if (options.client.reconnect === true) { + options.client.reconnect = Infinity; + } else if (options.client.reconnect === false) { + options.client.reconnect = 0; + } + // Respect infrastructureLogging.level if (typeof options.client.logging === "undefined") { options.client.logging = compilerOptions.infrastructureLogging @@ -1627,6 +1639,10 @@ class Server { this.sendMessage([client], "progress", this.options.client.progress); } + if (this.options.client && this.options.client.reconnect) { + this.sendMessage([client], "reconnect", this.options.client.reconnect); + } + if (this.options.client && this.options.client.overlay) { this.sendMessage([client], "overlay", this.options.client.overlay); } diff --git a/lib/options.json b/lib/options.json index 8b1834294a..875e828e82 100644 --- a/lib/options.json +++ b/lib/options.json @@ -59,6 +59,9 @@ "progress": { "$ref": "#/definitions/ClientProgress" }, + "reconnect": { + "$ref": "#/definitions/ClientReconnect" + }, "webSocketTransport": { "$ref": "#/definitions/ClientWebSocketTransport" }, @@ -102,6 +105,19 @@ "link": "https://webpack.js.org/configuration/dev-server/#progress", "type": "boolean" }, + "ClientReconnect": { + "description": "Tells dev-server the number of times it should try to reconnect the client.", + "link": "https://webpack.js.org/configuration/dev-server/#reconnect", + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "number", + "minimum": 0 + } + ] + }, "ClientWebSocketTransport": { "anyOf": [ { diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 93171a058e..26874115f1 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -83,7 +83,7 @@ exports[`options validate should throw an error on the "client" option with '{"l exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -122,16 +122,32 @@ exports[`options validate should throw an error on the "client" option with '{"p -> Read more at https://webpack.js.org/configuration/dev-server/#progress" `; +exports[`options validate should throw an error on the "client" option with '{"reconnect":""}' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.client should be one of these: + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } + -> Allows to specify options for client script in the browser or disable client script. + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient + Details: + * options.client.reconnect should be one of these: + boolean | number (should be >= 0) + -> Tells dev-server the number of times it should try to reconnect the client. + -> Read more at https://webpack.js.org/configuration/dev-server/#reconnect + Details: + * options.client.reconnect should be a boolean. + * options.client.reconnect should be a number (should be >= 0)." +`; + exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client has an unknown property 'unknownOption'. These properties are valid: - object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }" + object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? }" `; exports[`options validate should throw an error on the "client" option with '{"webSocketTransport":true}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -171,7 +187,7 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -186,7 +202,7 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -199,13 +215,13 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: * options.client should be false. * options.client should be an object: - object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }" + object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? }" `; exports[`options validate should throw an error on the "compress" option with '' value 1`] = ` diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 93171a058e..26874115f1 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -83,7 +83,7 @@ exports[`options validate should throw an error on the "client" option with '{"l exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -122,16 +122,32 @@ exports[`options validate should throw an error on the "client" option with '{"p -> Read more at https://webpack.js.org/configuration/dev-server/#progress" `; +exports[`options validate should throw an error on the "client" option with '{"reconnect":""}' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.client should be one of these: + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } + -> Allows to specify options for client script in the browser or disable client script. + -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient + Details: + * options.client.reconnect should be one of these: + boolean | number (should be >= 0) + -> Tells dev-server the number of times it should try to reconnect the client. + -> Read more at https://webpack.js.org/configuration/dev-server/#reconnect + Details: + * options.client.reconnect should be a boolean. + * options.client.reconnect should be a number (should be >= 0)." +`; + exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client has an unknown property 'unknownOption'. These properties are valid: - object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }" + object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? }" `; exports[`options validate should throw an error on the "client" option with '{"webSocketTransport":true}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -171,7 +187,7 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -186,7 +202,7 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: @@ -199,13 +215,13 @@ exports[`options validate should throw an error on the "client" option with '{"w exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.client should be one of these: - false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? } + false | object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? } -> Allows to specify options for client script in the browser or disable client script. -> Read more at https://webpack.js.org/configuration/dev-server/#devserverclient Details: * options.client should be false. * options.client should be an object: - object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }" + object { logging?, overlay?, progress?, reconnect?, webSocketTransport?, webSocketURL? }" `; exports[`options validate should throw an error on the "compress" option with '' value 1`] = ` diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack4 b/test/cli/__snapshots__/basic.test.js.snap.webpack4 index 0e593d2855..e0df6aac4f 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack4 @@ -69,6 +69,8 @@ Options: --no-client-overlay-errors Negative 'client-overlay-errors' option. --client-overlay-warnings Enables a full-screen overlay in the browser when there are compiler warnings. --no-client-overlay-warnings Negative 'client-overlay-warnings' option. + --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. + --no-client-reconnect Tells dev-server to not to try to connect the client. --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. --client-web-socket-url-port Tells clients connected to devServer to use the provided port. diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack5 b/test/cli/__snapshots__/basic.test.js.snap.webpack5 index e9ea671b59..bc996eea90 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack5 @@ -69,6 +69,8 @@ Options: --no-client-overlay-warnings Negative 'client-overlay-warnings' option. --client-progress Prints compilation progress in percentage in the browser. --no-client-progress Negative 'client-progress' option. + --client-reconnect [value] Tells dev-server the number of times it should try to reconnect the client. + --no-client-reconnect Negative 'client-reconnect' option. --client-web-socket-transport Allows to set custom web socket transport to communicate with dev server. --client-web-socket-url Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to). --client-web-socket-url-hostname Tells clients connected to devServer to use the provided hostname. diff --git a/test/cli/client-option.test.js b/test/cli/client-option.test.js index f1592d297f..61a4eb5432 100644 --- a/test/cli/client-option.test.js +++ b/test/cli/client-option.test.js @@ -105,6 +105,33 @@ describe('"client" CLI option', () => { expect(exitCode).toEqual(0); }); + it('should work using "--client-reconnect"', async () => { + const { exitCode } = await testBin(["--port", port, "--client-reconnect"]); + + expect(exitCode).toEqual(0); + }); + + it('should work using "--client-reconnect "', async () => { + const { exitCode } = await testBin([ + "--port", + port, + "--client-reconnect", + 5, + ]); + + expect(exitCode).toEqual(0); + }); + + it('should work using "--no-client-reconnect"', async () => { + const { exitCode } = await testBin([ + "--port", + port, + "--no-client-reconnect", + ]); + + expect(exitCode).toEqual(0); + }); + it('should work using "--client-web-socket-url"', async () => { const { exitCode } = await testBin([ "--port", diff --git a/test/client/__snapshots__/index.test.js.snap.webpack4 b/test/client/__snapshots__/index.test.js.snap.webpack4 index 49d113ed5d..21fe0b8a7c 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack4 +++ b/test/client/__snapshots__/index.test.js.snap.webpack4 @@ -27,6 +27,7 @@ Object { "logging": "info", "overlay": false, "progress": false, + "reconnect": 10, } `; @@ -88,10 +89,12 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "reconnect": [Function], "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, + 10, ] `; diff --git a/test/client/__snapshots__/index.test.js.snap.webpack5 b/test/client/__snapshots__/index.test.js.snap.webpack5 index 49d113ed5d..21fe0b8a7c 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack5 +++ b/test/client/__snapshots__/index.test.js.snap.webpack5 @@ -27,6 +27,7 @@ Object { "logging": "info", "overlay": false, "progress": false, + "reconnect": 10, } `; @@ -88,10 +89,12 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "reconnect": [Function], "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, + 10, ] `; diff --git a/test/client/index.test.js b/test/client/index.test.js index 34fafa793b..6d98a0937b 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -57,6 +57,7 @@ describe("index", () => { jest.setMock("../../client-src/utils/parseURL.js", () => { return { logging: "info", + reconnect: 10, }; }); diff --git a/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack4 b/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack4 index 7243c67af4..98f1f1b688 100644 --- a/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack4 @@ -260,6 +260,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -271,6 +272,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -282,6 +284,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -293,6 +296,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; diff --git a/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack5 b/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack5 index 7243c67af4..98f1f1b688 100644 --- a/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/allowed-hosts.test.js.snap.webpack5 @@ -260,6 +260,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -271,6 +272,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -282,6 +284,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -293,6 +296,7 @@ Array [ "Hey.", "[webpack-dev-server] Invalid Host/Origin header", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; diff --git a/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack4 b/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack4 new file mode 100644 index 0000000000..a4e3a9badb --- /dev/null +++ b/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack4 @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`client.reconnect option specified as false should not try to reconnect: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", + "[webpack-dev-server] Disconnected!", +] +`; + +exports[`client.reconnect option specified as false should not try to reconnect: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as false should not try to reconnect: response status 1`] = `200`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", + "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", + "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "[webpack-dev-server] JSHandle@object", + "[webpack-dev-server] Trying to reconnect...", + "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "[webpack-dev-server] JSHandle@object", +] +`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: response status 1`] = `200`; + +exports[`client.reconnect option specified as true should try to reconnect unlimited times: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as true should try to reconnect unlimited times: response status 1`] = `200`; diff --git a/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 b/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 new file mode 100644 index 0000000000..a4e3a9badb --- /dev/null +++ b/test/e2e/__snapshots__/client-reconnect.test.js.snap.webpack5 @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`client.reconnect option specified as false should not try to reconnect: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", + "[webpack-dev-server] Disconnected!", +] +`; + +exports[`client.reconnect option specified as false should not try to reconnect: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as false should not try to reconnect: response status 1`] = `200`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: console messages 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[webpack-dev-server] Hot Module Replacement enabled.", + "[webpack-dev-server] Live Reloading enabled.", + "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", + "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "[webpack-dev-server] JSHandle@object", + "[webpack-dev-server] Trying to reconnect...", + "WebSocket connection to 'ws://127.0.0.1:8163/ws' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED", + "[webpack-dev-server] JSHandle@object", +] +`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as number should try to reconnect 2 times: response status 1`] = `200`; + +exports[`client.reconnect option specified as true should try to reconnect unlimited times: page errors 1`] = `Array []`; + +exports[`client.reconnect option specified as true should try to reconnect unlimited times: response status 1`] = `200`; diff --git a/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack4 b/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack4 index 77b81321c4..c0b53e0646 100644 --- a/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack4 @@ -72,6 +72,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "liveReload", "[webpack-dev-server] Live Reloading enabled.", + "reconnect", "overlay", "hash", "ok", diff --git a/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack5 b/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack5 index 77b81321c4..c0b53e0646 100644 --- a/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/server-and-client-transport.test.js.snap.webpack5 @@ -72,6 +72,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "liveReload", "[webpack-dev-server] Live Reloading enabled.", + "reconnect", "overlay", "hash", "ok", diff --git a/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack4 b/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack4 index d1cd9ca1fb..6296cfb6b7 100644 --- a/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack4 @@ -7,6 +7,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -19,6 +20,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -31,6 +33,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] App hot update...", @@ -54,6 +57,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] App hot update...", diff --git a/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack5 b/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack5 index d1cd9ca1fb..6296cfb6b7 100644 --- a/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/web-socket-communication.test.js.snap.webpack5 @@ -7,6 +7,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -19,6 +20,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", ] `; @@ -31,6 +33,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] App hot update...", @@ -54,6 +57,7 @@ Array [ "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] Disconnected!", + "[webpack-dev-server] Trying to reconnect...", "[webpack-dev-server] Hot Module Replacement enabled.", "[webpack-dev-server] Live Reloading enabled.", "[webpack-dev-server] App hot update...", diff --git a/test/e2e/client-reconnect.test.js b/test/e2e/client-reconnect.test.js new file mode 100644 index 0000000000..1e9958f3bd --- /dev/null +++ b/test/e2e/client-reconnect.test.js @@ -0,0 +1,170 @@ +"use strict"; + +const webpack = require("webpack"); +const Server = require("../../lib/Server"); +const config = require("../fixtures/simple-config/webpack.config"); +const runBrowser = require("../helpers/run-browser"); +const port = require("../ports-map")["client-reconnect-option"]; + +describe("client.reconnect option", () => { + describe("specified as true", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server({ port, client: { reconnect: true } }, compiler); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + }); + + it("should try to reconnect unlimited times", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.status()).toMatchSnapshot("response status"); + + await server.stop(); + // Can't wait to check for unlimited times so wait only for 5-6 retries + // eslint-disable-next-line no-restricted-properties + await page.waitForTimeout(1000 * Math.pow(2, 5) + Math.random() * 100); + + const retryingMessages = consoleMessages.filter((message) => + message.text().includes("Trying to reconnect...") + ); + + // snapshot can be different on different CI jobs + expect(retryingMessages.length).toBeGreaterThanOrEqual(5); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("specified as false", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server({ port, client: { reconnect: false } }, compiler); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + }); + + it("should not try to reconnect", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.status()).toMatchSnapshot("response status"); + + await server.stop(); + // Can't wait to check for unlimited times so wait only for 5-6 retries + // eslint-disable-next-line no-restricted-properties + await page.waitForTimeout(1000 * Math.pow(2, 2) + Math.random() * 100); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); + + describe("specified as number", () => { + let compiler; + let server; + let page; + let browser; + let pageErrors; + let consoleMessages; + + beforeEach(async () => { + compiler = webpack(config); + + server = new Server({ port, client: { reconnect: 2 } }, compiler); + + await server.start(); + + ({ page, browser } = await runBrowser()); + + pageErrors = []; + consoleMessages = []; + }); + + afterEach(async () => { + await browser.close(); + }); + + it("should try to reconnect 2 times", async () => { + page + .on("console", (message) => { + consoleMessages.push(message); + }) + .on("pageerror", (error) => { + pageErrors.push(error); + }); + + const response = await page.goto(`http://127.0.0.1:${port}/main`, { + waitUntil: "networkidle0", + }); + + expect(response.status()).toMatchSnapshot("response status"); + + await server.stop(); + // eslint-disable-next-line no-restricted-properties + await page.waitForTimeout(1000 * Math.pow(2, 3) + Math.random() * 100); + + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( + "console messages" + ); + + expect(pageErrors).toMatchSnapshot("page errors"); + }); + }); +}); diff --git a/test/ports-map.js b/test/ports-map.js index 5baca5aebb..f2bc714e5a 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -74,6 +74,7 @@ const listOfTests = { "range-header": 1, port: 1, "web-socket-server-test": 1, + "client-reconnect-option": 1, }; let startPort = 8089; diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index 2dc0dca68a..2d257aa5ef 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -63,6 +63,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -105,6 +106,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -147,6 +149,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "/path/to/custom/client/", "webSocketURL": Object {}, }, @@ -190,6 +193,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "hostname": "my.host", "port": 9000, @@ -235,6 +239,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "hostname": "my.host", "port": 9000, @@ -280,6 +285,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "pathname": "/custom/path/", }, @@ -324,6 +330,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "pathname": "custom/path", }, @@ -368,6 +375,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "sockjs", "webSocketURL": Object {}, }, @@ -411,6 +419,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -454,6 +463,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -499,6 +509,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -544,6 +555,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -587,6 +599,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -631,6 +644,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -673,6 +687,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -715,6 +730,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -757,6 +773,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -799,6 +816,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -841,6 +859,7 @@ Object { "client": Object { "logging": "none", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -883,6 +902,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -925,6 +945,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -967,6 +988,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1009,6 +1031,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1051,6 +1074,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1093,6 +1117,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1135,6 +1160,7 @@ Object { "client": Object { "logging": "verbose", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1177,6 +1203,7 @@ Object { "client": Object { "logging": "none", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1219,6 +1246,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1263,6 +1291,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1307,6 +1336,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1351,6 +1381,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1395,6 +1426,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1448,6 +1480,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1501,6 +1534,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1554,6 +1588,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1596,6 +1631,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1626,6 +1662,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1668,6 +1705,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1710,6 +1748,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1752,6 +1791,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1795,6 +1835,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1837,6 +1878,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1877,6 +1919,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1919,6 +1962,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1963,6 +2007,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2005,6 +2050,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2047,6 +2093,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "password": "chuntaro", "username": "zenitsu", @@ -2092,6 +2139,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2134,6 +2182,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index 2dc0dca68a..2d257aa5ef 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info&reconnect=10", ], Array [ "node_modules", @@ -63,6 +63,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -105,6 +106,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -147,6 +149,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "/path/to/custom/client/", "webSocketURL": Object {}, }, @@ -190,6 +193,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "hostname": "my.host", "port": 9000, @@ -235,6 +239,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "hostname": "my.host", "port": 9000, @@ -280,6 +285,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "pathname": "/custom/path/", }, @@ -324,6 +330,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "pathname": "custom/path", }, @@ -368,6 +375,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "sockjs", "webSocketURL": Object {}, }, @@ -411,6 +419,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -454,6 +463,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -499,6 +509,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -544,6 +555,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketTransport": "ws", "webSocketURL": Object {}, }, @@ -587,6 +599,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -631,6 +644,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -673,6 +687,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -715,6 +730,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -757,6 +773,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -799,6 +816,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -841,6 +859,7 @@ Object { "client": Object { "logging": "none", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -883,6 +902,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -925,6 +945,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -967,6 +988,7 @@ Object { "client": Object { "logging": "warn", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1009,6 +1031,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1051,6 +1074,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1093,6 +1117,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1135,6 +1160,7 @@ Object { "client": Object { "logging": "verbose", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1177,6 +1203,7 @@ Object { "client": Object { "logging": "none", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1219,6 +1246,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1263,6 +1291,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1307,6 +1336,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1351,6 +1381,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1395,6 +1426,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1448,6 +1480,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1501,6 +1534,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1554,6 +1588,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1596,6 +1631,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1626,6 +1662,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1668,6 +1705,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1710,6 +1748,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1752,6 +1791,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1795,6 +1835,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1837,6 +1878,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1877,6 +1919,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1919,6 +1962,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -1963,6 +2007,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2005,6 +2050,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2047,6 +2093,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object { "password": "chuntaro", "username": "zenitsu", @@ -2092,6 +2139,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, @@ -2134,6 +2182,7 @@ Object { "client": Object { "logging": "info", "overlay": true, + "reconnect": 10, "webSocketURL": Object {}, }, "compress": true, diff --git a/test/validate-options.test.js b/test/validate-options.test.js index f79893f24b..bb319acef6 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -50,6 +50,15 @@ const tests = { { progress: false, }, + { + reconnect: false, + }, + { + reconnect: true, + }, + { + reconnect: 5, + }, { overlay: true, }, @@ -115,6 +124,9 @@ const tests = { { progress: "", }, + { + reconnect: "", + }, { overlay: "", },