tschaub / mock-fs

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

mockfs fs.readlink('missing') throws EINVAL when node throws ENOENT #231

Closed deployable closed 6 years ago

deployable commented 6 years ago

mock-fs readlink will throw an EINVAL error when the destination object is missing. Node (v8.9.4) will throw a ENOENT

fs-extra relies on this behaviour for file existence detection during a copy.

mkdir -p /tmp/mockfs
cd /tmp/mockfs
yarn add mock-fs fs-extra
mkdir adir
touch afile
ln -s afile alink
→ node
> let fs = require('fs')

> fs.readlinkSync('nope')
Error: ENOENT: no such file or directory, readlink 'nope'
    at Object.fs.readlinkSync (fs.js:967:18)
> let mockfs = require('mock-fs')

> mockfs({ 
...   'alink': mockfs.symlink({ path: 'afile' }),
...   'afile':'',
...   'adir':{},
... })

> fs.readlinkSync('nope')
Error: EINVAL, invalid argument 'nope'
    at Binding.<anonymous> (/private/tmp/mockfs/node_modules/mock-fs/lib/binding.js:1039:13)
    at maybeCallback (/private/tmp/mockfs/node_modules/mock-fs/lib/binding.js:42:17)
    at Binding.readlink (/private/tmp/mockfs/node_modules/mock-fs/lib/binding.js:1036:10)
    at Object.fs.readlinkSync (fs.js:967:18)