Skip to content

Commit

Permalink
Merge pull request #291 from mehiel/issue-289-unwatch-watch
Browse files Browse the repository at this point in the history
Cleanup watcher's state after unwatching a path (fixes #289)
  • Loading branch information
es128 committed Jul 22, 2015
2 parents 01263e3 + 6fb6999 commit 6c7b411
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ FSWatcher.prototype.unwatch = function(paths) {
paths.forEach(function(path) {
if (this._closers[path]) {
this._closers[path]();
delete this._closers[path];
this._getWatchedDir(sysPath.dirname(path)).remove(sysPath.basename(path));
} else {
this._ignoredPaths[path] = true;
if (path in this._watched) this._ignoredPaths[path + '/**/*'] = true;
Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,23 @@ function runTests(options) {
}));
})();
});
it('should watch paths the were unwatched and added again', function(done) {
var spy = sinon.spy();
var watchPaths = [getFixturePath('change.txt')];
watcher = chokidar.watch(watchPaths, options)
.on('all', spy)
.on('ready', d(function() {
watcher.unwatch(getFixturePath('change.txt'));
watcher.add(getFixturePath('change.txt'));

fs.writeFileSync(getFixturePath('change.txt'), 'c');
waitFor([spy], function() {
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
spy.should.have.been.calledOnce;
done();
});
}));
});
});
describe('close', function() {
beforeEach(clean);
Expand Down

0 comments on commit 6c7b411

Please sign in to comment.