JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 899632
  • Score
    100M100P100Q172017F
  • License MIT

Convert objects into directory structures and back again

Package Exports

  • fixturify
  • fixturify/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fixturify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-fixturify

CI

Convert JSON objects into directory structures on the file system, and back again. This package is primarily useful for writing tests.

Installation

yarn add fixturify

Usage

const fixturify = require('fixturify')

const obj = {
  'foo.txt': 'foo.txt contents',
  'subdir': {
    'bar.txt': 'bar.txt contents'
  }
}

fixturify.writeSync('testdir', obj) // write it to disk

fixturify.readSync('testdir') // => deep-equals obj

fixturify.readSync('testdir', { globs: ['foo*'] }) // glob support
// => { foo.txt: 'foo.text contents' }

fixturify.readSync('testdir', { ignore: ['foo*'] }) // glob support
// => { subdir: { bar.txt: 'bar.text contents' } }

fixturify.writeSync('testDir', {
  'subdir': { 'bar.txt': null }
}) // remove subdir/bar.txt

fixturify.readSync('testdir') // => { foo.txt: 'foo.text contents' }

fixturify.writeSync('testDir', {
  'subdir': null
}) // remove subdir/
const fixturify = require('fixturify')

const obj = {
  'subdir': {
    'foo.txt': 'foo.txt contents'
  },
  'emptydir': {}
}

fixturify.writeSync('testdir', obj) // write it to disk

fixturify.readSync('testdir', { ignoreEmptyDirs: true })
// => { subdir: { foo.txt': 'foo.txt contents' } }

File contents are decoded and encoded with UTF-8.

fixture.readSync follows symlinks. It throws an error if it encounters a broken symlink.

Limitations

To keep the API simple, node-fixturify has the following limitations:

  • Reading or setting file stats (last-modified time, permissions, etc.) is not supported.

  • Creating symlinks is not supported. Symlinks are traversed when reading. Broken symlinks throw.

  • Special files like FIFOs, sockets, or devices are not supported.

  • File contents are automatically encoded/decoded into strings. Binary files are not supported.