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

Add tests to narrowly demonstrate defect mentioned in PR #682 #737

Merged
merged 6 commits into from
Jun 19, 2018
Merged
Changes from 5 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
111 changes: 110 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,121 @@ 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 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