Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve message for static content changes #3289

Merged
merged 5 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,22 @@ const onSocketMessage = {

reloadApp(options, status);
},
'content-changed': function contentChanged() {
log.info('Content base changed. Reloading...');
// TODO: remove in v5 in favor of 'static-changed'
'content-changed': function contentChanged(file) {
log.info(
`${
file ? `"${file}"` : 'Content'
} from static directory was changed. Reloading...`
);

self.location.reload();
},
'static-changed': function staticChanged(file) {
log.info(
`${
file ? `"${file}"` : 'Content'
} from static directory was changed. Reloading...`
);

self.location.reload();
},
Expand Down
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', watchPath);
});
}

Expand Down
9 changes: 8 additions & 1 deletion test/client/__snapshots__/index.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ 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['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['still-ok'] 1`] = `"Nothing changed."`;

Expand All @@ -103,6 +109,7 @@ Array [
"overlay": [Function],
"progress": [Function],
"progress-update": [Function],
"static-changed": [Function],
"still-ok": [Function],
"warnings": [Function],
},
Expand Down
9 changes: 8 additions & 1 deletion test/client/__snapshots__/index.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ 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['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['still-ok'] 1`] = `"Nothing changed."`;

Expand All @@ -103,6 +109,7 @@ Array [
"overlay": [Function],
"progress": [Function],
"progress-update": [Function],
"static-changed": [Function],
"still-ok": [Function],
"warnings": [Function],
},
Expand Down
21 changes: 21 additions & 0 deletions test/client/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@ 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']();

expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
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([
Expand Down