Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwatch and some sporadic test errors #355

Merged
merged 5 commits into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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