Skip to content

Commit

Permalink
Merge pull request #8 from chancancode/rm-warning
Browse files Browse the repository at this point in the history
Remove "Could not start watchman" warning
  • Loading branch information
rwjblue authored Sep 7, 2019
2 parents a462c37 + e369461 commit d97cfdf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "4"
- "6"
- "8"
- "10"
- "lts/*"
- "stable"
sudo: false

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ sane(root, options);
```js
new WatchDetector({
ui: /* console-ui instance */,
fs: /* fs instance */,
watchmanSupportsPlatform: true | false /* defaults to no for windows */
fs: /* fs instance */
});
```
21 changes: 5 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const quickTemp = require('quick-temp');
const Promise = require('rsvp').Promise;
const WATCHMAN_INFO = 'Visit https://ember-cli.com/user-guide/#watchman for more info.';
const semver = require('semver');
const SilentError = require('silent-error');

Expand All @@ -11,6 +10,7 @@ const WATCHMAN = 'watchman';
const NODE = 'node';
const EVENTS = 'events';
const POSSIBLE_WATCHERS = [POLLING, WATCHMAN, NODE, EVENTS];
const WATCHMAN_INFO = 'Visit https://ember-cli.com/user-guide/#watchman for more info.';

const debug = require('heimdalljs-logger')('ember-cli:watcher');

Expand Down Expand Up @@ -44,12 +44,6 @@ class WatchDetector {
constructor(options) {
this.childProcess = options.childProcess || require('child-process');

if ('watchmanSupportsPlatform' in options) {
this.watchmanSupportsPlatform = options.watchmanSupportsPlatform;
} else {
this.watchmanSupportsPlatform = process.platform !== "win32";
}

this.fs = options.fs || require('fs');
this.root = options.root;

Expand Down Expand Up @@ -188,6 +182,10 @@ class WatchDetector {
) {
// if there was an initial preference, but we had to fall back inform the user.
this.ui.writeLine(`was unable to use: "${original}", fell back to: "${actual.watcher}"`);

if (original === WATCHMAN) {
this.ui.writeLine(WATCHMAN_INFO);
}
}
return actual;
}
Expand Down Expand Up @@ -248,15 +246,6 @@ class WatchDetector {
return result;
} catch (reason) {
debug.info('detecting watchman failed %o', reason);

if (this.watchmanSupportsPlatform) {
// don't bother telling windows users watchman detection failed, that is
// until watchman is legit on windows.
} else {
this.ui.writeLine('Could not start watchman');
this.ui.writeLine(WATCHMAN_INFO);
}

result.watcher = NODE;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"sinon-chai": "^2.14.0"
},
"engines": {
"node": ">= 4"
"node": ">= 8"
},
"dependencies": {
"heimdalljs-logger": "^0.1.9",
Expand Down
47 changes: 5 additions & 42 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('WatchDetector', function() {
expect(option.watchmanInfo).to.have.property('version');
expect(option.watchmanInfo).to.have.property('canNestRoots');
expect(option.watchmanInfo).to.have.property('enabled', true);
expect(ui.output).not.to.match(/Could not start watchman/);
expect(ui.output).not.to.match(/fell back to: "node"/);
expect(ui.output).not.to.match(/Visit https:\/\/ember-cli.com\/user-guide\/#watchman/);
});
Expand All @@ -95,7 +94,7 @@ describe('WatchDetector', function() {
};
});

it('false back to node if it can', function() {
it('falls back to node if it can', function() {
fs.watch = function() {
return { close() {} };
};
Expand All @@ -105,12 +104,11 @@ describe('WatchDetector', function() {
expect(option).to.have.property('watcher', 'node');
expect(option.watchmanInfo).to.have.property('version');
expect(option.watchmanInfo).to.have.property('canNestRoots');
expect(ui.output).to.match(/Could not start watchman/);
expect(ui.output).to.match(/fell back to: "node"/);
expect(ui.output).to.match(/Visit https:\/\/ember-cli.com\/user-guide\/#watchman/);
});

it('false back to polling if node does not work', function() {
it('falls back to polling if node does not work', function() {
fs.watch = function() {
throw new Error('something went wrong');
};
Expand All @@ -120,7 +118,6 @@ describe('WatchDetector', function() {
expect(option.watchmanInfo).to.have.property('enabled', false);
expect(option.watchmanInfo).to.have.property('version');
expect(option.watchmanInfo).to.have.property('canNestRoots');
expect(ui.output).to.match(/Could not start watchman/);
expect(ui.output).to.match(/fell back to: "polling"/);
expect(ui.output).to.match(/Visit https:\/\/ember-cli.com\/user-guide\/#watchman/);
});
Expand Down Expand Up @@ -149,7 +146,7 @@ describe('WatchDetector', function() {
expect(ui.output).to.eql('');
});

it('false back to polling if watch fails', function() {
it('falls back to polling if watch fails', function() {
fs.watch = function() {
throw new Error('OMG');
};
Expand All @@ -175,53 +172,20 @@ describe('WatchDetector', function() {
});

describe('#checkWatchman', function() {
describe('watchmanSupportsPlatform', function() {
it('true: hides the "watchman not found, falling back to XYZ message"', function() {
subject.watchmanSupportsPlatform = true;

childProcess.execSync = function() {
throw new Error();
};
fs.watch = function() {
return { close() {} };
};

let result = subject.checkWatchman();
expect(result).to.have.property('watcher', 'node');
expect(ui.output).to.eql('');
});

it('false: shows the "watchman not found, falling back to XYZ message"', function() {
subject.watchmanSupportsPlatform = false;
fs.watch = function() {
return { close() {} };
};

childProcess.execSync = function() {
throw new Error();
};

let result = subject.checkWatchman();
expect(result).to.have.property('watcher', 'node');
expect(ui.output).to.match(/Could not start watchman/);
expect(ui.output).to.match(/Visit https:\/\/ember-cli.com\/user-guide\/#watchman/);
});
});
it('prefers watchman if everything appears to be good', function() {
childProcess.execSync = function() {
return '{"version":"3.0.0"}';
};

let preference = subject.checkWatchman();
expect(preference).to.have.property('watcher', 'watchman');
expect(ui.output).to.not.match(/Could not start watchman/);
expect(ui.output).to.not.match(/falling back to NodeWatcher/);
expect(ui.output).to.not.match(/ember-cli\.com\/user-guide\/#watchman/);
expect(ui.output).to.not.match(/Looks like you have a different program called watchman/);
expect(ui.output).to.not.match(/Invalid watchman found/);
});

describe('fallse back to NODE', function() {
describe('falls back to NODE', function() {
let iff = it;

iff('the exec rejects', function() {
Expand All @@ -231,8 +195,7 @@ describe('WatchDetector', function() {

let preference = subject.checkWatchman();
expect(preference).to.have.property('watcher', 'node');
expect(ui.output).to.match(/Could not start watchman/);
expect(ui.output).to.match(/ember-cli\.com\/user-guide\/#watchman/);
expect(ui.output).to.not.match(/ember-cli\.com\/user-guide\/#watchman/);
});

iff("the `watchman version` doesn't parse", function() {
Expand Down

0 comments on commit d97cfdf

Please sign in to comment.