From 26902603e69b608fda820b3c0b527393c5e9c6f1 Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Wed, 13 May 2020 08:07:07 +0200 Subject: [PATCH 1/6] fix: disable socket injection when hot & liveReload are disabled --- client-src/default/index.js | 6 +- lib/Server.js | 4 +- test/client/__snapshots__/index.test.js.snap | 10 +- test/client/index.test.js | 16 + test/e2e/ClientOptions.test.js | 93 ++-- test/e2e/Socket-injection.test.js | 403 ++++++++++++++++++ .../__snapshots__/ClientOptions.test.js.snap | 121 +++++- 7 files changed, 608 insertions(+), 45 deletions(-) create mode 100644 test/e2e/Socket-injection.test.js diff --git a/client-src/default/index.js b/client-src/default/index.js index dede6f0763..4c06a70b7e 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -136,7 +136,11 @@ const onSocketMessage = { log.error(error); }, close() { - log.error('[WDS] Disconnected!'); + if (options.hot || options.liveReload) { + log.error('[WDS] Disconnected!'); + } else { + log.error('[WDS] Hot Module Replacement & Live Reloading are disabled!'); + } sendMessage('Close'); }, }; diff --git a/lib/Server.js b/lib/Server.js index 4043b354ee..671db1fca5 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -678,7 +678,9 @@ class Server { this.hostname = hostname; return this.listeningApp.listen(port, hostname, (err) => { - this.createSocketServer(); + if (this.options.hot || this.options.liveReload !== false) { + this.createSocketServer(); + } if (this.options.bonjour) { runBonjour(this.options); diff --git a/test/client/__snapshots__/index.test.js.snap b/test/client/__snapshots__/index.test.js.snap index cc267a2ce7..f3c4b1e27e 100644 --- a/test/client/__snapshots__/index.test.js.snap +++ b/test/client/__snapshots__/index.test.js.snap @@ -1,6 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`index should run onSocketMessage.close 1`] = `"[WDS] Disconnected!"`; +exports[`index should run onSocketMessage.close (hot enabled) 1`] = `"[WDS] Disconnected!"`; + +exports[`index should run onSocketMessage.close (hot enabled) 2`] = `"Close"`; + +exports[`index should run onSocketMessage.close (liveReload enabled) 1`] = `"[WDS] Disconnected!"`; + +exports[`index should run onSocketMessage.close (liveReload enabled) 2`] = `"Close"`; + +exports[`index should run onSocketMessage.close 1`] = `"[WDS] Hot Module Replacement & Live Reloading are disabled!"`; exports[`index should run onSocketMessage.close 2`] = `"Close"`; diff --git a/test/client/index.test.js b/test/client/index.test.js index ba402a2dd9..f2196febae 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -214,4 +214,20 @@ describe('index', () => { expect(log.log.error.mock.calls[0][0]).toMatchSnapshot(); expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); }); + + test('should run onSocketMessage.close (hot enabled)', () => { + // enabling hot + onSocketMessage.hot(); + onSocketMessage.close(); + expect(log.log.error.mock.calls[0][0]).toMatchSnapshot(); + expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); + }); + + test('should run onSocketMessage.close (liveReload enabled)', () => { + // enabling liveReload + onSocketMessage.liveReload(); + onSocketMessage.close(); + expect(log.log.error.mock.calls[0][0]).toMatchSnapshot(); + expect(sendMessage.mock.calls[0][0]).toMatchSnapshot(); + }); }); diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index 4847f2a6a6..ee83900048 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -365,6 +365,12 @@ describe('Client console.log', () => { port: port2, host: '0.0.0.0', }; + const transportModes = [ + {}, + { transportMode: 'sockjs' }, + { transportMode: 'ws' }, + ]; + const cases = [ { title: 'hot disabled', @@ -390,6 +396,13 @@ describe('Client console.log', () => { liveReload: true, }, }, + { + title: 'liveReload & hot are disabled', + options: { + liveReload: false, + hot: false, + }, + }, // TODO: make clientLogLevel work as expected for HMR logs { title: 'clientLogLevel is silent', @@ -399,48 +412,54 @@ describe('Client console.log', () => { }, ]; - cases.forEach(({ title, options }) => { - it(title, (done) => { - const res = []; - const testOptions = Object.assign({}, baseOptions, options); - - // TODO: use async/await when Node.js v6 support is dropped - Promise.resolve() - .then(() => { - return new Promise((resolve) => { - testServer.startAwaitingCompilation(config, testOptions, resolve); - }); - }) - .then(() => { - // make sure the previous Promise is not passing along strange arguments to runBrowser - return runBrowser(); - }) - .then(({ page, browser }) => { - return new Promise((resolve) => { - page.goto(`http://localhost:${port2}/main`); - page.on('console', ({ _text }) => { - res.push(_text); + transportModes.forEach((mode) => { + cases.forEach(({ title, options }) => { + title += ` (${ + Object.keys(mode).length ? mode.transportMode : 'default' + })`; + options = { ...mode, ...options }; + it(title, (done) => { + const res = []; + const testOptions = Object.assign({}, baseOptions, options); + + // TODO: use async/await when Node.js v6 support is dropped + Promise.resolve() + .then(() => { + return new Promise((resolve) => { + testServer.startAwaitingCompilation(config, testOptions, resolve); }); - // wait for load before closing the browser - page.waitForNavigation({ waitUntil: 'load' }).then(() => { - page.waitFor(beforeBrowserCloseDelay).then(() => { - browser.close().then(() => { - resolve(); + }) + .then(() => { + // make sure the previous Promise is not passing along strange arguments to runBrowser + return runBrowser(); + }) + .then(({ page, browser }) => { + return new Promise((resolve) => { + page.goto(`http://localhost:${port2}/main`); + page.on('console', ({ _text }) => { + res.push(_text); + }); + // wait for load before closing the browser + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + resolve(); + }); }); }); }); + }) + .then(() => { + return new Promise((resolve) => { + testServer.close(resolve); + }); + }) + .then(() => { + // Order doesn't matter, maybe we should improve that in future + expect(res.sort()).toMatchSnapshot(); + done(); }); - }) - .then(() => { - return new Promise((resolve) => { - testServer.close(resolve); - }); - }) - .then(() => { - // Order doesn't matter, maybe we should improve that in future - expect(res.sort()).toMatchSnapshot(); - done(); - }); + }); }); }); }); diff --git a/test/e2e/Socket-injection.test.js b/test/e2e/Socket-injection.test.js new file mode 100644 index 0000000000..2005af6796 --- /dev/null +++ b/test/e2e/Socket-injection.test.js @@ -0,0 +1,403 @@ +'use strict'; + +/* eslint-disable + no-unused-vars +*/ + +const express = require('express'); +const request = require('supertest'); +const testServer = require('../helpers/test-server'); +const runBrowser = require('../helpers/run-browser'); +const port = require('../ports-map').WebsocketClient; +const config = require('../fixtures/client-config/webpack.config'); +const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants'); + +const transportModeWSValidOptions = [{}, { transportMode: 'ws' }]; + +describe('ws websocket client injection', () => { + for (const wsOption of transportModeWSValidOptions) { + let req; + let server; + const errorMsg = `WebSocket connection to 'ws://localhost:${port}/ws' failed: Error during WebSocket handshake: Unexpected response code: 404`; + const res = []; + + describe('testing default settings', () => { + beforeAll((done) => { + const options = { + port, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when liveReload is enabled', () => { + beforeAll((done) => { + const options = { + port, + liveReload: true, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when liveReload is disabled', () => { + beforeAll((done) => { + const options = { + port, + liveReload: false, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when hot is enabled', () => { + beforeAll((done) => { + const options = { + port, + hot: true, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when hot is enabled and liveReload is disabled', () => { + beforeAll((done) => { + const options = { + port, + hot: true, + liveReload: false, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when hot is disabled and liveReload is enabled', () => { + beforeAll((done) => { + const options = { + port, + hot: false, + liveReload: true, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(false); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + + describe('testing when hot and liveReload are disabled', () => { + beforeAll((done) => { + const options = { + port, + hot: false, + liveReload: false, + ...wsOption, + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should not be injected', (done) => { + // TODO: listen for websocket requestType via puppeteer when added + // to puppeteer: https://github.com/puppeteer/puppeteer/issues/2974 + runBrowser().then(({ page, browser }) => { + page.on('console', ({ _text }) => { + res.push(_text); + }); + page.waitForNavigation({ waitUntil: 'load' }).then(() => { + page.waitFor(beforeBrowserCloseDelay).then(() => { + browser.close().then(() => { + // if the error msg doesn't exist that means the ws websocket is working. + expect(res.includes(errorMsg)).toBe(true); + done(); + }); + }); + }); + page.goto(`http://localhost:${port}/main`); + }); + }); + }); + } +}); + +describe('sockjs websocket client injection', () => { + let req; + let server; + + describe('testing default settings', () => { + beforeAll((done) => { + const options = { + port, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when liveReload is enabled', () => { + beforeAll((done) => { + const options = { + port, + liveReload: true, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when liveReload is disabled', () => { + beforeAll((done) => { + const options = { + port, + liveReload: false, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when hot is enabled', () => { + beforeAll((done) => { + const options = { + port, + hot: true, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when hot is enabled and liveReload is disabled', () => { + beforeAll((done) => { + const options = { + port, + hot: true, + liveReload: false, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when hot is disabled and liveReload is enabled', () => { + beforeAll((done) => { + const options = { + port, + hot: false, + liveReload: true, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should be injected', (done) => { + req.get('/ws').expect(200, 'Welcome to SockJS!\n', done); + }); + }); + + describe('testing when hot and liveReload are disabled', () => { + beforeAll((done) => { + const options = { + port, + hot: false, + liveReload: false, + transportMode: 'sockjs', + }; + server = testServer.start(config, options, done); + req = request(`http://localhost:${port}`); + }); + + afterAll(testServer.close); + + it('should not be injected', (done) => { + req + .get('/ws') + .expect(404) + .then(({ res }) => { + expect(res.text.includes('Cannot GET /ws')).toBe(true); + done(); + }); + }); + }); +}); diff --git a/test/e2e/__snapshots__/ClientOptions.test.js.snap b/test/e2e/__snapshots__/ClientOptions.test.js.snap index d3040d3f2c..72d313bf8a 100644 --- a/test/e2e/__snapshots__/ClientOptions.test.js.snap +++ b/test/e2e/__snapshots__/ClientOptions.test.js.snap @@ -1,20 +1,48 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Client console.log clientLogLevel is silent 1`] = ` +exports[`Client console.log clientLogLevel is silent (default) 1`] = ` Array [ "Hey.", "[HMR] Waiting for update signal from WDS...", ] `; -exports[`Client console.log hot disabled 1`] = ` +exports[`Client console.log clientLogLevel is silent (sockjs) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", +] +`; + +exports[`Client console.log clientLogLevel is silent (ws) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", +] +`; + +exports[`Client console.log hot disabled (default) 1`] = ` Array [ "Hey.", "[WDS] Live Reloading enabled.", ] `; -exports[`Client console.log hot enabled 1`] = ` +exports[`Client console.log hot disabled (sockjs) 1`] = ` +Array [ + "Hey.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log hot disabled (ws) 1`] = ` +Array [ + "Hey.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log hot enabled (default) 1`] = ` Array [ "Hey.", "[HMR] Waiting for update signal from WDS...", @@ -23,15 +51,98 @@ Array [ ] `; -exports[`Client console.log liveReload disabled 1`] = ` +exports[`Client console.log hot enabled (sockjs) 1`] = ` Array [ "Hey.", "[HMR] Waiting for update signal from WDS...", "[WDS] Hot Module Replacement enabled.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log hot enabled (ws) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log liveReload & hot are disabled (default) 1`] = ` +Array [ + "Hey.", + "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "[WDS] Disconnected!", + "[WDS] JSHandle@object", + "[WDS] JSHandle@object", +] +`; + +exports[`Client console.log liveReload & hot are disabled (sockjs) 1`] = ` +Array [ + "Failed to load resource: the server responded with a status of 404 (Not Found)", + "Failed to load resource: the server responded with a status of 404 (Not Found)", + "Hey.", + "[WDS] Disconnected!", +] +`; + +exports[`Client console.log liveReload & hot are disabled (ws) 1`] = ` +Array [ + "Hey.", + "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", + "[WDS] Disconnected!", + "[WDS] JSHandle@object", + "[WDS] JSHandle@object", +] +`; + +exports[`Client console.log liveReload disabled (default) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", +] +`; + +exports[`Client console.log liveReload disabled (sockjs) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", +] +`; + +exports[`Client console.log liveReload disabled (ws) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", +] +`; + +exports[`Client console.log liveReload enabled (default) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log liveReload enabled (sockjs) 1`] = ` +Array [ + "Hey.", + "[HMR] Waiting for update signal from WDS...", + "[WDS] Hot Module Replacement enabled.", + "[WDS] Live Reloading enabled.", ] `; -exports[`Client console.log liveReload enabled 1`] = ` +exports[`Client console.log liveReload enabled (ws) 1`] = ` Array [ "Hey.", "[HMR] Waiting for update signal from WDS...", From 8ca60c93999b99a3ae62236dea1974b7b79df5a1 Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Wed, 13 May 2020 08:47:23 +0200 Subject: [PATCH 2/6] test: update snapshot --- test/e2e/__snapshots__/ClientOptions.test.js.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/__snapshots__/ClientOptions.test.js.snap b/test/e2e/__snapshots__/ClientOptions.test.js.snap index 72d313bf8a..4b7bbaea75 100644 --- a/test/e2e/__snapshots__/ClientOptions.test.js.snap +++ b/test/e2e/__snapshots__/ClientOptions.test.js.snap @@ -74,7 +74,7 @@ Array [ "Hey.", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", - "[WDS] Disconnected!", + "[WDS] Hot Module Replacement & Live Reloading are disabled!", "[WDS] JSHandle@object", "[WDS] JSHandle@object", ] @@ -85,7 +85,7 @@ Array [ "Failed to load resource: the server responded with a status of 404 (Not Found)", "Failed to load resource: the server responded with a status of 404 (Not Found)", "Hey.", - "[WDS] Disconnected!", + "[WDS] Hot Module Replacement & Live Reloading are disabled!", ] `; @@ -94,7 +94,7 @@ Array [ "Hey.", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", - "[WDS] Disconnected!", + "[WDS] Hot Module Replacement & Live Reloading are disabled!", "[WDS] JSHandle@object", "[WDS] JSHandle@object", ] From 564dc7a852177993a63c1c3e883829f91ea53b1f Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Wed, 13 May 2020 12:57:19 +0200 Subject: [PATCH 3/6] test: normalize liveReload option --- lib/Server.js | 4 ++-- test/server/__snapshots__/transportMode-option.test.js.snap | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 671db1fca5..0935f09655 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -678,7 +678,7 @@ class Server { this.hostname = hostname; return this.listeningApp.listen(port, hostname, (err) => { - if (this.options.hot || this.options.liveReload !== false) { + if (this.options.hot || this.options.liveReload) { this.createSocketServer(); } @@ -925,7 +925,7 @@ class Server { const watcher = chokidar.watch(watchPath, watchOptions); // disabling refreshing on changing the content - if (this.options.liveReload !== false) { + if (this.options.liveReload) { watcher.on('change', () => { this.sockWrite(this.sockets, 'content-changed'); }); diff --git a/test/server/__snapshots__/transportMode-option.test.js.snap b/test/server/__snapshots__/transportMode-option.test.js.snap index cb0a1037ca..daf1f29b01 100644 --- a/test/server/__snapshots__/transportMode-option.test.js.snap +++ b/test/server/__snapshots__/transportMode-option.test.js.snap @@ -96,7 +96,7 @@ Array [ Object { "foo": "bar", }, - "{\\"type\\":\\"liveReload\\"}", + "{\\"type\\":\\"liveReload\\",\\"data\\":true}", ] `; From 0f3674d77bc28a2f48d79af5cc76ecc643ef824f Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Tue, 19 May 2020 17:47:09 +0200 Subject: [PATCH 4/6] test: remove unnecessary console msg --- client-src/default/index.js | 7 ++----- test/e2e/__snapshots__/ClientOptions.test.js.snap | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/client-src/default/index.js b/client-src/default/index.js index 4c06a70b7e..1cbf5372d9 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -136,11 +136,8 @@ const onSocketMessage = { log.error(error); }, close() { - if (options.hot || options.liveReload) { - log.error('[WDS] Disconnected!'); - } else { - log.error('[WDS] Hot Module Replacement & Live Reloading are disabled!'); - } + log.error('[WDS] Disconnected!'); + sendMessage('Close'); }, }; diff --git a/test/e2e/__snapshots__/ClientOptions.test.js.snap b/test/e2e/__snapshots__/ClientOptions.test.js.snap index 4b7bbaea75..72d313bf8a 100644 --- a/test/e2e/__snapshots__/ClientOptions.test.js.snap +++ b/test/e2e/__snapshots__/ClientOptions.test.js.snap @@ -74,7 +74,7 @@ Array [ "Hey.", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", - "[WDS] Hot Module Replacement & Live Reloading are disabled!", + "[WDS] Disconnected!", "[WDS] JSHandle@object", "[WDS] JSHandle@object", ] @@ -85,7 +85,7 @@ Array [ "Failed to load resource: the server responded with a status of 404 (Not Found)", "Failed to load resource: the server responded with a status of 404 (Not Found)", "Hey.", - "[WDS] Hot Module Replacement & Live Reloading are disabled!", + "[WDS] Disconnected!", ] `; @@ -94,7 +94,7 @@ Array [ "Hey.", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", "WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404", - "[WDS] Hot Module Replacement & Live Reloading are disabled!", + "[WDS] Disconnected!", "[WDS] JSHandle@object", "[WDS] JSHandle@object", ] From 58957ee7550a2ae7b6b296ce7d952e4f4e6dc31d Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Thu, 21 May 2020 09:45:24 +0200 Subject: [PATCH 5/6] test: convert promises to async/await --- test/client/__snapshots__/index.test.js.snap | 2 +- test/e2e/ClientOptions.test.js | 59 ++++++-------------- 2 files changed, 18 insertions(+), 43 deletions(-) diff --git a/test/client/__snapshots__/index.test.js.snap b/test/client/__snapshots__/index.test.js.snap index f3c4b1e27e..9768edb49f 100644 --- a/test/client/__snapshots__/index.test.js.snap +++ b/test/client/__snapshots__/index.test.js.snap @@ -8,7 +8,7 @@ exports[`index should run onSocketMessage.close (liveReload enabled) 1`] = `"[WD exports[`index should run onSocketMessage.close (liveReload enabled) 2`] = `"Close"`; -exports[`index should run onSocketMessage.close 1`] = `"[WDS] Hot Module Replacement & Live Reloading are disabled!"`; +exports[`index should run onSocketMessage.close 1`] = `"[WDS] Disconnected!"`; exports[`index should run onSocketMessage.close 2`] = `"Close"`; diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index ee83900048..e9d66e3b46 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -412,53 +412,28 @@ describe('Client console.log', () => { }, ]; - transportModes.forEach((mode) => { - cases.forEach(({ title, options }) => { + transportModes.forEach(async (mode) => { + await cases.forEach(async ({ title, options }) => { title += ` (${ Object.keys(mode).length ? mode.transportMode : 'default' })`; options = { ...mode, ...options }; - it(title, (done) => { + const testOptions = Object.assign({}, baseOptions, options); + await it(title, async (done) => { + await testServer.startAwaitingCompilation(config, testOptions); const res = []; - const testOptions = Object.assign({}, baseOptions, options); - - // TODO: use async/await when Node.js v6 support is dropped - Promise.resolve() - .then(() => { - return new Promise((resolve) => { - testServer.startAwaitingCompilation(config, testOptions, resolve); - }); - }) - .then(() => { - // make sure the previous Promise is not passing along strange arguments to runBrowser - return runBrowser(); - }) - .then(({ page, browser }) => { - return new Promise((resolve) => { - page.goto(`http://localhost:${port2}/main`); - page.on('console', ({ _text }) => { - res.push(_text); - }); - // wait for load before closing the browser - page.waitForNavigation({ waitUntil: 'load' }).then(() => { - page.waitFor(beforeBrowserCloseDelay).then(() => { - browser.close().then(() => { - resolve(); - }); - }); - }); - }); - }) - .then(() => { - return new Promise((resolve) => { - testServer.close(resolve); - }); - }) - .then(() => { - // Order doesn't matter, maybe we should improve that in future - expect(res.sort()).toMatchSnapshot(); - done(); - }); + const { page, browser } = await runBrowser(); + page.goto(`http://localhost:${port2}/main`); + page.on('console', ({ _text }) => { + res.push(_text); + }); + // wait for load before closing the browser + await page.waitForNavigation({ waitUntil: 'load' }); + await page.waitFor(beforeBrowserCloseDelay); + await browser.close(); + // Order doesn't matter, maybe we should improve that in future + await expect(res.sort()).toMatchSnapshot(); + await testServer.close(done); }); }); }); From a66d15786c19203e6d27fbce4d02039b2be04112 Mon Sep 17 00:00:00 2001 From: Islam ElHakmi Date: Thu, 21 May 2020 13:23:51 +0200 Subject: [PATCH 6/6] test: update snapshot --- test/server/__snapshots__/transportMode-option.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/server/__snapshots__/transportMode-option.test.js.snap b/test/server/__snapshots__/transportMode-option.test.js.snap index daf1f29b01..cb0a1037ca 100644 --- a/test/server/__snapshots__/transportMode-option.test.js.snap +++ b/test/server/__snapshots__/transportMode-option.test.js.snap @@ -96,7 +96,7 @@ Array [ Object { "foo": "bar", }, - "{\\"type\\":\\"liveReload\\",\\"data\\":true}", + "{\\"type\\":\\"liveReload\\"}", ] `;