afix
Tiny fixture utility.
npm i afix
Usage
Each call to afix()
creates a new directory in process.cwd()
and writes
files within the new directory.
import fs from 'fs'
import { afix } from 'afix'
const fixture = afix({
config: ['config.js', 'export default { foo: true }'],
nested: ['some/path/file.js'],
})
const dir = fixture.mkdir('/some/dir')
fs.existsSync(fixture.root)
fs.existsSync(fixture.files.config.path)
assert.equal(fs.readFileSync(fixture.files.config.path, 'utf8'), fixture.files.config.content)
fs.existsSync(fixture.files.nested.path)
assert.equal(fs.readFileSync(fixture.files.nested.path, 'utf8'), fixture.files.nested.content)
fs.existsSync(dir)
fixture.cleanup()
fs.existsSync(fixture.root)
Plus, fixtures are automaticaly removed when the process exits.
License
MIT License © Sure Thing