Skip to content

Commit

Permalink
fix readyCount logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 6, 2023
1 parent 08318d6 commit 1370123
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ add(paths_, _origAdd, _internal) {

if (this.options.useFsEvents && this._fsEventsHandler) {
if (!this._readyCount) this._readyCount = paths.length;
if (this.options.persistent) this._readyCount *= 2;
if (this.options.persistent) this._readyCount += paths.length;
paths.forEach((path) => this._fsEventsHandler._addToFsEvents(path));
} else {
if (!this._readyCount) this._readyCount = 0;
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ const runTests = (baseopts) => {
unlinkSpy.withArgs(newPath1).should.have.been.calledOnce;
unlinkSpy.withArgs(newPath2).should.not.have.been.called;
});
it('should emit `ready` when three files were added', async () => {
const path1 = getFixturePath('add1.txt');
const path2 = getFixturePath('add2.txt');
const path3 = getFixturePath('add3.txt');

watcher.add(path1);
watcher.add(path2);
watcher.add(path3);

await waitForWatcher(watcher);
});
it('should survive ENOENT for missing subdirectories', async () => {
const testDir = getFixturePath('notadir');
await waitForWatcher(watcher);
Expand Down

0 comments on commit 1370123

Please sign in to comment.