1.1.0 • Published 4 years ago

json-to-fixture v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

json-to-fixture

About

Use this library to load a directory of JSON files into an easy to use fixture object that you can reference in your code.

It's quite useful for generating test data.

Usage

Create a directory in your filesystem and fill it with *.json files, then call makeFixture() and pass it the path to your directory. makeFixture() will return an a Promise that resolves to an object with keys corresponding to the filenames in your fixture directory, and values initialized with the JSON contents of your json files.

Given the file structure:

+-- tests
  `-- fixtures
    `-- federationInfo.json (JSON object)
    `-- peopleList.json (JSON array)
import makeFixture from 'json-to-fixture';

const fixtureDirectoryPath = './tests/fixtures/';
makeFixture(fixtureDirectoryPath)
  .then(fx => {
    console.log('fx: %o', fx);
    // outputs:
    // {
    //   federationInfo: {...},
    //   peopleList: [...]
    // }
  });

Changelog

v1.1.0

  • Ignores subdirectories and non-json files. Any files that don't have the .json extension are silently skipped, as are all subdirectories.
1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-pre2

4 years ago

1.0.0-pre

4 years ago