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

fix: do not report directory as initial missing on the second watch #237

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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