test: added dotfile tests

This commit is contained in:
Kevin Woo
2015-09-15 21:44:39 -07:00
parent 538f10757e
commit cde21fb4de
8 changed files with 50 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
module.exports = {
run: require('./run'),
watch: require('./watch'),
};
watch: require('./watch').watch,
};

View File

@@ -4,7 +4,7 @@ var bus = utils.bus;
var childProcess = require('child_process');
var spawn = childProcess.spawn;
var exec = childProcess.exec;
var watch = require('./watch');
var watch = require('./watch').watch;
var config = require('../config');
var child = null; // the actual child process we spawn
var killedAfterChange = false;

View File

@@ -1,4 +1,5 @@
module.exports = watch;
module.exports.watch = watch;
module.exports.resetWatchers = resetWatchers;
var debug = require('debug')('nodemon:watch');
var debugRoot = require('debug')('nodemon');
@@ -13,13 +14,16 @@ var match = require('./match');
var watchers = [];
var debouncedBus;
bus.on('reset', function () {
bus.on('reset', resetWatchers);
function resetWatchers() {
debug('resetting watchers');
watchers.forEach(function (watcher) {
watcher.close();
});
watchers = [];
});
}
function watch() {
if (watchers.length) {
@@ -33,6 +37,7 @@ function watch() {
debugRoot('ignore dirs regex(%s)', config.options.ignore.re);
var promises = [];
var watchedFiles = [];
dirs.forEach(function (dir) {
var promise = new Promise(function (resolve) {
@@ -45,9 +50,10 @@ function watch() {
var total = 0;
watcher.on('change', filterAndRestart);
watcher.on('add', function (arg) {
watcher.on('add', function (file) {
watchedFiles.push(file);
total++;
debug('watching dir: %s', arg);
debug('watching dir: %s', file);
});
watcher.on('ready', function () {
resolve(total);
@@ -58,7 +64,7 @@ function watch() {
promises.push(promise);
});
Promise.all(promises).then(function (res) {
return Promise.all(promises).then(function (res) {
var total = res.reduce(function (acc, curr) {
acc += curr;
return acc;
@@ -66,6 +72,7 @@ function watch() {
var count = total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
utils.log.detail('watching ' + count + ' files');
return watchedFiles;
});
}

0
test/fixtures/.dotfile vendored Normal file
View File

View File

0
test/fixtures/.dotfolder/second.js vendored Normal file
View File

0
test/fixtures/.dotfolder/some_file.js vendored Normal file
View File

View File

@@ -8,6 +8,7 @@ var assert = require('assert'),
nodemonUtils = require('../../lib/utils'),
defaults = require('../../lib/config/defaults'),
utils = require('../utils'),
watch = require('../../lib/monitor/watch'),
merge = nodemonUtils.merge;
describe('match', function () {
@@ -338,3 +339,36 @@ describe('match rule parser', function () {
assert(matched.result.length === 1, 'no file matched');
});
});
describe('watcher', function () {
afterEach(function () {
watch.resetWatchers();
});
it('should match a dotfile if explicitly asked to', function (done) {
config.load({
watch: ['test/fixtures/.dotfile']
}, function (config) {
return watch.watch()
.then(function (files) {
assert.deepEqual(files.length, 1, 'should contain .dotfile');
})
.then(done)
.catch(done);
})
});
it('should match a dotfolder if explicitly asked to', function (done) {
config.load({
watch: ['test/fixtures/.dotfolder']
}, function (config) {
return watch.watch()
.then(function (files) {
assert.deepEqual(files.length, 3, 'file lists should contain .dotfolder files');
})
.then(done)
.catch(done);
})
});
});