tschaub / mock-fs

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

glob and mocked directory with `/` not worked as expected #290

Open smmoosavi opened 4 years ago

smmoosavi commented 4 years ago

code:

mockFs({
      '/path-to-project/packages': {
        abc: { 'index.d.ts': '' },
        xyz: {},
        '@www/uuu': { 'index.d.ts': '' },
        '@aaa': {'bbb':{ 'index.d.ts': '' }},
      },
    });
glob.sync('*', { cwd: '/path-to-project/packages' }); // output: [ '@aaa', 'abc', 'xyz' ]

expected behavior

//  [ '@aaa', '@www', 'abc', 'xyz' ]

real behavior

//  [ '@aaa', 'abc', 'xyz' ]
3cp commented 4 years ago

From the lib/filesystem.js implementation, it looks like only first level keys /path-to-project/packages accepts nested folder string.

If you break the 2nd level key @www/uuu into '@www': { uuu: { 'index.d.ts': '' } },, it will work as expected.

Anyway, this feature should be relatively easy to implement on all levels of keys.