-
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
Unexpected ENOENT when using createReadStream #338
Comments
I can reproduce the error in Nodejs v16, but not v14. Don't need to use jest to reproduce the bug. const mockFs = require("mock-fs");
const fs = require("fs");
const { writeFile, unlink } = require("fs/promises");
const { join } = require("path");
const { tmpdir } = require("os");
mockFs();
// mockFs.restore();
async function test() {
const path = join(tmpdir(), `tmpfile-${Math.random()}.png`);
await writeFile(path, Buffer.from("whatever"));
const rs = fs.createReadStream(path);
// rs.close();
await unlink(path);
}
test().then(() => console.log("DONE"));
|
Update: I found there is a very strange timing issue. My log shows the logic inside This can be approved with 2 ways:
async function delay() {
return new Promise(resolve => {
setTimeout(resolve, 500);
});
}
// ...
await delay();
await unlink(path); Since nodejs v14 has no such issue, there might be some bug or edge case in nodejs v16. |
I can reproduce the same issue WITHOUT using mock-fs in nodejs v16.13.0, so this is probably an unexpected bug in nodejs v16+ itself. const fs = require("fs");
const { writeFile, unlink } = require("fs/promises");
async function test() {
const path = `tmpfile-${Math.random()}.png`;
await writeFile(path, Buffer.from("whatever"));
const rs = fs.createReadStream(path);
// it doesn't matter whether we call close()
rs.close();
await unlink(path);
}
test().then(() => console.log("DONE"));
Note the error is printed after "DONE" (means test() is resolved successfully...) |
This also appears to be an issue impacting readFileSync. I tried to create a stream from a file loaded by readFileSync but I get the same ENOENT error. |
Hi there, I'm trying mock-fs out. I might be misunderstanding, but it sounds like it creates an in-memory filesystem that can be written to as well as read from, right? Unfortunately, I seem to be getting an error when I write a file to the os tmpdir and then try to read it back via
createReadStream
. This works fine on the real filesystem.Here's a minimal repro, using mock-fs 5.1.0 and jest 27.2.1.
Here's the output I get:
Commenting out
const rs = createReadStream(path); rs.close();
causes the test to pass.The text was updated successfully, but these errors were encountered: