From 1370123de8b21090faa76aa8b911a07bad2579a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Tue, 5 Sep 2023 20:41:07 -0400 Subject: [PATCH 1/2] fix readyCount logic --- index.js | 2 +- test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ed4b6d5b..8752893c 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/test.js b/test.js index 3e91d8f1..a909ea28 100644 --- a/test.js +++ b/test.js @@ -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); From f022fe7e978f690ba9ab12be14f02bcc73f9d78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Wed, 6 Sep 2023 10:55:13 -0400 Subject: [PATCH 2/2] ready call # is unfortunately platform specific --- test.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/test.js b/test.js index a909ea28..cdf982fb 100644 --- a/test.js +++ b/test.js @@ -469,17 +469,6 @@ 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); @@ -560,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);