From c708c452370610fdce1d264a67db9261748b71f1 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 12 Mar 2024 16:04:04 +0300 Subject: [PATCH] fix: do not report directory as initial missing on the second watch --- lib/DirectoryWatcher.js | 1 + test/DirectoryWatcher.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/DirectoryWatcher.js b/lib/DirectoryWatcher.js index abbb142..32eb3cc 100644 --- a/lib/DirectoryWatcher.js +++ b/lib/DirectoryWatcher.js @@ -365,6 +365,7 @@ class DirectoryWatcher extends EventEmitter { !this.directories.has(filePath) && watcher.checkStartTime(this.initialScanFinished, false) ) { + console.log(watcher.checkStartTime(this.initialScanFinished, false)) process.nextTick(() => { if (this.closed) return; watcher.emit("initial-missing", "watch (missing on attach)"); diff --git a/test/DirectoryWatcher.js b/test/DirectoryWatcher.js index 8b8072d..f5cf8d8 100644 --- a/test/DirectoryWatcher.js +++ b/test/DirectoryWatcher.js @@ -169,6 +169,29 @@ describe("DirectoryWatcher", function() { }); }); + it("should not report directory as initial missing on the second watch", 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; + } + ); + process.nextTick(() => { + 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;