-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keeping mock-fs alive without process.binding #386
Comments
This sounds really promising, @BadIdeaException. I really appreciate you taking the time to investigate this. I'll try to make time in the coming days to see what it would be like to use your approach. |
I'm happy to hear that. Also will be happy to help more if I can. |
@tschaub Any news on this yet? I have been playing around with it a little in a local copy (I haven't forked, just cloned and went wild), and I have been able to throw this together in a way that both keeps the existing compatibility with CommonJS and does its new trick with ESM. New Gist here. Just add the files into Trying itFor convenience, I then symlinked this into
and
Ergo, works in both ways. Some remarks and open questions
Would love to hear your thoughts. |
As seen in #383:
and had started wondering if Loaders (now called Customization Hooks) might be a way to control access to the fs module without needing access to
process.binding
.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()
andfakefs.restore()
, resp. For this, it intercepts import resolution requests tofs
ornode:fs
and redirects them to a dedicated module, which in turn exports aProxy
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.The text was updated successfully, but these errors were encountered: