Skip to content

Commit

Permalink
Merge pull request #737 from srguiwiz/fix-issue-682
Browse files Browse the repository at this point in the history
Add tests to narrowly demonstrate defect mentioned in PR #682
  • Loading branch information
es128 committed Jun 19, 2018
2 parents 3ad1ae8 + 5966686 commit b1f8bcb
Showing 1 changed file with 134 additions and 1 deletion.
135 changes: 134 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,145 @@ function runTests(baseopts) {
});
});
});
it('should detect unlink while watching a non-existent second file in another directory', function(done) {
var spy = sinon.spy();
var testPath = getFixturePath('unlink.txt');
var otherDirPath = getFixturePath('other-dir');
var otherPath = getFixturePath('other-dir/other.txt');
fs.mkdirSync(otherDirPath, 0x1ed);
// intentionally for this test don't write fs.writeFileSync(otherPath, 'other');
watcher = chokidar.watch([testPath, otherPath], options)
.on('unlink', spy)
.on('ready', function() {
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([spy], function() {
spy.should.have.been.calledWith(testPath);
done();
});
});
});
it('should detect unlink and re-add', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
watcher = chokidar.watch([testPath, testPath + '.does-not-exist'], options)
watcher = chokidar.watch([testPath], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([unlinkSpy], w(function() {
unlinkSpy.should.have.been.calledWith(testPath);
w(fs.writeFile.bind(fs, testPath, 're-added', simpleCb))();
waitFor([addSpy], function() {
addSpy.should.have.been.calledWith(testPath);
done();
});
}));
});
});
it('should detect unlink and re-add while watching a second file', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
var otherPath = getFixturePath('other.txt');
fs.writeFileSync(otherPath, 'other');
watcher = chokidar.watch([testPath, otherPath], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([unlinkSpy], w(function() {
unlinkSpy.should.have.been.calledWith(testPath);
w(fs.writeFile.bind(fs, testPath, 're-added', simpleCb))();
waitFor([addSpy], function() {
addSpy.should.have.been.calledWith(testPath);
done();
});
}));
});
});
it('should detect unlink and re-add while watching a non-existent second file in another directory', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
var otherDirPath = getFixturePath('other-dir');
var otherPath = getFixturePath('other-dir/other.txt');
fs.mkdirSync(otherDirPath, 0x1ed);
// intentionally for this test don't write fs.writeFileSync(otherPath, 'other');
watcher = chokidar.watch([testPath, otherPath], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([unlinkSpy], w(function() {
unlinkSpy.should.have.been.calledWith(testPath);
w(fs.writeFile.bind(fs, testPath, 're-added', simpleCb))();
waitFor([addSpy], function() {
addSpy.should.have.been.calledWith(testPath);
done();
});
}));
});
});
it('should detect unlink and re-add while watching a non-existent second file in the same directory', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
var otherPath = getFixturePath('other.txt');
// intentionally for this test don't write fs.writeFileSync(otherPath, 'other');
watcher = chokidar.watch([testPath, otherPath], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([unlinkSpy], w(function() {
unlinkSpy.should.have.been.calledWith(testPath);
w(fs.writeFile.bind(fs, testPath, 're-added', simpleCb))();
waitFor([addSpy], function() {
addSpy.should.have.been.calledWith(testPath);
done();
});
}));
});
});
it('should detect two unlinks and one re-add', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
var otherPath = getFixturePath('other.txt');
fs.writeFileSync(otherPath, 'other');
watcher = chokidar.watch([testPath, otherPath], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
w(fs.unlink.bind(fs, otherPath, simpleCb))();
w(fs.unlink.bind(fs, testPath, simpleCb))();
waitFor([[unlinkSpy, 2]], w(function() {
unlinkSpy.should.have.been.calledWith(otherPath);
unlinkSpy.should.have.been.calledWith(testPath);
w(fs.writeFile.bind(fs, testPath, 're-added', simpleCb))();
waitFor([addSpy], function() {
addSpy.should.have.been.calledWith(testPath);
done();
});
}));
});
});
it('should detect unlink and re-add while watching a second file and a non-existent third file', function(done) {
options.ignoreInitial = true;
var unlinkSpy = sinon.spy(function unlinkSpy(){});
var addSpy = sinon.spy(function addSpy(){});
var testPath = getFixturePath('unlink.txt');
var otherPath = getFixturePath('other.txt');
var other2Path = getFixturePath('other2.txt');
fs.writeFileSync(otherPath, 'other');
// intentionally for this test don't write fs.writeFileSync(other2Path, 'other2');
watcher = chokidar.watch([testPath, otherPath, other2Path], options)
.on('unlink', unlinkSpy)
.on('add', addSpy)
.on('ready', function() {
Expand Down

0 comments on commit b1f8bcb

Please sign in to comment.