Tiny fixture utility.
npm i afix
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) // true
fs.existsSync(fixture.files.config.path) // true
assert.equal(fs.readFileSync(fixture.files.config.path, 'utf8'), fixture.files.config.content)
fs.existsSync(fixture.files.nested.path) // true
assert.equal(fs.readFileSync(fixture.files.nested.path, 'utf8'), fixture.files.nested.content)
fs.existsSync(dir) // true
// remove fixture.root
fixture.cleanup()
fs.existsSync(fixture.root) // false
Plus, fixtures are automaticaly removed when the process exits.
MIT License © Sure Thing