// src/nested/test.jsconst test = require('ava');const fixtures = require('fixturez');const f = fixtures(__dirname);test('finding a fixture', t => { let filePath = f.find('samples.txt'); // "/path/to/project/src/fixtures/samples.txt" // ...});test('copying a file', t => { let tmpPath = f.copy('data.json'); // // "/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018/data.json" // (from /path/to/project/src/nested/fixtures/samples.txt)
API
const fixtures = require('fixturez');
fixtures(dirname, opts)
Create fixture functions for the current file.
const f = fixtures(__dirname);
f.find(basename)
Find and return the path to a fixture by its basename (directory or filename
including file extension).
let dirname = f.find('directory');let filename = f.find('file.txt');f.find('file'); // Error, not found!
f.copy(basename)
Copy a fixture into a temporary directory by its basename.
let tempDir = f.copy('directory');let tempFile = f.copy('file.txt');
f.temp()
Create an empty temporary directory.
let tempDir = f.temp();
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 = fixtures(__dirname, { glob: 'mocks/*.json' });
opts.cleanup
Automatically cleanup temporary files created
Default: true
const f = fixtures(__dirname, { cleanup: false });
opts.root
Set the parent directory to stop searching for fixtures.
Default: "/"
const f = fixtures(__dirname, { root: 'path/to/project' });