-
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
Only works the first time #254
Comments
@bard got the same issue but after migrating to 10.11.0 it's gone UPD: I was wrong, still doesn't work :( |
Preliminary investigation and here's what I've got: in Node 10 a new helper This utility pulls functions directly from the binding, and doesn't reference the binding as an object with dynamic properties, making overriding it impossible. https://github.com/nodejs/node/blob/master/lib/internal/fs/read_file_context.js#L4 It is also lazy-loaded, so the first time it's called it
In the second call, it's still the first Side note: if you make a call to Maybe we could look into reusing the I'll try to submit a PR to https://github.com/nodejs/node to not dereference the binding functions in TL;DR: It's borked for node 10. It could be less borked. |
bad news - Node 11 is moving away from process.binding entirely |
With the most recent changes on Node 10 and on Node 11 this library won't work anymore with logic it uses for apply the bindings. The only possible way right now seems to me like instead of binding the process.binding('fs') methods we need to reassign the methods for the |
@mistic - The Ideally, we could engage with Node folks on ideas for an in-memory filesystem implementation. Providing an alternate binding felt like the most sensible way to do this. But it has been very painful to provide support across multiple Node versions. Another thing that might be worth considering is dropping support for more than one version of Node. It would be far more straightforward to target a single major version. The reason I tried to support more than one version of Node was that I imagined that people wanted to run tests on multiple Node versions. Providing an in-memory filesystem implementation that works across multiple Node versions when there is no supported way to do such a thing has proven to be more work than I have time for. |
OP here. I'ts no drop-in replacement but I've been using https://github.com/streamich/memfs |
This should be addressed on the 4.8.0 release (thanks @huochunpeng, see #260). |
I had a second look of this issue, which is the same cause for #264. The reason for working for the first time is that first read is after first mock(), so if (!ReadFileContext)
ReadFileContext = require('internal/fs/read_file_context'); nodejs const { FSReqWrap, close, read } = process.binding('fs'); trapped the first mocked For the case of #264, it trapped |
Shown with promises and async/await for clarity. The issue doesn't change with nested callbacks, and makes it impossible to use mock-fs in automated tests.
Output:
Environment:
The text was updated successfully, but these errors were encountered: