fixturify

2019-01-14 admin

fixturify是什么

什么是fixturify,Convert objects into directory structures and back again

fixturify使用教程帮助文档

node-fixturify

Build Status Build status

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

Installation

npm install --save-dev fixturify

Usage

var fs = require('fs')
var fixturify = require('fixturify')

var 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', { include: ['foo*'] }) // glob support
// => { foo.txt: 'foo.text contents' }

fixturify.readSync('testdir', { exclude: ['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/

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.

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

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

你可能感兴趣的文章:

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-50928.html

文章标题:fixturify

回到顶部