Move FileWatcher into node-haste

Reviewed By: davidaurelio

Differential Revision: D2752711

fb-gh-sync-id: e656a3019b95c7677d5b27e74dc921ef62ba5c83
This commit is contained in:
Christoph Pojer 2015-12-14 11:12:54 -08:00 committed by facebook-github-bot-4
parent 26102c3934
commit ae4ea67fa6
5 changed files with 21 additions and 16 deletions

View File

@ -9,5 +9,5 @@
'use strict';
module.exports = {
WatchmanWatcher: jest.genMockFromModule('sane/src/watchman_watcher')
WatchmanWatcher: jest.genMockFromModule('sane/src/watchman_watcher'),
};

View File

@ -12,28 +12,37 @@ jest
.dontMock('util')
.dontMock('events')
.dontMock('../')
.dontMock('q')
.setMock('child_process', {
exec: function(cmd, cb) {
cb(null, '/usr/bin/watchman');
}
},
});
var FileWatcher = require('../');
var sane = require('sane');
describe('FileWatcher', function() {
var Watcher;
var FileWatcher;
var config;
beforeEach(function() {
Watcher = sane.WatchmanWatcher;
Watcher.prototype.once.mockImplementation(function(type, callback) {
callback();
});
FileWatcher = require('../');
config = [{
dir: 'rootDir',
globs: [
'**/*.js',
'**/*.json',
],
}];
});
pit('it should get the watcher instance when ready', function() {
var fileWatcher = new FileWatcher(['rootDir']);
var fileWatcher = new FileWatcher(config);
return fileWatcher.getWatchers().then(function(watchers) {
watchers.forEach(function(watcher) {
expect(watcher instanceof Watcher).toBe(true);
@ -46,10 +55,10 @@ describe('FileWatcher', function() {
Watcher.prototype.on.mockImplementation(function(type, callback) {
cb = callback;
});
var fileWatcher = new FileWatcher(['rootDir']);
var fileWatcher = new FileWatcher(config);
var handler = jest.genMockFn();
fileWatcher.on('all', handler);
return fileWatcher.getWatchers().then(function(){
return fileWatcher.getWatchers().then(function() {
cb(1, 2, 3, 4);
jest.runAllTimers();
expect(handler.mock.calls[0]).toEqual([1, 2, 3, 4]);
@ -57,7 +66,7 @@ describe('FileWatcher', function() {
});
pit('it should end the watcher', function() {
var fileWatcher = new FileWatcher(['rootDir']);
var fileWatcher = new FileWatcher(config);
Watcher.prototype.close.mockImplementation(function(callback) {
callback();
});

View File

@ -12,11 +12,10 @@ const EventEmitter = require('events').EventEmitter;
const sane = require('sane');
const Promise = require('promise');
const exec = require('child_process').exec;
const _ = require('underscore');
const MAX_WAIT_TIME = 25000;
// TODO(amasad): can we use watchman version command instead?r
// TODO(amasad): can we use watchman version command instead?
const detectingWatcherClass = new Promise(function(resolve) {
exec('which watchman', function(err, out) {
if (err || out.length === 0) {
@ -81,13 +80,10 @@ class FileWatcher extends EventEmitter {
}
static createDummyWatcher() {
const ev = new EventEmitter();
_.extend(ev, {
return Object.assign(new EventEmitter(), {
isWatchman: () => Promise.resolve(false),
end: () => Promise.resolve(),
});
return ev;
}
}

View File

@ -19,7 +19,7 @@ jest.setMock('worker-farm', function() { return () => {}; })
const Promise = require('promise');
var Bundler = require('../../Bundler');
var FileWatcher = require('../../FileWatcher');
var FileWatcher = require('../../DependencyResolver/FileWatcher');
var Server = require('../');
var Server = require('../../Server');
var AssetServer = require('../../AssetServer');

View File

@ -10,7 +10,7 @@
const Activity = require('../Activity');
const AssetServer = require('../AssetServer');
const FileWatcher = require('../FileWatcher');
const FileWatcher = require('../DependencyResolver/FileWatcher');
const getPlatformExtension = require('../DependencyResolver/lib/getPlatformExtension');
const Bundler = require('../Bundler');
const Promise = require('promise');