Skip to content

Commit

Permalink
fix(FsEvents): Remove situation with NaN depth. (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSMonk authored and paulmillr committed Apr 19, 2019
1 parent 7cf3f7e commit 41f8782
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/fsevents-handler.js
Expand Up @@ -19,6 +19,8 @@ if (fsevents) {
}
}

const Option = (key, value) => isNaN(value) ? {} : {[key]: value};

/**
* @typedef {String} Path
*/
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 7 additions & 8 deletions test.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}));
Expand Down

0 comments on commit 41f8782

Please sign in to comment.