tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
906 stars 86 forks source link

File descriptor issues with Mocha in ElementaryOS #27

Open josiah14 opened 9 years ago

josiah14 commented 9 years ago

It seems mock-fs can't create the mock filesystem correctly in ElementaryOS??? This code works fine on OSX.

Mocha and Chai.expect are being used, here.

The test:

  /*
   * ::getFtpFileList
   */
  describe('::getFtpFileList', function () {
    var mockfs = require('mock-fs'),
        fs = require('fs');

    describe('When the directory contains only files', function () {
      before(function () {
        mockfs({
            'test': {
              'file.txt': 'contents',
              'file1.ext': ''
            }
        });
      });

      after(function () {
        mockfs.restore();
      });

      it('Injects a String Array of all the files with their full paths', function () {
        functions.getFtpFileList('test', function (err, files) {
          expect(files).to.deep.equal([
            'test/file.txt',
            'test/file1.ext'
          ]);

          expect(err).to.equal(null);
        });
      });
    });

The error

 6 passing (86ms)
  1 failing

  1) For module functions ::getFtpFileList When the directory contains only files "before all" hook:
     Uncaught Error: EBADF, bad file descriptor
    at Binding._getDescriptorById (/project_dir/node_modules/mock-fs/lib/binding.js:189:11)
    at Binding.<anonymous> (/project_dir/node_modules/mock-fs/lib/binding.js:375:27)
    at maybeCallback (/project_dir/node_modules/mock-fs/lib/binding.js:27:18)
    at Binding.writeBuffer (/project_dir/node_modules/mock-fs/lib/binding.js:374:10)
    at Object.fs.write (/project_dir/node_modules/mock-fs/node/fs-0.10.28.js:513:11)
    at WriteStream._write (/project_dir/node_modules/mock-fs/node/fs-0.10.28.js:1677:6)
    at doWrite (_stream_writable.js:226:10)
    at clearBuffer (_stream_writable.js:305:5)
    at onwrite (_stream_writable.js:263:7)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at /project_dir/node_modules/mock-fs/node/fs-0.10.28.js:1683:5
    at Object.wrapper [as oncomplete] (/project_dir/node_modules/mock-fs/node/fs-0.10.28.js:510:5)
Slayer95 commented 8 years ago

I am seeing this error at fs.write in one setup of Windows 7. Also a similar EBADF error in a Windows 8 setup, though from fs.close.

MiniXC commented 8 years ago

Also having this problem when using fs.readFileSync on Linux.

     Error: EBADF, bad file descriptor
      at Binding.<anonymous> (node_modules/mock-fs/lib/binding.js:343:13)
      at maybeCallback (node_modules/mock-fs/lib/binding.js:41:17)
      at Binding.read (node_modules/mock-fs/lib/binding.js:335:10)
      at Object.fs.readSync (node_modules/mock-fs/node/fs-6.0.0.js:651:19)
      at Object.fs.readFileSync (node_modules/mock-fs/node/fs-6.0.0.js:472:24)
mrchief commented 7 years ago

On Windows 7, I'm getting EBADF too. Just calling mock() throws this error. Also, mock({'path/to/dir': {}}) throws same error.

cco3 commented 5 years ago

What node versions are you all running? I get this on 10, but not on 8.