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(FsEvents): Remove situation with NaN depth. #823

Merged
merged 1 commit into from
Apr 19, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/fsevents-handler.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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