Skip to content

Commit

Permalink
Merge pull request #380 from erezarnon/master
Browse files Browse the repository at this point in the history
Pull request #378 + test
  • Loading branch information
es128 committed Oct 30, 2015
2 parents 8a0b194 + 21de91b commit 1d11418
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ FSWatcher.prototype._remove = function(directory, item) {
delete this._watched[fullPath];
var eventName = isDirectory ? 'unlinkDir' : 'unlink';
if (wasTracked && !this._isIgnored(path)) this._emit(eventName, path);

// Avoid conflicts if we later create another directory with the same name
if (isDirectory && !this.options.usePolling) {
this.unwatch(path);
}
};

// Public method: Adds paths to be watched on an existing FSWatcher instance
Expand Down
30 changes: 30 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function rmFixtures() {
try { fs.rmdirSync(getFixturePath('subdir/subsub/subsubsub')); } catch(err) {}
try { fs.unlinkSync(getFixturePath('subdir/subsub/ab.txt')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir/subsub')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir2/dir')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir2')); } catch(err) {}
try { fs.rmdirSync(getFixturePath('subdir')); } catch(err) {}
}
Expand Down Expand Up @@ -290,6 +291,35 @@ function runTests(options) {
});
}));
});
it('should watch removed and re-added directories', function(done) {
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var parentPath = getFixturePath('subdir2');
var subPath = getFixturePath('subdir2/dir');
watcher
.on('unlinkDir', unlinkSpy)
.on('addDir', addSpy)
.on('ready', d(function() {
fs.mkdirSync(parentPath);
d(function() {
fs.rmdirSync(parentPath);
waitFor([unlinkSpy], function() {
unlinkSpy.should.have.been.calledWith(parentPath);
d(function() {
fs.mkdirSync(parentPath);
d(function() {
fs.mkdirSync(subPath);
waitFor([addSpy], d(function() {
addSpy.should.have.been.calledWith(parentPath);
addSpy.should.have.been.calledWith(subPath);
done();
}, false, true));
}, false, true)();
}, false, true)();
});
}, false, true)()
}));
})
});
describe('watch individual files', function() {
beforeEach(clean);
Expand Down

0 comments on commit 1d11418

Please sign in to comment.