Skip to content

Commit 117d09a

Browse files
committed
test: stabilize test-vfs-watch-directory
The first block used persistent: false plus setTimeout to trigger the write. The watcher's poll timer was unref'd, so on slow runners the write timer could fire before the first poll and the change event would be missed. Use the same await-once pattern as the other blocks in the file with a content-length change so the size-based stat-change detector always fires. Assisted-by: Claude-Opus4.7 Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 98f37a8 commit 117d09a

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

test/parallel/test-vfs-watch-directory.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@ const assert = require('assert');
1111
const { once } = require('events');
1212
const vfs = require('node:vfs');
1313

14-
// Modifying a child file of a watched directory must emit a change event.
15-
{
16-
const myVfs = vfs.create();
17-
myVfs.mkdirSync('/parent', { recursive: true });
18-
myVfs.writeFileSync('/parent/file.txt', 'x');
19-
20-
const watcher = myVfs.watch('/parent', {
21-
interval: 50,
22-
persistent: false,
23-
}, common.mustCall((eventType, filename) => {
14+
(async () => {
15+
// Modifying a child file emits a change event.
16+
{
17+
const myVfs = vfs.create();
18+
myVfs.mkdirSync('/parent', { recursive: true });
19+
myVfs.writeFileSync('/parent/file.txt', 'x');
20+
const watcher = myVfs.watch('/parent', { interval: 25 });
21+
const changed = once(watcher, 'change');
22+
myVfs.writeFileSync('/parent/file.txt', 'longer-content-changed');
23+
const [, filename] = await changed;
2424
assert.strictEqual(filename, 'file.txt');
2525
watcher.close();
26-
}));
27-
28-
setTimeout(() => myVfs.writeFileSync('/parent/file.txt', 'y'), 100);
29-
}
26+
}
3027

31-
(async () => {
3228
// Non-recursive directory watch: file creation
3329
{
3430
const myVfs = vfs.create();

0 commit comments

Comments
 (0)