Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ojhaujjwal/mongoose-fixtures
Mongoose Data Fixtures
https://github.com/ojhaujjwal/mongoose-fixtures
Last synced: 17 days ago
JSON representation
Mongoose Data Fixtures
- Host: GitHub
- URL: https://github.com/ojhaujjwal/mongoose-fixtures
- Owner: ojhaujjwal
- License: mit
- Created: 2015-11-03T02:21:49.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-07T10:42:31.000Z (over 8 years ago)
- Last Synced: 2023-12-23T18:02:07.843Z (11 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mongoose-fixtures
===================
[![Build Status](https://api.travis-ci.org/ojhaujjwal/mongoose-fixtures.svg)](https://travis-ci.org/ojhaujjwal/mongoose-fixtures)This library aims to provide a simple way to manage and execute the loading of data fixtures for the [mongoose](https://github.com/Automattic/mongoose). Here is a simple example of a fixture:
```js
// fixtures/user-fixture.js
module.exports = function(conn, references) {
User = conn.model('User');
var user = new User({...})
return user.save();
};
```A fixture is any callback which returns a promise. The promise should be resolved when all the fixtures data are loaded to the database.
Then you need to add fixtures to a loader instance:
```js
var loader = require('mongoose-fixtures').loader();
loader.load(require('fixtures/user-fixture'));
```You can load a set of fixtures from a directory as well:
```js
var path = require('path');loader.loadFromDirectory(path.resolve(__dirname, './fixtures'));
```Then you can execute the fixtures:
```js
var mongoose = require('mongoose'),
executor = require('mongoose-fixtures').executor(mongoose);
executor.execute(loader);
```## Running the tests
* clone the repo and go to the root directory of the repo
* npm install
* npm test