tschaub / mock-fs

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

Can't find directory when using templated strings for mocking directories #255

Closed circa10a closed 6 years ago

circa10a commented 6 years ago
const inputs = `${os.homedir()}/inputs`;

mock({
    inputs: {
      reports: {},
      logs: {
        'console.log': 'test',
      },
    },
  });

console.log(fs.readdirSync(`${os.homedir()}/annt-inputs`));

Results in:

Error: ENOENT, no such file or directory '/Users/me/inputs'

However, this works fine when using full paths, but this is not a great solution when tests run on different machines and I do have a hard requirement of needing to use the home directory. Dumb, I know, but beyond my control for many reasons.

circa10a commented 6 years ago

Workaround:

mock({
    [inputs]: {
      reports: {},
      logs: {
        'console.log': 'test',
      },
    },
  });