Skip to content

Commit d0938bd

Browse files
committed
refactor: code
1 parent d421190 commit d0938bd

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

client-src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ const onSocketMessage = {
140140
// TODO: remove in v5 in favor of 'static-changed'
141141
'content-changed': function contentChanged(file) {
142142
log.info(
143-
`${file || 'Content'} from static directory was changed. Reloading...`
143+
`${
144+
file ? `"${file}"` : 'Content'
145+
} from static directory was changed. Reloading...`
144146
);
145147

146148
self.location.reload();
147149
},
148150
'static-changed': function staticChanged(file) {
149151
log.info(
150-
`${file || 'Content'} from static directory was changed. Reloading...`
152+
`${
153+
file ? `"${file}"` : 'Content'
154+
} from static directory was changed. Reloading...`
151155
);
152156

153157
self.location.reload();

test/client/__snapshots__/index.test.js.snap.webpack4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ Array [
8282

8383
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
8484

85+
exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`;
86+
8587
exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
8688

87-
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`;
89+
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`;
8890

8991
exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`;
9092

test/client/__snapshots__/index.test.js.snap.webpack5

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ Array [
8282

8383
exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
8484

85+
exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`;
86+
8587
exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`;
8688

87-
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"/static/assets/index.html from static directory was changed. Reloading..."`;
89+
exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`;
8890

8991
exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`;
9092

test/client/index.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ describe('index', () => {
185185
expect(self.location.reload).toBeCalled();
186186
});
187187

188+
test("should run onSocketMessage['content-changed'](file)", () => {
189+
onSocketMessage['content-changed']('/public/assets/index.html');
190+
191+
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
192+
expect(self.location.reload).toBeCalled();
193+
});
194+
188195
test("should run onSocketMessage['static-changed']", () => {
189196
onSocketMessage['static-changed']();
190197

0 commit comments

Comments
 (0)