Detalhes do pacote

sinon-doublist-fs

codeactual58MITdepreciado0.5.1

No longer maintained.

node.js fs mixins for sinon-doublist

sinon, test, mixin, unit

readme (leia-me)

sinon-doublist-fs

node.js fs mixins for sinon-doublist: stubFile(), stubTree()

Build Status

Examples

All sinon sandboxes except fake timers will be created by the both mixin approaches below. (sinon docs)

Mixin with auto-sandboxing (recommended)

sinonDoublist(sinon, 'mocha');
sinonDoublistFs('mocha');

describe('myFunction', function() {
  it('should do something', function() {
    // this.stubFile()
    // this.stubTree()
  });
});

Mixin w/ manual sandboxing

describe('myFunction', function() {
  beforeEach(function() {
    sinonDoublist(sinon, this);
    sinonDoublistFs(this);
  });

  afterEach(function() {
    this.sandbox.restore();
  });

  it('should do something', function() {
    // this.spyFile()
    // this.stubTree()
  });
});

Fake a large file

describe('#validate()', function() {
 it('should detect file that is too large', function() {
    var filename = '/path/to/file';
    this.stubFile(filename).stat('size', 1024 * 1024 * 1024).make();
    var myLib = new MyLib(filename);
    myLib.validate().should.equal(false);
  });
});

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.stubFile('/root').readdir([
  this.stubFile('/root/a').readdir([
    this.stubFile('/root/a/b').size(100),
    this.stubFile('/root/a/b2').size(50)
  ]),
  this.stubFile('/root/a2').size(10),
  this.stubFile('/root/a3').readdir([
    this.stubFile('/root/a3/b4').readdir([
      this.stubFile('/root/a3/b4/c').size(20)
    ])
  ])
]).make();

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.stubTree([
  '/root/a/b2',
  '/root/a2',
  '/root/a3/b4/c'
]);

fs coverage

File stubs created by stubFile() / stubTree(), and configured via .stat() and others, will be reflected/modifiable by:

  • fs.writeFile*
  • fs.readFile*
  • fs.exists*
  • fs.readdir*
  • fs.stat* / fs.lstat*
    • Including isFile() / isDirectory() responses
  • 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'

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

Documentation

License

MIT

Tests

npm test

changelog (log de mudanças)

0.5.1

  • fix(fsFallback): Undefined due to typo

0.5.0

  • fix(sinon-doublist): Upgrade peer dependency to 0.5.0 to no longer use fake timers by default
  • chore(pkg): Upgrade outdated dependencies

0.4.7

  • fix(FileStub#readdir): Convert string input to array
  • chore(npm): Upgrade outdated dependencies

0.4.6

  • chore(deps): Upgrade sinon-doublist peer dependency to 0.4.2

0.4.5

  • fix(writeFile): Detect options argument

0.4.4

  • fix(fs wrappers): Wrap all callbacks w/ setImmediate
  • chore(deps): Update NPM dev dependencies

0.4.3

  • fix(fs stub, readdir): Pass ENOTDIR to callback, instead of throwing, to match fs

0.4.2

  • feat(FileStub#readdir): Accept a string argument for single-descendant case
  • fix(fs stub): Support trailing slashes in exists*, renameSync, unlink*, readdir*, lstat*, stat*

0.4.1

  • feat(FileStub#stubFile): Detect empty dir names based on trailing slash
  • fix(FileStub): Drop trailing slash during stub create/seek
  • fix(FileStub#readdir): Remove extra leading slash from stub keys for top-level paths

0.4.0

  • Add unlink*() wrappers
  • By default, fallback on real fs methods if file stub not found.
  • By default, set stub size/blocks values to 0.
  • Fix:
    • parentName updating
    • fs.Stats copying during renameSync()
    • readdir*() payload after renameSync()

0.3.1

  • chore(npm): Upgrade outdated dependencies

0.3.0

  • Upgrade sinon-doublist peer dependency to ~0.4.0 (sinon ~1.7.2).
  • Rely on sinon-doublist to enforce sinon peer dependency.

0.2.3

  • Upgrade sinon-doublist, long-con, apidox.

0.2.2

  • Add missing fs.lstat* responses for each FileStub. Fix incompatibility with shelljs-0.1.3.

0.2.1

  • Remove NPM shrinkwrapping.

0.2.0

  • Add stubTree mixin.
  • Remove requirement that fs must be passed to sinonDoublistFs().
  • Add fs.renameSync stub.
  • Add FileStub#unlink.
  • Fix NPM compatibility.

0.1.2

  • Support file tree building by passing an array of stubFile() chains to .readdir().
  • Upgrade codeactual/sinon-doublist to 0.2.3.

0.1.1

  • Upgrade codeactual/sinon-doublist to 0.2.2.

0.1.0

  • Add stubFile mixin.