fixtures-fs
Create a temporary fs with JSON fixtures
Example
var withFixtures = ;var test = ;var path = ; var myNpmVerify = ... /* this test wants a directory set up with some mock data then do asserts against the directory with some code. withFixtures creates the file system before your test and tears it down after your test is done.*/;
example with mocha
var withFixtures = ;var suite = suite;var test = it;var assert = ;var path = ; var myNpmVerify = ... ;
Docs
var func = withFixtures(dirname, fixtures, lambda, opts={})
fixtures-fs := ( dirname: String, fixtures: Fixture, lambda: (EndCallback<T>) => void, opts?: FsMock) => (EndCallback<T>) => void
withFixtures
takes a dirname
, an object of fixtures
and an async lambda
function
It will run create a file system matching your fixtures
before calling your async lambda
function and tear down
the file system once the lambda
finishes.
You can invoke the returned func
with a callback or an object
with an .end()
method.
dirname
This is the directory the fixtures
will be written into.
If this directory does not exist, it will be created.
fixtures
fixtures := Object<String, String | Fixture>
The fixtures
object has key value pairs where the key is the
directory or file name and the value is either a string content
of the file or another object that is the content of a directory
lambda
lambda := (Callback<Error, T> | Object & { end: Callback<Error, T>}) => void
The lambda
should be an async function that takes either a
callback or an object with an .end(err=null)
method. This
callback / .end()
method is intercepted and withFixtures
will cleanup the file system before it completes.
opts
opts := { fs: Object, mkdirp: Function, rimraf: Function }
You can pass an optional opts
object to customize the file
system functions that withFixtures
uses. This is useful if
you want to withFixtures
to write to a non-standard file
system like a browser file system, a remote file system or
an in memory file system.
func
The func
result of the withFixtures()
call can be passed
directly into the test()
function of tape
or the test()
function of mocha
.
When you call func
with either a callback or object with an
.end()
method argument it will create the fixtures, invoke
the lambda
, tear down the fixtures and then invoke either
the callback or .end()
method.
Installation
npm install fixtures-fs
Tests
npm test
Contributors
- Raynos