Skip to content
Merged
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
test: deflake fs-promises-watch
Change the contents of the file every 100 milliseconds until the watcher
notices the change. This is already done in the callback based version
of the test (`test-fs-watch.js`).

Fixes: #37637
  • Loading branch information
lpinca committed Nov 18, 2021
commit c79b3c06ccbfb31a5cb7f79ec5d2f122f8712cfa
6 changes: 4 additions & 2 deletions test/parallel/test-fs-promises-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ for (const testCase of kCases) {
const content1 = Date.now() + testCase.fileName.toLowerCase().repeat(1e4);
fs.writeFileSync(testCase.filePath, content1);

let interval;
async function test() {
const watcher = watch(testCase[testCase.field]);
for await (const { eventType, filename } of watcher) {
clearInterval(interval);
assert.strictEqual(['rename', 'change'].includes(eventType), true);
assert.strictEqual(filename, testCase.fileName);
break;
Expand All @@ -64,10 +66,10 @@ for (const testCase of kCases) {

// Long content so it's actually flushed. toUpperCase so there's real change.
const content2 = Date.now() + testCase.fileName.toUpperCase().repeat(1e4);
setImmediate(() => {
interval = setInterval(() => {
fs.writeFileSync(testCase.filePath, '');
fs.writeFileSync(testCase.filePath, content2);
});
}, 100);

test().then(common.mustCall());
}
Expand Down