Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Fixtures

For quickly adding data to a node project. Ideal for mock or testing data. Fixtures serve up json files as a data source.

Requires Nodejs http://nodejs.org

Installing

From the Command Line
npm install git+https://github.com/bdunford/fixtures.git

package.json as a dependency
add "fixtures": "git+https://github.com/bdunford/fixtures.git" to dependencies

{
    "name": "your-app",
    "version": "0.0.0",
    "private": true,
    "description": "just another node app",
    "dependencies": {
        "helpers": "git+https://github.com/bdunford/fixtures.git"
    }
}

Raw
git clone https://github.com/bdunford/fixtures
Be sure to run npm install from with in the fixtures directory

Usage

Require fixtures in your javascript

var fixtures = require('fixtures');

Methods

store returns an instance of Store for the matching JSON file found with in the fixtures directory If you had the following JSON file in your directory fixtures/cusomters.json

    fixtures.store('customers'); //will return
    {
        file: 'fixtures/customers.json',
        all: [Function],
        find: [Function]
    }

stores returns an object containing all of the stores (JSON files) found with in the fixtures folder in you project. If you had the following JSON files in your directory fixtures/cusomters.json and fixtures/orders.json

    fixtures.stores(); //will return
    {
        customers: {
            file: 'fixtures/customers.json',
            all: [Function],
            find: [Function] },
        orders: {
            file: 'spec/fixtures/orders.json',
            all: [Function],
            find: [Function] }
        }
    }

Store.all returns the contents of the JSON file parsed to an object or array of objects for that store. If you had the following JSON file in your directory fixtures/cusomters.json

    fixtures.store('customers').all();
    //will return the content of "fixtures/cusomters.json" parsed to an array of objects

Store.find returns the contents of the JSON file matching the filter object passed to in you had the following JSON file in your directory fixtures/cusomters.json

   fixtures.store("customers").find({lastName: "smith"});
//will return the content of "fixtures/cusomters.json" parsed to an array where the customers had a lastName of smith.

Properties

location can be set on fixtures to control the location of the JSON files. The default location is fixtures/

fixtures.location = "./db/fixtures";
//would make fixtures look for JSON files in db/fixtures/ instead of fixtures/

About

JSON file based store for quickly adding data to a node project

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages