Skip to content

Commit

Permalink
test: Added unit test to reproduce bug #1061
Browse files Browse the repository at this point in the history
  • Loading branch information
jrebmann committed Jan 12, 2021
1 parent 95dd156 commit 6400338
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,47 @@ const runTests = (baseopts) => {
watcher.close();
}
});

it('should detect changes to symlink folders, even if they were deleted before', async () => {
const id = subdirId.toString();
const relativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test');
const linkedRelativeWatcherDir = sysPath.join(FIXTURES_PATH_REL, id, 'test-link');
await fs_symlink(sysPath.resolve(relativeWatcherDir), linkedRelativeWatcherDir);
const watcher = chokidar.watch(linkedRelativeWatcherDir, {
persistent: true,
});
try {
const events = [];
watcher.on('all', (event, path) =>
events.push(`[ALL] ${event}: ${path}`)
);
const testSubDir = sysPath.join(relativeWatcherDir, 'dir');
const testSubDirFile = sysPath.join(relativeWatcherDir, 'dir', 'file');

// Command sequence from https://github.com/paulmillr/chokidar/issues/1042.
await delay();
await fs_mkdir(relativeWatcherDir);
await fs_mkdir(testSubDir);
// The following delay is essential otherwise the call of mkdir and rmdir will be equalize
await delay(300);
await fs_rmdir(testSubDir);
// The following delay is essential otherwise the call of rmdir and mkdir will be equalize
await delay(300);
await fs_mkdir(testSubDir);
await write(testSubDirFile, '');
await delay(300);

chai.assert.deepStrictEqual(events, [
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] unlinkDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] addDir: ${sysPath.join('test-fixtures', id, 'test-link', 'dir')}`,
`[ALL] add: ${sysPath.join('test-fixtures', id, 'test-link', 'dir', 'file')}`,
]);
} finally {
watcher.close();
}
});
});
};

Expand Down

0 comments on commit 6400338

Please sign in to comment.