Registry / testing / fixturez

fixturez

JSON →
library1.1.0jsnpmunverified

Easily create and maintain test fixtures in the file system. Version 1.1.0 is the latest stable release. It allows placing fixtures in any parent directory, finding them by name via upward search, copying into temporary directories, and auto-cleanup on process exit. Differentiators: supports multiple test frameworks (Jest, AVA, Mocha), fixture sharing between tests, and customizable glob patterns to locate fixture directories.

npm install fixturez
INSTALL
IMPORT
SIG · FIXTUREZ
F
fixturez
testingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fixturez
import fixturez from 'fixturez'
const { fixturez } = require('fixturez')
Default export; named export is not available.
fixturez
const fixtures = require('fixturez')
const fixtures = require('fixturez').default
CommonJS require returns the default export directly.
fixturez
const f = fixtures(__dirname)
const f = new fixtures(__dirname)
fixturez is a function, not a class; do not use 'new'.

Shows how to create fixture functions using require, find, copy, temp, and cleanup methods.

const test = require('ava'); const fixtures = require('fixturez'); const f = fixtures(__dirname, { root: __dirname }); test('find fixture', t => { const filePath = f.find('sample.txt'); t.truthy(filePath); }); test('copy fixture', t => { const tmpDir = f.copy('sample'); t.truthy(tmpDir); f.cleanup(); }); test('temp directory', t => { const tmpDir = f.temp(); t.truthy(tmpDir); f.cleanup(); });
Debug
Known issues
gotchafixturez searches up the directory tree from __dirname; if no fixture directory is found, it will throw an error.
fix
Ensure a 'fixtures' or '__fixtures__' directory exists in a parent directory, or set 'root' option.
affects: >=1.0.0
deprecatedOptions 'glob' and 'root' may be removed in future versions.
fix
Use the current options as documented; future API might change.
affects: >=1.0.0
gotchaThe 'copy' method copies the fixture into a new temporary directory each invocation; the path changes each time.
fix
Call f.find() if you only need the original path without copying.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Could not find fixture "file"
f.find('file') called but the fixture name must include the file extension.
fix
Use f.find('file.txt') with the full basename including extension.
TypeError: fixtures is not a function
Importing fixturez incorrectly using destructuring or as a class.
fix
Use default import: const fixtures = require('fixturez'); or import fixtures from 'fixturez';
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fixturez — npm install fixturez · libregistry