Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/internal/vfs/providers/real.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ class RealFSProvider extends VirtualProvider {
return fs.promises.watch(realPath, options);
}

watchFile(vfsPath, options) {
watchFile(vfsPath, options, listener) {
const realPath = this.#resolvePath(vfsPath);
return fs.watchFile(realPath, options, () => {});
return fs.watchFile(realPath, options, listener);
}

unwatchFile(vfsPath, listener) {
Expand Down
18 changes: 14 additions & 4 deletions test/parallel/test-vfs-real-provider-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ assert.strictEqual(myVfs.provider.supportsWatch, true);
await iter.return();
})().then(common.mustCall());

// watchFile / unwatchFile
// watchFile / unwatchFile: the listener must be forwarded to the real fs
// watcher (not stubbed), fire on change, and be removable by identity.
{
fs.writeFileSync(path.join(root, 'wf.txt'), 'a');
const listener = () => {};
myVfs.watchFile('/wf.txt', { persistent: false }, listener);
myVfs.unwatchFile('/wf.txt', listener);
const listener = common.mustCall();
myVfs.watchFile('/wf.txt', { interval: 10, persistent: false }, listener);
// uv_fs_poll records the first stat asynchronously as the baseline and
// only reports subsequent changes, so mutate the file only after that
// baseline reflects 'a'; otherwise the change is folded into the baseline
// and the listener never fires. Change the size too, because some
// platforms (e.g. AIX) only report timestamps to the second, so a
// same-size rewrite within that second would look unchanged.
setTimeout(() => fs.writeFileSync(path.join(root, 'wf.txt'), 'bb'), 100);
setTimeout(() => {
myVfs.unwatchFile('/wf.txt', listener);
}, 500);
}
Loading