Skip to content

Commit

Permalink
fix: do not report directory as initial missing on the second watch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 12, 2024
2 parents f5baba7 + 3c5eefd commit 74439b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/DirectoryWatcher.js
Expand Up @@ -362,6 +362,7 @@ class DirectoryWatcher extends EventEmitter {
});
}
} else if (
filePath !== this.path &&
!this.directories.has(filePath) &&
watcher.checkStartTime(this.initialScanFinished, false)
) {
Expand Down
46 changes: 46 additions & 0 deletions test/DirectoryWatcher.js
Expand Up @@ -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;
Expand Down

0 comments on commit 74439b1

Please sign in to comment.