Description
As seen in #383:
Nodejs also planed to cut off process.binding() from user land, that's death sentence for mock-fs.
I've taken the liberty of throwing together a quick gist for this as a proof of concept. It provides a mechanism to switch access between real and fake file system by calling fakefs()
and fakefs.restore()
, resp. For this, it intercepts import resolution requests to fs
or node:fs
and redirects them to a dedicated module, which in turn exports a Proxy
that basically acts as a switch between the real and the fake file system at will.
The only caveat with this approach that I can see is that the hooks would need to be registered right at the beginning, but this should easily be doable by specifying an import flag. Mocha even supports doing this as part of the configuration file.
I would love if this project could be kept alive. The only alternative I have found is memfs, and I dislike that I have to manually mock the fs
import in the system under test literally every time.