tschaub / mock-fs

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

Question: Is it possible to view the contents of the mock file system? #314

Open hubol opened 3 years ago

hubol commented 3 years ago

I want to see the contents of the mock file system to determine why a test of fs.existsSync is failing. It would be nice if I could somehow explore the structure of the file system in my debugger. The getMockRoot() method looks interesting but I'm not sure it's what I need.

Thanks :-)

felinto-dev commented 3 years ago

I'm looking for that too. I tried using fs.readdirsync but to no avail.

andorfermichael commented 3 years ago

yes that would be a great feature

charleshimmer commented 3 years ago

fs.existsSync and fs.readFileSync are working as expected for me. Although a way to dump the mock-fs filesystem object in console.log would be handy.

felinto-dev commented 3 years ago

fs.existsSync and fs.readFileSync are working as expected for me. Although a way to dump the mock-fs filesystem object in console.log would be handy.

Try it:

import { Console } from 'console';

  beforeEach(async () => {
    global.console = new Console(process.stdout, process.stderr);
    mockFs();
  });
jamesmontalvo3 commented 2 years ago

Getting the contents of the mock file system: JSON.stringify(mockFS.getMockRoot(), null, 2)