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 readyCount logic #1288

Merged
merged 2 commits into from
Sep 6, 2023
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
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
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,21 @@ const runTests = (baseopts) => {
});
});
describe('watch individual files', () => {
it('should emit `ready` when three files were added', async () => {
const readySpy = sinon.spy(function readySpy(){});
const watcher = chokidar_watch().on(EV_READY, readySpy);
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);
// callCount is 1 on macOS, 4 on Ubuntu
readySpy.callCount.should.be.greaterThanOrEqual(1);
});
it('should detect changes', async () => {
const testPath = getFixturePath('change.txt');
const watcher = chokidar_watch(testPath, options);
Expand Down