Skip to content

Commit

Permalink
feat: enable overlay by default (#3108)
Browse files Browse the repository at this point in the history
Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
  • Loading branch information
snitin315 and rishabh3112 committed Mar 25, 2021
1 parent 45b698d commit 5e05e48
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/utils/normalizeOptions.js
Expand Up @@ -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'
}`;
Expand Down
1 change: 1 addition & 0 deletions test/e2e/__snapshots__/TransportMode.test.js.snap
Expand Up @@ -6,6 +6,7 @@ Array [
"open",
"liveReload",
"[webpack-dev-server] Live Reloading enabled.",
"overlay",
"hash",
"ok",
"close",
Expand Down
4 changes: 4 additions & 0 deletions test/server/clientOptions-option.test.js
Expand Up @@ -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);
});
Expand Down
8 changes: 4 additions & 4 deletions test/server/transportMode-option.test.js
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions test/server/utils/__snapshots__/normalizeOptions.test.js.snap
Expand Up @@ -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,
},
Expand Down Expand Up @@ -35,6 +36,7 @@ Object {
exports[`normalizeOptions client path should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/custom/path",
},
"dev": Object {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -95,6 +98,7 @@ Object {
exports[`normalizeOptions dev is set should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {
Expand Down Expand Up @@ -127,6 +131,7 @@ Object {
exports[`normalizeOptions firewall is set should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -157,6 +162,7 @@ Object {
exports[`normalizeOptions hot is false should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -187,6 +193,7 @@ Object {
exports[`normalizeOptions hot is only should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -217,6 +224,7 @@ Object {
exports[`normalizeOptions hot is true should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -247,6 +255,7 @@ Object {
exports[`normalizeOptions liveReload is false should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -277,6 +286,7 @@ Object {
exports[`normalizeOptions liveReload is true should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -339,6 +350,7 @@ Object {
exports[`normalizeOptions no options should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -648,6 +668,7 @@ Object {
exports[`normalizeOptions static is false should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand All @@ -666,6 +687,7 @@ Object {
exports[`normalizeOptions static is string should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -696,6 +718,7 @@ Object {
exports[`normalizeOptions static is true should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -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 {},
Expand Down Expand Up @@ -1057,6 +1091,7 @@ Object {
exports[`normalizeOptions transportMode sockjs string should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -1087,6 +1122,7 @@ Object {
exports[`normalizeOptions transportMode ws object should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down Expand Up @@ -1117,6 +1153,7 @@ Object {
exports[`normalizeOptions transportMode ws string should set correct options 1`] = `
Object {
"client": Object {
"overlay": true,
"path": "/ws",
},
"dev": Object {},
Expand Down

0 comments on commit 5e05e48

Please sign in to comment.