Skip to content

Commit

Permalink
Correctly instantiate server watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Dec 12, 2022
1 parent a11f096 commit 25e82ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
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,
});
});

Expand Down

0 comments on commit 25e82ad

Please sign in to comment.