mirror of
https://github.com/SrIzan10/nodemon.git
synced 2026-05-01 10:55:09 +00:00
test: added dotfile tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
run: require('./run'),
|
||||
watch: require('./watch'),
|
||||
};
|
||||
watch: require('./watch').watch,
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
0
test/fixtures/.dotfile
vendored
Normal file
0
test/fixtures/.dotfolder/.nested_dotfile.js
vendored
Normal file
0
test/fixtures/.dotfolder/.nested_dotfile.js
vendored
Normal file
0
test/fixtures/.dotfolder/second.js
vendored
Normal file
0
test/fixtures/.dotfolder/second.js
vendored
Normal file
0
test/fixtures/.dotfolder/some_file.js
vendored
Normal file
0
test/fixtures/.dotfolder/some_file.js
vendored
Normal 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);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user