Skip to content

Commit 16b2a0e

Browse files
authored
Merge pull request #33 from nkzawa/fix/remove-event
Fix remove event is not emitted
2 parents d9b0dbc + 0232e01 commit 16b2a0e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/DirectoryWatcher.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ DirectoryWatcher.prototype.setFileTime = function setFileTime(filePath, mtime, i
8383
this.files[filePath] = [initial ? Math.min(now, mtime) : now, mtime];
8484

8585
// we add the fs accurency to reach the maximum possible mtime
86-
mtime = mtime + FS_ACCURENCY;
86+
if(mtime)
87+
mtime = mtime + FS_ACCURENCY;
8788

8889
if(!old) {
8990
if(mtime) {

test/DirectoryWatcher.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,18 @@ describe("DirectoryWatcher", function() {
143143
});
144144
});
145145
});
146+
147+
it("should detect a file removal", function(done) {
148+
testHelper.file("a");
149+
var d = new DirectoryWatcher(fixtures, {});
150+
var a = d.watch(path.join(fixtures, "a"));
151+
a.on("remove", function(mtime) {
152+
(typeof mtime === 'undefined').should.be.true;
153+
a.close();
154+
done();
155+
});
156+
testHelper.tick(function() {
157+
testHelper.remove("a");
158+
});
159+
});
146160
});

0 commit comments

Comments
 (0)