Create/copy directories to automatically cleaned up temporary directories via Mocha
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore Initial files via grunt-init Apr 13, 2014
.travis.yml Initial files via grunt-init Apr 13, 2014
CHANGELOG.md
Gruntfile.js Initial files via grunt-init Apr 13, 2014
README.md
UNLICENSE Initial files via grunt-init Apr 13, 2014
package.json

README.md

mocha-fixture-dir Build status

Create/copy directories to automatically cleaned up temporary directories via Mocha

More information on the repository can be found in fixture-dir's documentation.

Getting Started

Install the module with: npm install mocha-fixture-dir

// Generate our fixture utils
var exec = require('child_process').exec;
var FixtureDir = require('fixture-dir');
var mochaFixtureDir = require('mochaFixtureDir');
var fixtureUtils = mochaFixtureDir(FixtureDir);

// Generate a tmp namespace for our tests
fixtureUtils.init('my-node-module-tests');

// Copy over folder contents (`git-log`) to temporary directory (`/tmp/my-node-module-tests/git-log`)
// This also cleans up the directory on `after`
fixtureUtils.mkdir({
  folderName: 'git-log',
  copyFrom: __dirname + '/test-files/git-log' // Folder with `.git` activity
});
before(function (done) {
  // Run `git log` in our directory ()
  exec('git log', {cwd: this.dir.path}, function (err, stdout, stderr) {
    // Save our stdout and callback
    this.stdout = stdout;
    done(err);
  });
});

it('retrieved `git log` in our fixture directory', function () {
  assert(this.stdout);
});

Documentation

mocha-fixture-dir returns mochaFixtureDir as its module.exports.

mochaFixtureDir(FixtureDir)

Factory that wraps a FixtureDir instance with Mocha methods.

Returns:

  • fixtureUtils FixtureUtils, object with methods for creating/interacting with a FixtureDir in Mocha's before/after contexts

FixtureUtils

FixtureUtils#init(folderName)

Initialize the FixtureDir constructor inside of a before block. This must be run before any other FixtureUtils calls.

FixtureUtils#mkdir(options)

Runs FixtureDir#mkdir on the current FixtureDir instance inside a Mocha's before block. Additionally, it cleans up the directory via FixtureDir#destroy in an after block.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

Unlicense

As of Apr 13 2014, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.