From 9e7a985585ddfc6809846d65d77faee1f752a578 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 13 May 2021 19:18:17 +0530 Subject: [PATCH 1/5] fix: improve message for static content changes --- client-src/index.js | 5 +++++ lib/Server.js | 2 +- test/client/__snapshots__/index.test.js.snap.webpack4 | 3 +++ test/client/__snapshots__/index.test.js.snap.webpack5 | 3 +++ test/client/index.test.js | 7 +++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client-src/index.js b/client-src/index.js index b6ff70a4e7..28ea72b3fd 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -142,6 +142,11 @@ const onSocketMessage = { self.location.reload(); }, + 'static-changed': function staticChanged() { + log.info('Contents from static directory were changed. Reloading...'); + + self.location.reload(); + }, warnings(warnings) { log.warn('Warnings while compiling.'); diff --git a/lib/Server.js b/lib/Server.js index 5261f7f7e8..338b3eadc8 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1121,7 +1121,7 @@ class Server { // disabling refreshing on changing the content if (this.options.liveReload) { watcher.on('change', () => { - this.sockWrite(this.sockets, 'content-changed'); + this.sockWrite(this.sockets, 'static-changed'); }); } diff --git a/test/client/__snapshots__/index.test.js.snap.webpack4 b/test/client/__snapshots__/index.test.js.snap.webpack4 index 9cea051989..a0ba319dbe 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack4 +++ b/test/client/__snapshots__/index.test.js.snap.webpack4 @@ -82,6 +82,8 @@ Array [ exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Contents from static directory were changed. Reloading..."`; + exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; exports[`index should run onSocketMessage['still-ok'] 2`] = `"StillOk"`; @@ -103,6 +105,7 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, diff --git a/test/client/__snapshots__/index.test.js.snap.webpack5 b/test/client/__snapshots__/index.test.js.snap.webpack5 index 9cea051989..a0ba319dbe 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack5 +++ b/test/client/__snapshots__/index.test.js.snap.webpack5 @@ -82,6 +82,8 @@ Array [ exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Contents from static directory were changed. Reloading..."`; + exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; exports[`index should run onSocketMessage['still-ok'] 2`] = `"StillOk"`; @@ -103,6 +105,7 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, diff --git a/test/client/index.test.js b/test/client/index.test.js index 452d2b4ddd..fd8ba309d5 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -185,6 +185,13 @@ describe('index', () => { expect(self.location.reload).toBeCalled(); }); + test("should run onSocketMessage['static-changed']", () => { + onSocketMessage['static-changed'](); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + test('should run onSocketMessage.warnings', () => { { const res = onSocketMessage.warnings([ From c68d03835094de99cd4b79be683221e673e30ea6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 13 May 2021 19:25:58 +0530 Subject: [PATCH 2/5] chore: add TODO --- client-src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client-src/index.js b/client-src/index.js index 28ea72b3fd..7bd081d71b 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -137,6 +137,7 @@ const onSocketMessage = { reloadApp(options, status); }, + // TODO: remove in v5 in favor of 'static-changed' 'content-changed': function contentChanged() { log.info('Content base changed. Reloading...'); From 464a761249175114dd20d0509a53ae88631c3f3d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 24 May 2021 07:12:44 +0530 Subject: [PATCH 3/5] fix: improve message --- client-src/index.js | 12 ++++++++---- lib/Server.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index 7bd081d71b..5a90e77152 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -138,13 +138,17 @@ const onSocketMessage = { reloadApp(options, status); }, // TODO: remove in v5 in favor of 'static-changed' - 'content-changed': function contentChanged() { - log.info('Content base changed. Reloading...'); + 'content-changed': function contentChanged(file) { + log.info( + `${file || 'Contents'} from static directory were changed. Reloading...` + ); self.location.reload(); }, - 'static-changed': function staticChanged() { - log.info('Contents from static directory were changed. Reloading...'); + 'static-changed': function staticChanged(file) { + log.info( + `${file || 'Contents'} from static directory were changed. Reloading...` + ); self.location.reload(); }, diff --git a/lib/Server.js b/lib/Server.js index 338b3eadc8..bb0851a59a 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1121,7 +1121,7 @@ class Server { // disabling refreshing on changing the content if (this.options.liveReload) { watcher.on('change', () => { - this.sockWrite(this.sockets, 'static-changed'); + this.sockWrite(this.sockets, 'static-changed', watchPath); }); } From d4211909ae6dd76ab59f727c6f64d4be40b08eb1 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 24 May 2021 07:26:39 +0530 Subject: [PATCH 4/5] test: updates --- client-src/index.js | 4 ++-- test/client/__snapshots__/index.test.js.snap.webpack4 | 6 ++++-- test/client/__snapshots__/index.test.js.snap.webpack5 | 6 ++++-- test/client/index.test.js | 7 +++++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index 5a90e77152..d821d418e0 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -140,14 +140,14 @@ const onSocketMessage = { // TODO: remove in v5 in favor of 'static-changed' 'content-changed': function contentChanged(file) { log.info( - `${file || 'Contents'} from static directory were changed. Reloading...` + `${file || 'Content'} from static directory was changed. Reloading...` ); self.location.reload(); }, 'static-changed': function staticChanged(file) { log.info( - `${file || 'Contents'} from static directory were changed. Reloading...` + `${file || 'Content'} from static directory was changed. Reloading...` ); self.location.reload(); diff --git a/test/client/__snapshots__/index.test.js.snap.webpack4 b/test/client/__snapshots__/index.test.js.snap.webpack4 index a0ba319dbe..0629cc46d9 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack4 +++ b/test/client/__snapshots__/index.test.js.snap.webpack4 @@ -80,9 +80,11 @@ Array [ ] `; -exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; -exports[`index should run onSocketMessage['static-changed'] 1`] = `"Contents from static directory were changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; diff --git a/test/client/__snapshots__/index.test.js.snap.webpack5 b/test/client/__snapshots__/index.test.js.snap.webpack5 index a0ba319dbe..0629cc46d9 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack5 +++ b/test/client/__snapshots__/index.test.js.snap.webpack5 @@ -80,9 +80,11 @@ Array [ ] `; -exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; -exports[`index should run onSocketMessage['static-changed'] 1`] = `"Contents from static directory were changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; diff --git a/test/client/index.test.js b/test/client/index.test.js index fd8ba309d5..1b955a04b3 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -192,6 +192,13 @@ describe('index', () => { expect(self.location.reload).toBeCalled(); }); + test("should run onSocketMessage['static-changed'](file)", () => { + onSocketMessage['static-changed']('/static/assets/index.html'); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + test('should run onSocketMessage.warnings', () => { { const res = onSocketMessage.warnings([ From d0938bdb6b7fa859bdef0980083143ce70d7e575 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 24 May 2021 19:15:08 +0530 Subject: [PATCH 5/5] refactor: code --- client-src/index.js | 8 ++++++-- test/client/__snapshots__/index.test.js.snap.webpack4 | 4 +++- test/client/__snapshots__/index.test.js.snap.webpack5 | 4 +++- test/client/index.test.js | 7 +++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index d821d418e0..5e1d367732 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -140,14 +140,18 @@ const onSocketMessage = { // TODO: remove in v5 in favor of 'static-changed' 'content-changed': function contentChanged(file) { log.info( - `${file || 'Content'} from static directory was changed. Reloading...` + `${ + file ? `"${file}"` : 'Content' + } from static directory was changed. Reloading...` ); self.location.reload(); }, 'static-changed': function staticChanged(file) { log.info( - `${file || 'Content'} from static directory was changed. Reloading...` + `${ + file ? `"${file}"` : 'Content' + } from static directory was changed. Reloading...` ); self.location.reload(); diff --git a/test/client/__snapshots__/index.test.js.snap.webpack4 b/test/client/__snapshots__/index.test.js.snap.webpack4 index 0629cc46d9..8c2e9e9f25 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack4 +++ b/test/client/__snapshots__/index.test.js.snap.webpack4 @@ -82,9 +82,11 @@ Array [ exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`; + exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; -exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; diff --git a/test/client/__snapshots__/index.test.js.snap.webpack5 b/test/client/__snapshots__/index.test.js.snap.webpack5 index 0629cc46d9..8c2e9e9f25 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack5 +++ b/test/client/__snapshots__/index.test.js.snap.webpack5 @@ -82,9 +82,11 @@ Array [ exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`; + exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; -exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`; +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; diff --git a/test/client/index.test.js b/test/client/index.test.js index 1b955a04b3..1f8db5cdc4 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -185,6 +185,13 @@ describe('index', () => { expect(self.location.reload).toBeCalled(); }); + test("should run onSocketMessage['content-changed'](file)", () => { + onSocketMessage['content-changed']('/public/assets/index.html'); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + test("should run onSocketMessage['static-changed']", () => { onSocketMessage['static-changed']();