fs-test-fixtures
v0.2.0-next
Published
Helper for writing filesystem fixtures
Downloads
5
Maintainers
Readme
fs-test-fixtures
Helper for writing filesystem fixtures
$ npm i fs-test-fixtures
Example usage in mocha
tests:
'use strict'
const { suite, test, before } = require('mocha')
const path = require('path')
const fs = require('fs').promise
const fixtures = require('fs-test-fixtures')
suite('some package tests', () => {
let fix
before(() => {
// Setup our fixtures instance with a directory structure like:
// test/
// - index.js
// - tmp/
// - fixtures/
// - example/
// - package.json
fix = fixtures({
fixtures: path.join(__dirname, 'fixtures'),
tmp: path.join(__dirname, 'tmp')
})
})
test('test some things which require filesystem mocks', async () => {
// Copy the contens of fixtures/example to tmp
await fix.setup('example')
// Do your tests
assert.strictEqual(await fs.access(path.join(fix.TMP, 'package.json'), true)
// Teardown (optional, because each call to `.setup`
// will teardown first to ensure a clean state)
// await fix.teardown()
})
})