fs-test-fixtures

0.2.0-next • Public • Published

fs-test-fixtures

NPM Version NPM Downloads Build Status js-standard-style

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()
  })
})

Package Sidebar

Install

npm i fs-test-fixtures

Weekly Downloads

9

Version

0.2.0-next

License

ISC

Unpacked Size

6.32 kB

Total Files

5

Last publish

Collaborators

  • wesleytodd