Skip to content

Commit

Permalink
fixing linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Dec 11, 2017
1 parent e73a92c commit 0ef7a1a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
24 changes: 13 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ let POLLING = 'polling';
let WATCHMAN = 'watchman';
let NODE = 'node';
let EVENTS = 'events';
let POSSIBLE_WATCHERS = [
POLLING,
WATCHMAN,
NODE,
EVENTS,
];
let POSSIBLE_WATCHERS = [POLLING, WATCHMAN, NODE, EVENTS];

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

Expand Down Expand Up @@ -147,7 +142,11 @@ class WatchDetector {
let original = options.watcher;

if (original && POSSIBLE_WATCHERS.indexOf(original) === -1) {
return Promise.reject(new SilentError(`Unknown Watcher: \`${original}\` supported watchers: [${POSSIBLE_WATCHERS.join(', ')}]`));
return Promise.reject(
new SilentError(
`Unknown Watcher: \`${original}\` supported watchers: [${POSSIBLE_WATCHERS.join(', ')}]`
)
);
}

if (preference.watcher === WATCHMAN) {
Expand All @@ -169,12 +168,13 @@ class WatchDetector {
actual = bestOption;
}
debug.info('foundBestWatcherOption, preference was: %o, actual: %o', options, actual);
if (actual /* if no preference was initial set, don't bother informing the user */ &&
if (
actual /* if no preference was initial set, don't bother informing the user */ &&
original /* if no original was set, the fallback is expected */ &&
actual.watcher !== original &&

// events represents either watcherman or node, but no preference
!(original === EVENTS && (actual.watcher === WATCHMAN || actual.watcher === NODE))) {
!(original === EVENTS && (actual.watcher === WATCHMAN || actual.watcher === NODE))
) {
// 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}"`);
}
Expand Down Expand Up @@ -226,7 +226,9 @@ class WatchDetector {
} else {
debug.info('watchman %s does NOT satisfy: %s', version, '>= 3.0.0');

this.ui.writeLine(`Invalid watchman found, version: [${version}] did not satisfy [>= 3.0.0].`);
this.ui.writeLine(
`Invalid watchman found, version: [${version}] did not satisfy [>= 3.0.0].`
);
this.ui.writeLine(WATCHMAN_INFO);

result.watcher = NODE;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"type": "git",
"url": "git+https://github.com/chrmod/watch-detector.git"
},
"files": [
"lib/*"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/chrmod/watch-detector/issues"
Expand Down
42 changes: 29 additions & 13 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ describe('WatchDetector', function() {

it('#extractPreferenceFromOptions works', function() {
expect(subject.extractPreferenceFromOptions({})).to.have.property('watcher', 'watchman');
expect(subject.extractPreferenceFromOptions({ watcher: 'polling' })).to.have.property('watcher', 'polling');
expect(subject.extractPreferenceFromOptions({ watcher: 'node' })).to.have.property('watcher', 'node');
expect(subject.extractPreferenceFromOptions({ watcher: 'nodsdfe' })).to.have.property('watcher', 'watchman');
expect(subject.extractPreferenceFromOptions({ watcher: 'polling' })).to.have.property(
'watcher',
'polling'
);
expect(subject.extractPreferenceFromOptions({ watcher: 'node' })).to.have.property(
'watcher',
'node'
);
expect(subject.extractPreferenceFromOptions({ watcher: 'nodsdfe' })).to.have.property(
'watcher',
'watchman'
);
});

describe('#testIfNodeWatcherAppearsToWork', function() {
Expand All @@ -44,13 +53,14 @@ describe('WatchDetector', function() {

// we could extend this to test also if change events are triggered or not..
it('reports YES if nothing throws', function() {
fs.watch = function() { return { close() { } }; };
fs.watch = function() {
return { close() {} };
};

expect(subject.testIfNodeWatcherAppearsToWork()).to.be.true;
});
});


describe('#findBestWatcherOption', function() {
describe('input preference.watcher === watchman', function() {
beforeEach(function() {
Expand Down Expand Up @@ -78,7 +88,9 @@ describe('WatchDetector', function() {
});

it('false back to node if it can', function() {
fs.watch = function() { return { close() { } }; };
fs.watch = function() {
return { close() {} };
};

let option = subject.findBestWatcherOption({ watcher: 'watchman' });
expect(option.watchmanInfo).to.have.property('enabled', false);
Expand Down Expand Up @@ -119,7 +131,9 @@ describe('WatchDetector', function() {

describe('input preference.watcher === node', function() {
it('chooses node, if everything seems ok', function() {
fs.watch = function() { return { close() { } }; };
fs.watch = function() {
return { close() {} };
};

// we assuming polling can never not work, if it doesn't sorry..
let option = subject.findBestWatcherOption({ watcher: 'node' });
Expand Down Expand Up @@ -150,7 +164,6 @@ describe('WatchDetector', function() {
expect(ui.output).to.eql(`was unable to use: "node", fell back to: "polling"${EOL}`);
});
});

});

describe('#checkWatchman', function() {
Expand All @@ -161,7 +174,9 @@ describe('WatchDetector', function() {
childProcess.execSync = function() {
throw new Error();
};
fs.watch = function() { return { close() { } }; };
fs.watch = function() {
return { close() {} };
};

let result = subject.checkWatchman();
expect(result).to.have.property('watcher', 'node');
Expand All @@ -170,7 +185,9 @@ describe('WatchDetector', function() {

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

childProcess.execSync = function() {
throw new Error();
Expand Down Expand Up @@ -210,7 +227,7 @@ describe('WatchDetector', function() {
expect(ui.output).to.match(/ember-cli\.com\/user-guide\/#watchman/);
});

iff('the `watchman version` doesn\'t parse', function() {
iff("the `watchman version` doesn't parse", function() {
childProcess.execSync = function() {
return 'not json';
};
Expand All @@ -221,8 +238,7 @@ describe('WatchDetector', function() {
expect(ui.output).to.match(/ember-cli\.com\/user-guide\/#watchman/);
});


iff('the `watchman version` doesn\'t satisfy => 3.0.0', function() {
iff("the `watchman version` doesn't satisfy => 3.0.0", function() {
childProcess.execSync = function() {
return '{"version":"2.9.9"}';
};
Expand Down

0 comments on commit 0ef7a1a

Please sign in to comment.