Skip to content

Commit

Permalink
Use realPath instead of path on watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
RoXuS committed Mar 16, 2021
1 parent 4e4106b commit 07c7f12
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fsevents-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ const createFSEventsInstance = (path, callback) => {
* @returns {Function} closer
*/
function setFSEventsListener(path, realPath, listener, rawEmitter) {
let watchPath = sysPath.extname(path) ? sysPath.dirname(path) : path;
let watchPath = sysPath.extname(realPath) ? sysPath.dirname(realPath) : realPath;

const parentPath = sysPath.dirname(watchPath);
let cont = FSEventsWatchers.get(watchPath);

Expand Down
39 changes: 39 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,45 @@ const runTests = (baseopts) => {
});
}
});
describe('reproduction of bug in issue #1040', () => {
it('should detect change on symlink folders when consolidateThreshhold is reach', async () => {
const id = subdirId.toString();

const fixturesPathRel = sysPath.join(FIXTURES_PATH_REL, id, 'test-case-1040');
const linkPath = sysPath.join(fixturesPathRel, 'symlinkFolder');
await fs_mkdir(sysPath.resolve(linkPath), { recursive: true });

// Init chokidar
const watcher = chokidar.watch([]);
const events = [];

// Add more than 10 folders to cap consolidateThreshhold
for (let i = 0 ; i < 20 ; i += 1) {
const folderPath = sysPath.join(fixturesPathRel, 'packages', `folder${i}`);
await fs_mkdir(sysPath.resolve(folderPath), { recursive: true });
const filePath = sysPath.join(folderPath, `file${i}.js`);
await write(sysPath.resolve(filePath), 'file content');
const symlinkPath = sysPath.join(linkPath, `folder${i}`);
await fs_symlink(sysPath.resolve(folderPath), symlinkPath);
watcher.add(sysPath.resolve(sysPath.join(symlinkPath, `file${i}.js`)));
}

// Wait to be sure that we have no other event than the update file
await delay(300);
watcher.on('change', (event, path) =>
events.push(`[change] ${event}: ${path}`)
);

// Update a random generated file to fire an event
const randomFilePath = sysPath.join(fixturesPathRel, 'packages', 'folder17', 'file17.js');
await write(sysPath.resolve(randomFilePath), 'file content changer zeri ezhriez');

// Wait chokidar watch
await delay(300);

expect(events.length).to.equal(1);
})
});
describe('reproduction of bug in issue #1024', () => {
it('should detect changes to folders, even if they were deleted before', async () => {
const id = subdirId.toString();
Expand Down

0 comments on commit 07c7f12

Please sign in to comment.