Narnia's Psychedelic Mushrooms
Miss any of our Open RFC calls?Watch the recordings here! »

bookshelf-fixture-loader

0.3.3 • Public • Published

bookshelf-fixture-loader

Bookshelf fixtures loader

Build Status Coverage Status Code Climate dependencies Status devDependencies Status peerDependencies Status Downloads

Installation

npm install bookshelf-fixture-loader --save-dev

Usage

Fixture file format is inspired by Django fixture file format.

fixtures/test.yaml

id: 2
  model: 'Test'
  fields:
    name: 'test 2'

fixtures/test.json

[
  {
    "id": 1,
    "model": "Test",
    "fields": {
      "name": "test 1"
    }
  }
]

In test file:

var knex = require('knex')({
  client: 'sqlite3',
  connection: {
    filename: ':memory:'
  },
  useNullAsDefault: true
});
 
var bookshelf = require('bookshelf')(knex);
bookshelf.plugin('registry');
 
var BookshelfFixtureLoader = require('bookshelf-fixture-loader')(bookshelf, __dirname);
 
describe('BookshelfFixtureLoader', function() {
  it('should load json file', function() {
    BookshelfFixtureLoader('test.json');
 
    var Model = bookshelf.model('Test');
    Model.forge({id: 1}).fetch().then(function(row) {
      row.get('name').should.equal('test 1');
    });
  });
});

or define absolute path:

BookshelfFixtureLoader('/path/to/fixtures/test.yaml');

Install

npm i bookshelf-fixture-loader

DownloadsWeekly Downloads

3

Version

0.3.3

License

MIT

Last publish

Collaborators

  • avatar