https://github.com/tomi77/node-bookshelf-fixture-loader
Bookshelf fixtures loader
https://github.com/tomi77/node-bookshelf-fixture-loader
bookshelf fixture-loading testing-tools
Last synced: 10 months ago
JSON representation
Bookshelf fixtures loader
- Host: GitHub
- URL: https://github.com/tomi77/node-bookshelf-fixture-loader
- Owner: tomi77
- License: mit
- Created: 2016-08-08T06:57:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-08T09:14:24.000Z (over 8 years ago)
- Last Synced: 2024-12-16T19:03:32.777Z (over 1 year ago)
- Topics: bookshelf, fixture-loading, testing-tools
- Language: CoffeeScript
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bookshelf-fixture-loader
Bookshelf fixtures loader
[](https://travis-ci.org/tomi77/node-bookshelf-fixture-loader)
[](https://coveralls.io/github/tomi77/node-bookshelf-fixture-loader?branch=master)
[](https://codeclimate.com/github/tomi77/node-bookshelf-fixture-loader)
[](https://david-dm.org/tomi77/node-bookshelf-fixture-loader)
[](https://david-dm.org/tomi77/node-bookshelf-fixture-loader?type=dev)
[](https://david-dm.org/tomi77/node-bookshelf-fixture-loader?type=peer)

## Installation
~~~bash
npm install bookshelf-fixture-loader --save-dev
~~~
## Usage
Fixture file format is inspired by Django fixture file format.
**fixtures/test.yaml**
~~~yaml
- id: 2
model: 'Test'
fields:
name: 'test 2'
~~~
**fixtures/test.json**
~~~json
[
{
"id": 1,
"model": "Test",
"fields": {
"name": "test 1"
}
}
]
~~~
In test file:
~~~js
var knex = require('knex')({
client: 'sqlite3',
connection: {
filename: ':memory:'
},
useNullAsDefault: true
});
var bookshelf = require('bookshelf')(knex);
bookshelf.plugin('registry');
var FixtureLoader = require('bookshelf-fixture-loader')(bookshelf, __dirname);
var fixtures = new FixtureLoader();
var Model = bookshelf.model('Test');
describe('FixtureLoader', function() {
it('should load json file', function() {
fixtures.load('test.json')
.insert()
.then(function() {
return Model.forge({id: 1}).fetch();
})
.then(function(row) {
row.get('name').should.equal('test 1');
});
});
});
~~~
or define absolute path:
~~~js
new FixtureLoader('/path/to/fixtures/test.yaml');
~~~