Skip to content

front-of-house/afix

Repository files navigation

afix

npm version test coverage npm bundle size

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) // 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.

License

MIT License © Sure Thing