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
3 changes: 2 additions & 1 deletion lib/internal/vfs/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,10 @@ class VirtualProvider {
* @param {object} [options] Watch options
* @param {number} [options.interval] Polling interval in ms (default: 5007)
* @param {boolean} [options.persistent] Whether the watcher should prevent exit
* @param {Function} [listener] Change listener
* @throws {ERR_METHOD_NOT_IMPLEMENTED} When not overridden by subclass
*/
watchFile(path, options) {
watchFile(path, options, listener) {
throw new ERR_METHOD_NOT_IMPLEMENTED('watchFile');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/vfs/providers/real.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,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
11 changes: 11 additions & 0 deletions test/parallel/test-vfs-real-provider-watch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Flags: --experimental-vfs
'use strict';

Expand Down Expand Up @@ -38,3 +38,14 @@
myVfs.watchFile('/wf.txt', { persistent: false }, listener);
myVfs.unwatchFile('/wf.txt', listener);
}

// watchFile listener fires on change
(async () => {
fs.writeFileSync(path.join(root, 'wf2.txt'), 'a');
const fired = new Promise((resolve) => {
myVfs.watchFile('/wf2.txt', { interval: 25 }, common.mustCall(resolve));
});
fs.writeFileSync(path.join(root, 'wf2.txt'), 'b');
await fired;
myVfs.unwatchFile('/wf2.txt');
})().then(common.mustCall());
Loading