mockfs
MockFS - Mocking FS module implementation for testing purpouses.
Basic idea is to declare file system contents via JSON spec, mount it, and use through real fs.*
functions like an ordinary one.
/** * / * file-buffer * file-base64 * file-string * file-alt * dir/ * file-in-dir */var fs = MockFS = spec mfs fd; spec = time: 'Tue May 07 2013 17:09:57 GMT+0400' // global default time for any FS item, optional ctime: // creation time default, optional/*atime: ..., // atime and ctime is not set mtime: ...,*/ // value is taken from FS defaults (time) items: 'file-buffer': 'qwerty' // specify content as Buffer 'file-base64': 'cXdlcnR5' 'base64' // buffer with encoding 'file-string': 'qwerty' // or as string 'file-alt': // alternative syntax uid: 'johndoe' // owner user, as login name or id gid: 300 // owner group mode: 0766 // access mode atime: // Date instance mtime: 1000255364 // timestamp ctime: "-500" // number with a sign (+/-) - delta from fs default value content: 'asobject' // file content 'dir': // directory - always an object with items property (which is object too) atime: 'Tue May 07 2013 17:09:57 GMT+0400' // Date as string mtime: "+500" // stats, uid, gid, mode - on directories too /*ctime*/ // ctime is not set, value taken from FS defaults items: // directory contents 'file-in-dir': 'inside directory' ; mfs = spec;mfs; fs; // truefs; // "qwerty"fs; // file descriptors is also worksfs; mfs; fs; // false
Implemented by wrapping bundled fs
module's basic functions (file descriptors handling, stat, rename/delete files/directories).
So, functions as createReadStream
, appendFileSync
and so are supported "out of the box" without any wrapping.
Currently, NodeJS v0.8+ is supported.
TODO
- Support legacy interfaces
- Access rights check (read/write/search permissions)
- *chown(Sync), *chmod(Sync) functions
- Links support
- (un)watch(File) support
mirror
utility to create MockFS specs from real file systems- Integrate with some date parsing library for convinient atime/ctime/mtime specification
Roadmap
v0.2
- Access rights check (read/write/search permissions)
- *chown(Sync), *chmod(Sync) functions
v0.3
- Links support
- (un)watch(File) support
v1.0
- Support legacy interfaces
- Pass NodeJS test suite