-
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
EINVAL on Node 16.3.0 #332
Comments
… mock-fs (#15571) Recently we found an issue on our CI build for Node 16.3.0, which boiled down to one unit test specific to Identity: #15547 After some investigation, it is clear that Node 16.3.0 has some incompatibility with mock-fs: tschaub/mock-fs#332 In the mean time, to add this test again, we can simply create a file, point to it and delete it at the end. This should work in all versions of Node, and it means one less dev-dependency for us.
Nodejs v16.3.0 might just closed the door for mock-fs. https://github.com/nodejs/node/pull/38737/files Now the Our patch relies on the lazy loading of Lines 22 to 42 in 535a948
Note before Nodejs v10, Nodejs source code always uses But now, Nodjes v10+ uses Previously the lazy loaded |
First, I just wanted to throw in that if we're truly at an unmockable place with Node.js internals, I'd personally be willing to consider a replacement for // Some external flag.
const IS_TEST = process.env.IS_TEST === "true";
const fs = IS_TEST ? require("fs") : require("mock-fs").alternateFsMock; I normally don't like having test conditionals in actual library code, but for |
@ryan-roemer you can use https://www.npmjs.com/package/memfs. |
Just an update: We moved to use |
I'm also loving @3cp @tschaub how hacky would you be willing to get to patch things? The const realBinding = process.binding('fs');
const originalOpen = realBinding.open;
realBinding.open = (_path, _flags, _mode, req) => {
const proto = Object.getPrototypeOf(req.context)
proto.read = () => { /* mock hook */ }
}
fs.readFile('/nothing.txt', () => {});
realBinding.open = originalOpen; You'd then reroute the |
@Rugvip have you tried your suggested method? It didn't work for me in either 16.5.0 or 14.17.0. The mocked proto.read is never called. |
@3cp Hmm, strange, could it be that it doesn't handle all different ways of reading files? Here's a more complete example, working with 14.17.0, 16.5.0, and 16.7.0: const fs = require('fs');
const fsBinding = process.binding('fs');
const originalOpen = fsBinding.open;
fsBinding.open = (_path, _flags, _mode, req) => {
const proto = Object.getPrototypeOf(req.context);
console.log('Applying hook');
proto.read = function () {
console.log('Hook was called');
this.callback(null, Buffer.from('hello'));
};
};
fs.readFile('/nothing.txt', () => {});
fsBinding.open = originalOpen;
// Our actual call that we wanted to mock
fs.readFile('/', (err, content) => {
console.log(`err=${err} content=${content}`);
}); |
Oh, thx! I misunderstood you code. |
Fix from @Rugvip published in |
Hello, team!
This is not a blocking issue for me, and it really could be just a bug on Node 16.3.0.
Using mock-fs v5 (and v4), the code I’ll share below works in Node 16.2.0, but does not work in 16.3.0.
The code:
It logs the following on Node 16.2.0:
On Node 16.3.0, I get the following error:
I’m thinking on opening an issue on Node’s source itself, but it seems to me that tracking down this to the underlying bug may take me a long time, so I’m making an issue here in case anybody can help me understand what is going on. (If anybody knows what’s up and wants to open the issue, please do so! But also share it here 🌞).
Any help is appreciated.
The text was updated successfully, but these errors were encountered: