diff --git a/src/watch.js b/src/watch.js index 3860097..f451fba 100644 --- a/src/watch.js +++ b/src/watch.js @@ -4,6 +4,8 @@ import type {WatchCallback} from './typedef'; import {logError, log, consoleStyles} from './logger'; import {Client} from 'fb-watchman'; +/* eslint-disable camelcase */ + const client = new Client(), ALPHANUMERIC_BASE = 36, {yellow} = consoleStyles; @@ -31,13 +33,15 @@ const client = new Client(), export function watch(dir: string, type: string, callback: WatchCallback) { const subscription = Date.now().toString(ALPHANUMERIC_BASE); - client.capabilityCheck({}, capabilityErr => { + client.capabilityCheck({optional: [], required: ['relative_root']}, capabilityErr => { if (capabilityErr) { + client.end(); + return logError(capabilityErr); } client.command(['watch-project', dir], (watchErr, watchResp) => { - const {watch: watcher} = watchResp; + const {watch: watcher, relative_path: relative_root} = watchResp; if (watchErr) { return logError(watchErr); @@ -54,7 +58,8 @@ export function watch(dir: string, type: string, callback: WatchCallback) { client.command(['subscribe', watcher, subscription, { expression: ['suffix', type], - since: clockResp.clock + since: clockResp.clock, + relative_root }], subscribeErr => { if (subscribeErr) { logError(subscribeErr); diff --git a/test/mock.js b/test/mock.js index 1acd21a..4155902 100644 --- a/test/mock.js +++ b/test/mock.js @@ -104,7 +104,9 @@ export class Client { capabilityCheck: () => void; command: () => void; on: () => void; + end: () => void; } Client.prototype.capabilityCheck = noop; Client.prototype.command = noop; Client.prototype.on = noop; +Client.prototype.end = noop; diff --git a/test/watch.spec.js b/test/watch.spec.js index 0d471cf..ab9fd05 100644 --- a/test/watch.spec.js +++ b/test/watch.spec.js @@ -10,6 +10,7 @@ chai.use(sinonChai); /* eslint-disable no-unused-expressions */ /* eslint-disable require-jsdoc */ +/* eslint-disable camelcase */ const ALPHANUMERIC_BASE = 36, capabilityErr = new Error('capabilityErr'), @@ -69,7 +70,7 @@ describe('watch', () => { }); it('calls capabilityCheck', () => { - expect(Client.prototype.capabilityCheck).calledWith({}, match.func); + expect(Client.prototype.capabilityCheck).calledWith({optional: [], required: ['relative_root']}, match.func); }); it('prints an error on screen', () => { @@ -180,7 +181,7 @@ describe('watch', () => { beforeEach(() => { stub(Client.prototype, 'command', (command, cb) => { if ('watch-project' === command[0]) { - cb(null, {watch: 'a watcher instance'}); + cb(null, {watch: 'a watcher instance', relative_path: 'relative path'}); } else if ('clock' === command[0]) { cb(null, {clock: 'clock value'}); } else { @@ -196,7 +197,7 @@ describe('watch', () => { it('executes a subscribe command', () => { expect(Client.prototype.command).calledWith(['subscribe', 'a watcher instance', 'qwerty', - {expression: ['suffix', 'rty'], since: 'clock value'}], match.func); + {expression: ['suffix', 'rty'], since: 'clock value', relative_root: 'relative path'}], match.func); }); it('prints an error on screen', () => {