fixturez
Easily create and maintain test fixtures in the file system
- Place fixtures in any parent directory
- Find them again in your tests by their name
- Searches up the file system to find a match
- Makes it easy to move fixtures around and share between tests
- Copy them into a temporary directory
- Automatically cleanup any temporary files created
Install
yarn add --dev fixturez
Example
/path/to/project/
/src/
/fixtures/
samples.txt
examples/...
/nested/
/fixtures/
data.json
test.js
// src/nested/test.jsconst test = ;const fixtures = ;const f = ; ; ; ;
API
const fixtures = ;
fixtures(dirname, opts)
Create fixture functions for the current file.
const f = ;
f.find(basename)
Find and return the path to a fixture by its basename
(directory or filename
including file extension).
let dirname = f;let filename = f;f; // Error, not found!
f.copy(basename)
Copy a fixture into a temporary directory by its basename
.
let tempDir = f;let tempFile = f;
f.temp()
Create an empty temporary directory.
let tempDir = f;
f.cleanup()
Deletes any temporary files you created. This will automatically be called when the Node process closes.
opts.glob
Which files to match against when searching up the file system.
Default: {fixtures,__fixtures__}/*
const f = ;
opts.cleanup
Automatically cleanup temporary files created
Default: true
const f = ;
opts.root
Set the parent directory to stop searching for fixtures.
Default: "/"
const f = ;