tschaub / mock-fs

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

Errors when using glob pattern `**` and mock-fs #263

Closed iamssen closed 4 years ago

iamssen commented 5 years ago
const mock = require('mock-fs');
const glob = require('glob');
const fs = require('fs');

// Real file test
console.log(fs.existsSync('sample/test1/package.json'));
console.log(fs.existsSync('sample/test1/package.json/package.json'));
console.log(glob.sync('sample/**/package.json'));

// mock-fs test
mock({
  sample: {
    'test1': {
      'package.json': ''
    },
    'test2': {
      'package.json': ''
    },
    '@test': {
      test3: {
        'package.json': ''
      },
      test4: {
        'package.json': ''
      },
    }
  }
});

console.log(fs.existsSync('sample/test1/package.json'));
console.log(fs.existsSync('sample/test1/package.json/package.json'));
console.log(glob.sync('sample/**/package.json'));
true
false
[ 'sample/@test/test3/package.json',
  'sample/@test/test4/package.json',
  'sample/test1/package.json',
  'sample/test2/package.json' ]
true
false
[ 'sample/@test/test3/package.json',
  'sample/@test/test3/package.json/package.json',
  'sample/@test/test4/package.json',
  'sample/@test/test4/package.json/package.json',
  'sample/test1/package.json',
  'sample/test1/package.json/package.json',
  'sample/test2/package.json',
  'sample/test2/package.json/package.json' ]

I get this result when I run the test code.

I am not sure whether this is a mock-fs problem or a glob problem.

laland commented 5 years ago

+1 any way to fix it?

3cp commented 4 years ago

It looks like this is fixed in latest v4.10.4. @iamssen pls close this issue if you can confirm.