Skip to content

Commit

Permalink
Merge ccc5e6a into 305be34
Browse files Browse the repository at this point in the history
  • Loading branch information
es128 committed Sep 18, 2015
2 parents 305be34 + ccc5e6a commit 0570c15
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,13 @@ FSWatcher.prototype.unwatch = function(paths) {
delete this._closers[path];
this._getWatchedDir(sysPath.dirname(path)).remove(sysPath.basename(path));
} else {
//convert to absolute path
path = sysPath.resolve(path);

this._ignoredPaths[path] = true;
if (path in this._watched) this._ignoredPaths[path + '/**/*'] = true;
if (path in this._watched) {
this._ignoredPaths[path + '/**/*'] = true;
}

// reset the cached userIgnored anymatch fn
// to make ignoredPaths changes effective
Expand Down
55 changes: 32 additions & 23 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,10 @@ function runTests(options) {
.on('all', spy)
.on('ready', d(function() {
fs.symlinkSync(getFixturePath('subdir'), getFixturePath('link'));
waitFor([spy.withArgs('add'), spy.withArgs('addDir')], function() {
waitFor([
spy.withArgs('add', getFixturePath('link/add.txt')),
spy.withArgs('addDir', getFixturePath('link'))
], function() {
spy.should.have.been.calledWith('addDir', getFixturePath('link'));
spy.should.have.been.calledWith('add', getFixturePath('link/add.txt'));
done();
Expand Down Expand Up @@ -924,7 +927,7 @@ function runTests(options) {
.on('ready', d(function() {
fs.writeFileSync(getFixturePath('add.txt'), 'a');
fs.writeFileSync(getFixturePath('change.txt'), 'a');
waitFor([spy.withArgs('change')], function() {
waitFor([spy.withArgs('change', 'change.txt')], function() {
spy.should.not.have.been.calledWith('add', 'add.txt');
spy.should.not.have.been.calledWith('change', 'add.txt');
spy.should.have.been.calledWith('add', 'change.txt');
Expand Down Expand Up @@ -1247,17 +1250,21 @@ function runTests(options) {
watcher = chokidar.watch(fixturesPath, options)
.on('all', spy)
.on('ready', d(function() {
watcher.unwatch([getFixturePath('subdir'), getFixturePath('unl*')]);
fs.writeFileSync(getFixturePath('subdir/add.txt'), 'c');
fs.writeFileSync(getFixturePath('change.txt'), 'c');
fs.unlinkSync(getFixturePath('unlink.txt'));
waitFor([spy], function() {
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
spy.should.not.have.been.calledWith('add');
spy.should.not.have.been.calledWith('unlink');
if (!osXFsWatch) spy.should.have.been.calledOnce;
done();
});
// test with both relative and absolute paths
var subdirRel = sysPath.join(sysPath.basename(fixturesPath), 'subdir');
watcher.unwatch([subdirRel, getFixturePath('unl*')]);
dd(function() {
fs.unlinkSync(getFixturePath('unlink.txt'));
fs.writeFileSync(getFixturePath('subdir/add.txt'), 'c');
fs.writeFileSync(getFixturePath('change.txt'), 'c');
waitFor([spy.withArgs('change')], function() {
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
spy.should.not.have.been.calledWith('add', getFixturePath('subdir/add.txt'));
spy.should.not.have.been.calledWith('unlink');
if (!osXFsWatch) spy.should.have.been.calledOnce;
done();
});
})();
}, true));
});
it('should unwatch relative paths', function(done) {
Expand All @@ -1282,21 +1289,23 @@ function runTests(options) {
}));
})();
});
it('should watch paths the were unwatched and added again', function(done) {
it('should watch paths that 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();
});
dd(function() {
watcher.on('all', spy).add(getFixturePath('change.txt'));
dd(function() {
fs.writeFileSync(getFixturePath('change.txt'), 'c');
waitFor([spy], function() {
spy.should.have.been.calledWith('change', getFixturePath('change.txt'));
spy.should.have.been.calledOnce;
done();
});
})();
})();
}));
});
});
Expand Down

0 comments on commit 0570c15

Please sign in to comment.