tschaub / mock-fs

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

Renaming file to filename with trailing '/' should fail with "ENOENT: no such file or directory". #227

Open dienluong opened 6 years ago

dienluong commented 6 years ago

On MacOS, with the real fs where file test-data/bob.txt exists, the following rename fails :

> fs.renameSync('test-data/bob.txt', 'test-data/pete/');
Error: ENOENT: no such file or directory, rename 'test-data/bob.txt' -> 'test-data/pete/'
    at Object.fs.renameSync (fs.js:766:18)
    at repl:1:4
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:441:10)
    at emitOne (events.js:121:20)
    at REPLServer.emit (events.js:211:7)
    at REPLServer.Interface._onLine (readline.js:282:10)

But with mock-fs, it succeeds:

> let mockfs = require('mock-fs')
undefined
> mockfs({ 'test-data': { 'bob.txt': 'a text file' } })
undefined
> fs.renameSync('test-data/bob.txt', 'test-data/pete/');
undefined
> fs.readdirSync('test-data');
[ 'pete' ]

Thank you.

(On Windows, mock-fs is consistent with fs -- the rename would succeed with both.)