sinon-doublist-fs
node.js fs
mixins for sinon-doublist: stubFile()
, stubTree()
Examples
All
sinon
sandboxes except fake timers will be created by the both mixin approaches below. (sinon docs)
Mixin with auto-sandboxing (recommended)
;; ;
Mixin w/ manual sandboxing
;
Fake a large file
;
Fake a file tree with leaf attributes
/** * /root/a * /root/a/b * /root/a/b2 * /root/a2 * /root/a3 * /root/a3/b4 * /root/a3/b4/c */this;
Fake a file tree from a sparse path list
Creates the same hierarchy as the
stubFile()
example above. However, ancestor directories are stubbed automatically.
this;
fs
coverage
File stubs created by stubFile() / stubTree()
, and configured via .stat()
and others, will be reflected/modifiable by:
fs.writeFile*
fs.readFile*
- Writes can also be faked via FileStub#buffer().
fs.exists*
fs.readdir*
fs.stat* / fs.lstat*
- Including
isFile() / isDirectory()
responses
- Including
fs.unlink*
fs.renameSync
If a file stub does not exist for a given path, we fallback to the real fs
method. To override this behavior:
sinonDoublistFs.realFsFallback = 0
- Do nothing (async methods will hang).
sinonDoublistFs.realFsFallback = 2
- Throw an
Error
, ex.existsSync, no such file stub '/path/to/file'
- Throw an
co-fs compatibility
co-fs
wrappers just need to be added after sinon-doublist-fs
stubbing. See test/lib/co-fs.js.
Installation
NPM
npm install sinon-doublist-fs
API
License
MIT
Tests
npm test