From bfc6da202a6b0cd4e35f0ecf75962e64ffac1845 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 25 Mar 2021 21:47:18 +0530 Subject: [PATCH] feat: enable overlay by default Co-authored-by: Rishabh Chawla --- lib/utils/normalizeOptions.js | 5 +++ .../__snapshots__/TransportMode.test.js.snap | 1 + test/server/clientOptions-option.test.js | 4 ++ test/server/transportMode-option.test.js | 8 ++-- .../normalizeOptions.test.js.snap | 37 +++++++++++++++++++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index 3534947759..9706911c91 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -98,6 +98,11 @@ function normalizeOptions(compiler, options) { options.client = {}; } + // Enable client overlay by default + if (typeof options.client.overlay === 'undefined') { + options.client.overlay = true; + } + options.client.path = `/${ options.client.path ? options.client.path.replace(/^\/|\/$/g, '') : 'ws' }`; diff --git a/test/e2e/__snapshots__/TransportMode.test.js.snap b/test/e2e/__snapshots__/TransportMode.test.js.snap index a353f22048..141e201c4e 100644 --- a/test/e2e/__snapshots__/TransportMode.test.js.snap +++ b/test/e2e/__snapshots__/TransportMode.test.js.snap @@ -6,6 +6,7 @@ Array [ "open", "liveReload", "[webpack-dev-server] Live Reloading enabled.", + "overlay", "hash", "ok", "close", diff --git a/test/server/clientOptions-option.test.js b/test/server/clientOptions-option.test.js index ecc12a3771..8debb1ce3b 100644 --- a/test/server/clientOptions-option.test.js +++ b/test/server/clientOptions-option.test.js @@ -34,6 +34,10 @@ describe('client option', () => { ).toBeTruthy(); }); + it('overlay true by default', () => { + expect(server.options.client.overlay).toBe(true); + }); + it('responds with a 200', (done) => { req.get('/ws').expect(200, done); }); diff --git a/test/server/transportMode-option.test.js b/test/server/transportMode-option.test.js index eff136c60c..e23829079b 100644 --- a/test/server/transportMode-option.test.js +++ b/test/server/transportMode-option.test.js @@ -482,14 +482,14 @@ describe('transportMode', () => { expect(MockWebsocketServer.mock.calls[0][0].options.port).toEqual(port); expect(mockServerInstance.onConnection.mock.calls).toMatchSnapshot(); - expect(mockServerInstance.send.mock.calls.length).toEqual(4); + expect(mockServerInstance.send.mock.calls.length).toEqual(5); // call 0 to the send() method is hot expect(mockServerInstance.send.mock.calls[0]).toMatchSnapshot(); // call 1 to the send() method is liveReload expect(mockServerInstance.send.mock.calls[1]).toMatchSnapshot(); - // call 2 to the send() method is hash data, so we skip it - // call 3 to the send() method is the "ok" message - expect(mockServerInstance.send.mock.calls[3]).toMatchSnapshot(); + // call 3 to the send() method is hash data, so we skip it + // call 4 to the send() method is the "ok" message + expect(mockServerInstance.send.mock.calls[4]).toMatchSnapshot(); // close should not be called because the server never forcefully closes // a successful client connection expect(mockServerInstance.close.mock.calls.length).toEqual(0); diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap index 3a0b3d6f6f..629ddb411d 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap @@ -4,6 +4,7 @@ exports[`normalizeOptions client host and port should set correct options 1`] = Object { "client": Object { "host": "my.host", + "overlay": true, "path": "/ws", "port": 9000, }, @@ -35,6 +36,7 @@ Object { exports[`normalizeOptions client path should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/custom/path", }, "dev": Object {}, @@ -65,6 +67,7 @@ Object { exports[`normalizeOptions client path without leading/ending slashes should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/custom/path", }, "dev": Object {}, @@ -95,6 +98,7 @@ Object { exports[`normalizeOptions dev is set should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object { @@ -127,6 +131,7 @@ Object { exports[`normalizeOptions firewall is set should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -157,6 +162,7 @@ Object { exports[`normalizeOptions hot is false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -187,6 +193,7 @@ Object { exports[`normalizeOptions hot is only should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -217,6 +224,7 @@ Object { exports[`normalizeOptions hot is true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -247,6 +255,7 @@ Object { exports[`normalizeOptions liveReload is false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -277,6 +286,7 @@ Object { exports[`normalizeOptions liveReload is true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -307,6 +317,7 @@ Object { exports[`normalizeOptions multi compiler watchOptions is set should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -339,6 +350,7 @@ Object { exports[`normalizeOptions no options should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -369,6 +381,7 @@ Object { exports[`normalizeOptions single compiler watchOptions is object should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -401,6 +414,7 @@ Object { exports[`normalizeOptions single compiler watchOptions is object with static watch overriding it should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -433,6 +447,7 @@ Object { exports[`normalizeOptions single compiler watchOptions is object with static watch true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -465,6 +480,7 @@ Object { exports[`normalizeOptions single compiler watchOptions is object with watch false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -495,6 +511,7 @@ Object { exports[`normalizeOptions static is an array of static objects should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -536,6 +553,7 @@ Object { exports[`normalizeOptions static is an array of strings and static objects should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -577,6 +595,7 @@ Object { exports[`normalizeOptions static is an array of strings should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -618,6 +637,7 @@ Object { exports[`normalizeOptions static is an object should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -648,6 +668,7 @@ Object { exports[`normalizeOptions static is false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -666,6 +687,7 @@ Object { exports[`normalizeOptions static is string should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -696,6 +718,7 @@ Object { exports[`normalizeOptions static is true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -726,6 +749,7 @@ Object { exports[`normalizeOptions static publicPath is a string should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -756,6 +780,7 @@ Object { exports[`normalizeOptions static publicPath is an array should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -787,6 +812,7 @@ Object { exports[`normalizeOptions static serveIndex is an object should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -817,6 +843,7 @@ Object { exports[`normalizeOptions static serveIndex is false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -845,6 +872,7 @@ Object { exports[`normalizeOptions static serveIndex is true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -875,6 +903,7 @@ Object { exports[`normalizeOptions static watch is an object should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -907,6 +936,7 @@ Object { exports[`normalizeOptions static watch is false should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -937,6 +967,7 @@ Object { exports[`normalizeOptions static watch is true should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -967,6 +998,7 @@ Object { exports[`normalizeOptions transportMode custom client path should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -997,6 +1029,7 @@ Object { exports[`normalizeOptions transportMode custom server class should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -1027,6 +1060,7 @@ Object { exports[`normalizeOptions transportMode custom server path should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -1057,6 +1091,7 @@ Object { exports[`normalizeOptions transportMode sockjs string should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -1087,6 +1122,7 @@ Object { exports[`normalizeOptions transportMode ws object should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {}, @@ -1117,6 +1153,7 @@ Object { exports[`normalizeOptions transportMode ws string should set correct options 1`] = ` Object { "client": Object { + "overlay": true, "path": "/ws", }, "dev": Object {},