Skip to content
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

Should readFileSync(), statSync() work? #385

Closed
ddziara opened this issue Feb 15, 2024 · 1 comment
Closed

Should readFileSync(), statSync() work? #385

ddziara opened this issue Feb 15, 2024 · 1 comment

Comments

@ddziara
Copy link

ddziara commented Feb 15, 2024

Hello,

node ver: v20.9.0

the following code crashes (no such file) for readFileSync(). statSync() has the same problem.

import mock from 'mock-fs';
// import fs from "fs";
import fs from "fs/promises";

describe("Dummy test", () => {
    beforeEach(() => {
        mock({
                '/index.md': '# Hello world!',
        });
    });

    afterEach(() => {
        mock.restore();
    });

/*    
    test("test1", () => {
        const buf = fs.readFileSync(`/index.md`);                        // no such file

        console.log(buf.toString());
    });

    test("test2", (done) => {
        fs.readFile(`/index.md`, (err, data) => {
            console.log(data.toString());
            done();
        });
    });
*/

    test("test3", async () => {
        const buf = await fs.readFile(`/index.md`)

        console.log(buf.toString());
    });
});

@tschaub
Copy link
Owner

tschaub commented Feb 20, 2024

I'll close this as a duplicate of #380. If it looks like something else to you, feel free to reopen. I see that #381 includes some work toward a solution.

@tschaub tschaub closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants