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

[BUGFIX release] Correctly instantiate server watcher #10108

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
10 changes: 6 additions & 4 deletions lib/models/server-watcher.js
Expand Up @@ -3,11 +3,13 @@
const Watcher = require('./watcher');

module.exports = class ServerWatcher extends Watcher {
constructor(options, build) {
super(options, build);
static async build(options, build) {
let { watcher: instance } = await super.build(options, build);

this.watcher.on('add', this.didAdd.bind(this));
this.watcher.on('delete', this.didDelete.bind(this));
instance.watcher.on('add', instance.didAdd.bind(instance));
instance.watcher.on('delete', instance.didDelete.bind(instance));

return { watcher: instance };
}

constructBroccoliWatcher(options) {
Expand Down
14 changes: 8 additions & 6 deletions lib/tasks/serve.js
Expand Up @@ -69,12 +69,14 @@ class ServeTask extends Task {
let serverRoot = './server';
let serverWatcher = null;
if (fs.existsSync(serverRoot)) {
serverWatcher = new ServerWatcher({
ui: this.ui,
analytics: this.analytics,
watchedDir: path.resolve(serverRoot),
options,
});
serverWatcher = (
await ServerWatcher.build({
ui: this.ui,
analytics: this.analytics,
watchedDir: path.resolve(serverRoot),
options,
})
).watcher;
}

let expressServer =
Expand Down
11 changes: 9 additions & 2 deletions tests/unit/models/server-watcher-test.js
Expand Up @@ -17,10 +17,17 @@ describe('Server Watcher', function () {
analytics = new MockAnalytics();
watcher = new MockServerWatcher();

await ServerWatcher.build({
class ServerWatcherMock extends ServerWatcher {
setupBroccoliWatcher() {
this.watcher = watcher;

return super.setupBroccoliWatcher(...arguments);
}
}

await ServerWatcherMock.build({
ui,
analytics,
watcher,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning the watcher upon creation is not really how things work at the moment, and is why this test didn't catch this.watcher being undefined in the server-watcher's constructor when running ember s in a real project. This test now fails without the changes in this PR and succeeds with.

});
});

Expand Down