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

EBADF reading directory with readFileSync() #285

Closed
mattdeluco opened this issue Dec 28, 2019 · 2 comments · Fixed by #286
Closed

EBADF reading directory with readFileSync() #285

mattdeluco opened this issue Dec 28, 2019 · 2 comments · Fixed by #286
Assignees

Comments

@mattdeluco
Copy link

The attached mocha test will fail with Error: EBADF: bad file descriptor, read.

While searching the issues I noticed some relating to graceful-fs - while it's technically in my node_modules dependency tree, I don't believe it's loaded during the test. I think it's only used for the vscode eslint extension.

This is on macOS 10.15.2, Node 12.14.0, mock-fs 4.10.4.

const assert = require('assert'),
  fs = require('fs'),
  mockFS = require('mock-fs');

describe('Test Suite', () => {
  before(() => {
    mockFS({
      root: {}
    });
  });

  after(() => {
    mockFS.restore();
  });

  it('should mock the file system', () => {
    let foo = fs.readFileSync('root');
  });
});
@mattdeluco
Copy link
Author

mattdeluco commented Dec 28, 2019

Sorry, reading through the NodeJS API docs for fs I noticed that readFile() should return an error if the file is a directory. Which is odd, because I've got code that seems to work when I use readFileSync() to loop over directory contents (which is why I posted here before checking the Node API.)

@3cp 3cp self-assigned this Dec 28, 2019
@3cp
Copy link
Collaborator

3cp commented Dec 28, 2019

There is still a small mismatch, Nodejs fails EISDIR not EBADF when reading dir, at least for nodejs v12. I will follow up.

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

Successfully merging a pull request may close this issue.

2 participants