包详细信息

fixturify

joliss2.1mMIT3.0.0

Convert objects into directory structures and back again

自述文件

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.

更新日志

master

3.0.0

  • Drop unsupported Node versions to match node's LTS support policy

2.1.0

  • use walk-sync as the walking implementation for readSync
  • [DEPRECATED] options.include becomes options.globs to better match walk-sync
  • [DEPRECATED] options.exclude becomes options.ignore to better match walk-sync

2.0.0

  • Drop unsupported Node versions to match node's own support policy

1.3.0

  • Switch to GH Actions
  • Document DirJSON interface
  • Add more detail to symlinks docs

1.2.0

  • add ignoreEmptyDirs option
  • use files instead of npmignore

1.0.1

  • fix types, correctly expose Options and DirJSON

1.0.0

  • typescript
  • change node support to 6. || 8. || >= 10.*

0.3.4

  • Add include and exclude options to readSync

0.3.3

  • [BUGIFX] Ensure stat information is reset for each item in fixture when writing

0.3.2

  • Improve ergonomics: auto mkdirp when using fixtureify.writeSync(path, tree);

0.3.1

  • Fix README typo

0.3.0

  • Allow for overwriting and removing files and directories

0.2.0

  • Always follow symlinks

0.1.1

  • Fix bug due to missing var

0.1.0

  • Initial release