Skip to content

Commit

Permalink
test: test debounced behavior on multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Apr 29, 2024
1 parent b220568 commit 5d423c6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/parallel/test-watch-mode-files_watcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ describe('watch mode file watcher', () => {
assert.ok(changesCount < 5);
});

it('should debounce changes on multiple files', async () => {
const files = []
for (let i = 0; i < 10; i++) {
const file = tmpdir.resolve(`file-debounced-${i}`);
writeFileSync(file, 'written');
watcher.filterFile(file);
files.push(file);
}

files.forEach((file) => writeFileSync(file, '1'));
files.forEach((file) => writeFileSync(file, '2'));
files.forEach((file) => writeFileSync(file, '3'));
files.forEach((file) => writeFileSync(file, '4'));

await setTimeout(200); // debounce * 2
files.forEach((file) => writeFileSync(file, '5'));
const changed = once(watcher, 'changed');
files.forEach((file) => writeFileSync(file, 'after'));
await changed;
// Unfortunately testing that changesCount === 2 is flaky
assert.ok(changesCount < 5);
});

it('should ignore files in watched directory if they are not filtered',
{ skip: !supportsRecursiveWatching }, async () => {
watcher.on('changed', common.mustNotCall());
Expand Down

0 comments on commit 5d423c6

Please sign in to comment.