Permalink
Fetching contributors…
Cannot retrieve contributors at this time
245 lines (149 sloc) 6.37 KB

node.js fs mixins for sinon-doublist

Source: lib/sinon-doublist-fs/index.js

module.exports()

Reference to sinonDoublistFs().

Go: TOC | module

sinonDoublistFs(test)

Init fs stubs.

Parameters:

  • {object | string} test Test context OR name of supported test runner
    • {object} Context object including sandbox from prior sinonDoublist() call
    • {string} Named runner will be configured to automatically set-up/tear-down.
    • Supported runners: 'mocha'

Go: TOC

mixin.getFileStub(name)

Retrieve an existing stub.

Parameters:

  • {string} name Absolute path of file/directory w/out trailing slash
    • Trailing slashes will be dropped.

Return:

{object} FileStub instance, or undefined if not found.

Go: TOC | mixin

mixin.stubFile(name)

Begin configuring a file stub.

Usage:

var stub = this.stubFile('/path/to/file');
stub
  .stat('size', 50)
  .stat('gid', 2000)
  .make();

If the test needs ancestor directories to be automatically created/stubbed, use mixin.stubTree instead.

Parameters:

  • {string} name Absolute path of file/directory w/out trailing slash

Return:

{object} this

Go: TOC | mixin

mixin.stubTree(paths)

Stub a file tree based on a sparse list of absolute paths.

Any missing ancestor directories will be created automatically.

Usage:

this.stubTree('/root/a/b2');
this.stubTree([
  '/root/a/b2',
  '/root/a2',
  '/root/a3/b4/c'
]);

Parameters:

  • {string | array} paths File/directory absolute paths
    • Use a trailing slash to indicate an empty directory.

Go: TOC | mixin

mixin.restoreFs()

Clean up resources not covered by sinonDoublist sandbox restoration.

Go: TOC | mixin

FileStub()

FileStub constructor.

An entry in the map of stubbed files/directories.

Usage:

var stub = new FileStub();
stub
  .set('name', '/path/to/file')
  .stat('size', 50)
  .stat('gid', 2000)
  .make();

Configuration:

  • {string} name Absolute path w/out trailing slash
    • Trailing slashes will be dropped.
  • {boolean|array} readdir Names of direct descendant files/directories
    • false will lead to isFile() returning true
  • {string} parentName Absolute path w/out trailing slash
  • {object} stats Attributes to be returned by stat*() and lstat*()
    • Initial values are from the fs.Stats manual entry.

Go: TOC

FileStub.prototype.buffer(buffer)

Set the buffer to be returned by fs.readFile*.

Parameters:

  • {string | object} buffer String or Buffer instance

Return:

{this}

Go: TOC | FileStub.prototype

FileStub.prototype.map(cb)

Supply all sub-dir file stubs, recursively, to the iterator.

Parameters:

  • {function} cb Iterator that receives the file stub

Go: TOC | FileStub.prototype

FileStub.prototype.copyTree(name)

Recursively copy all files stubs from the source tree, renaming them to reflect the new root directory.

Parameters:

  • {string} name New full path

See:

Go: TOC | FileStub.prototype

FileStub.prototype.readdir(paths)

Set fs.readdir* results.

Parameters:

  • {string | boolean | array} paths
    • false: revert to default isFile()=true
    • string: Relative path of one direct descendant
    • object array: FileStub objects whose make() has not yet been called
    • string array: Relative paths of direct descendants

Return:

{this}

Go: TOC | FileStub.prototype

FileStub.prototype.stat(key, val)

Set an fs.Stats property.

Parameters:

  • {string} key Ex. 'size' or 'gid'
  • {mixed} val

Return:

{this}

Go: TOC | FileStub.prototype

FileStub.prototype.make()

Finalize the fs.{exists,lstat,stat,etc.} stubs based on collected settings.

Return:

{object} this

Go: TOC | FileStub.prototype

FileStub.prototype.unlink()

Undo a prior make().

Go: TOC | FileStub.prototype

FileStub.prototype.unlinkReaddir()

Unlink stub's readdir list.

Go: TOC | FileStub.prototype

—generated by apidox