diff --git a/lib/DirectoryWatcher.js b/lib/DirectoryWatcher.js index abbb142..034447d 100644 --- a/lib/DirectoryWatcher.js +++ b/lib/DirectoryWatcher.js @@ -362,6 +362,7 @@ class DirectoryWatcher extends EventEmitter { }); } } else if ( + filePath !== this.path && !this.directories.has(filePath) && watcher.checkStartTime(this.initialScanFinished, false) ) { diff --git a/test/DirectoryWatcher.js b/test/DirectoryWatcher.js index 8b8072d..30c1757 100644 --- a/test/DirectoryWatcher.js +++ b/test/DirectoryWatcher.js @@ -169,6 +169,52 @@ describe("DirectoryWatcher", function() { }); }); + it("should report directory as initial missing on the second watch when directory doesn't exist", function(done) { + var wm = getWatcherManager({}); + testHelper.dir("dir1"); + wm.watchDirectory(path.join(fixtures, "dir1")); + + testHelper.tick(function() { + var initialMissing = false; + wm.watchDirectory(path.join(fixtures, "dir3")).on( + "initial-missing", + () => { + initialMissing = true; + } + ); + testHelper.tick(function() { + for (const [, w] of wm.directoryWatchers) { + w.close(); + } + initialMissing.should.be.eql(true); + done(); + }); + }); + }); + + it("should not report directory as initial missing on the second watch when directory exists", function(done) { + var wm = getWatcherManager({}); + testHelper.dir("dir1"); + wm.watchDirectory(path.join(fixtures, "dir1")); + + testHelper.tick(function() { + var initialMissing = false; + wm.watchDirectory(path.join(fixtures, "dir1")).on( + "initial-missing", + () => { + initialMissing = true; + } + ); + testHelper.tick(function() { + for (const [, w] of wm.directoryWatchers) { + w.close(); + } + initialMissing.should.be.eql(false); + done(); + }); + }); + }); + if (!+process.env.WATCHPACK_POLLING) { it("should log errors emitted from watcher to stderr", function(done) { var error_logged = false;