Skip to content

existsSync throws an error instead of returning false in Node 11 #256

@nzakas

Description

@nzakas

Environment Info:

$ node --version
v11.2.0
$ npm --version
6.4.1
$ nvm --version
0.33.11

MockFS version: 4.7.0

We recently found one test using mock-fs that fails consistently in Node.js v11:
https://travis-ci.org/eslint/eslint/jobs/456094527#L484

This occurs because existsSync ends up throwing an error instead of returning false (which it does consistently in other Node.js versions).

The test in question looks like this:

describe("checkPackageJson()", () => {
    after(() => {
        mockFs.restore();
    });

    it("should return true if package.json exists", () => {
        mockFs({
            "package.json": "{ \"file\": \"contents\" }"
        });

        assert.strictEqual(npmUtils.checkPackageJson(), true);
    });

    it("should return false if package.json does not exist", () => {
        mockFs({});
        assert.strictEqual(npmUtils.checkPackageJson(), false);
    });
});

The first test passes while the second one throws an error in Node.js 11 (Node.js 6, 8, and 10 all pass). npmUtils.checkPackageJson() calls fs.existsSync under the covers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions