From 6c3b648b94ae1bd2cdc17ca0465f2032440ae048 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Fri, 19 Apr 2019 17:00:50 +0300 Subject: [PATCH] fix(FsEvents): Remove situation with NaN depth. --- lib/fsevents-handler.js | 4 +++- test.js | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/fsevents-handler.js b/lib/fsevents-handler.js index 02580c42..b4444778 100644 --- a/lib/fsevents-handler.js +++ b/lib/fsevents-handler.js @@ -19,6 +19,8 @@ if (fsevents) { } } +const Option = (key, value) => isNaN(value) ? {} : {[key]: value}; + /** * @typedef {String} Path */ @@ -398,7 +400,7 @@ _addToFsEvents(path, transform, forceAdd, priorDepth) { this.fsw._readdirp(wh.watchPath, { fileFilter: wh.filterPath, directoryFilter: wh.filterDir, - depth: opts.depth - (priorDepth || 0) + ...Option("depth", opts.depth - (priorDepth || 0)) }).on('data', (entry) => { // need to check filterPath on dirs b/c filterDir is less restrictive if (entry.stats.isDirectory() && !wh.filterPath(entry)) return; diff --git a/test.js b/test.js index 5381e4f6..5cbad8c5 100644 --- a/test.js +++ b/test.js @@ -368,6 +368,7 @@ const runTests = function(baseopts) { fs.mkdirSync(testDir2, PERM_ARR); fs.mkdirSync(testDir3, PERM_ARR); const spy = await aspy(watcher, 'unlinkDir'); + await waitFor([spy]); await rimraf(testDir2); // test removing in one await waitFor([spy]); spy.should.have.been.calledWith(testDir2); @@ -688,8 +689,7 @@ const runTests = function(baseopts) { await delay(1000); await fs_rename(testDir, renamedDir); - await waitFor([spy]); - spy.should.have.been.calledOnce; + await waitFor([spy.withArgs(expectedPath)]); spy.should.have.been.calledWith(expectedPath); }); }); @@ -766,11 +766,11 @@ const runTests = function(baseopts) { await delay(); let watcher = chokidar_watch(watchPath, options); const spy = await aspy(watcher, 'all'); - setTimeout(() => { - write(getFixturePath('add.txt'), Date.now()); - write(getFixturePath('subdir/subsub/ab.txt'), Date.now()); - fs_unlink(getFixturePath('subdir/a.txt')); - fs_unlink(getFixturePath('subdir/b.txt')); + setTimeout(async () => { + await write(getFixturePath('add.txt'), Date.now()); + await write(getFixturePath('subdir/subsub/ab.txt'), Date.now()); + await fs_unlink(getFixturePath('subdir/a.txt')); + await fs_unlink(getFixturePath('subdir/b.txt')); }, 50); await waitFor([[spy.withArgs('add'), 3], spy.withArgs('unlink'), spy.withArgs('change')]); spy.withArgs('add').should.have.been.calledThrice; @@ -2043,7 +2043,6 @@ describe('chokidar', function() { if (FsEventsHandler.canUse()) { describe('fsevents (native extension)', runTests.bind(this, {useFsEvents: true})); } - } else { } describe('fs.watch (non-polling)', runTests.bind(this, {usePolling: false, useFsEvents: false})); describe('fs.watchFile (polling)', runTests.bind(this, {usePolling: true, interval: 10}));