tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
911 stars 86 forks source link

Support for fs.opendir() #319

Open voxpelli opened 3 years ago

voxpelli commented 3 years ago

Noticed that mock-fs currently doesn't support fs.opendir (added in Node.js 12.12.0), which made one of my modules, list-installed, not recognize the mocked data which I tried to make it act on in another of my modules.

Since I couldn't see a mention of this I thought I should open an issue to keep track of it.

3cp commented 3 years ago

Running into big trouble. Mock-fs works through replacing Nodejs internal binding for fs.

But in Nodejs v12.12.0+, it introduced another internal binding fs_dir.

https://github.com/nodejs/node/blob/7296bcb3cb937ee6b3d607f8cfb84db21ebb069d/lib/internal/fs/dir.js#L15-L16

The problem is, the new fs_dir binding is not exposed to user code.

https://github.com/nodejs/node/blob/7296bcb3cb937ee6b3d607f8cfb84db21ebb069d/lib/internal/bootstrap/loaders.js#L73-L107

We could not grab the existing fs_dir binding through process.binding('fs_dir'). It means we could not replace/restore it. @tschaub any idea how to work around this?

3cp commented 3 years ago

From the above linked Nodejs issue, it's unlikely that Nodejs will open up fs_dir access.

voxpelli commented 3 years ago

Thanks for looking into it! I guess this becomes a wider issue then, maybe ultimately requiring another approach to patching. Feel free to close this for now if you think that would be out of scope for this.

m4s0 commented 2 years ago

Thanks for looking into it! I guess this becomes a wider issue then, maybe ultimately requiring another approach to patching. Feel free to close this for now if you think that would be out of scope for this.

@voxpelli how did you solve it?