fs-mock
Mock for fs module
Installation
$ npm install fs-mock
Usage
This module does not change original fs module in any way.
If you want to pass this module into other module, you will have to use for example rewire
package.
var FS = require('fs-mock');
var fs = new FS({
'var': {}, // empty directory
'var/www/index.php': '', // empty file in /var/www, so directory var is now not empty
'home/david/documents/school/projects': {},
'home': {
'david': {},
'john': {
'password.txt': 'my super password' // file
}
}
});
var myPassword = fs.readFileSync('/home/john/password.txt', {encoding: 'utf8'}); // my super password
If you write some path like this: home/david/documents/school/projects
, it will be automatically expanded and all its
parent directories will be also added to mocked file system.
Supported functions
There are also all *Sync methods.
Calling unsupported methods will throw an exception.
Fs object:
fs.rename()
: yesfs.ftruncate()
: yesfs.truncate()
: yesfs.chown()
: yesfs.fchown()
: yesfs.lchown()
: yesfs.chmod()
: yesfs.fchmod()
: yesfs.lchmod()
: yesfs.stat()
: yesfs.lstat()
: yesfs.fstat()
: yesfs.link()
: yesfs.symlink()
: yes (type argument is ignored)fs.readlink()
: yesfs.realpath()
: yesfs.unlink()
: yesfs.rmdir()
: yesfs.mkdir()
: yesfs.readdir()
: yesfs.close()
: yesfs.open()
: yesfs.utimes()
: yesfs.futimes()
: yesfs.write()
: yesfs.read()
: yesfs.readFile()
: yesfs.writeFile()
: yesfs.appendFile()
: yesfs.watchFile()
: no (use fs.watch())fs.unwatchFile()
: no (use fs.watch())fs.watch()
: yes (persistent option is ignored)fs.exists()
: yesfs.createReadStream()
: yesfs.createWriteStream()
: yes
Stats object:
dev
: noino
: nomode
: yesnlink
: nouid
: yesgid
: yesrdev
: nosize
: yesblksize
: yesblocks
: yesatime
: yesmtime
: yesctime
: yesisFile()
: yesisDirectory()
: yesisBlockDevice()
: noisCharacterDevice()
: noisSymbolicLink()
: yesisFIFO()
: noisSocket()
: no
Tests
$ npm test
Changelog
-
1.0.1
- Bug with root directories and readdir method
-
1.0.0