A Meteor package for setting the database to a consistent state in test.
1. Add this package to your application.
meteor add ryne:fixtures
2. Install mongo-tools on your system. This is probably bundled with the mongodb package in most distributions.
3. Add the functions to your server-only Meteor methods.
if (Meteor.isServer) {
typeof Fixtures !== 'undefined' && Meteor.methods(Fixtures);
}
Optional: Git ignore fixtures
You might not want to track database dumps for the sake of VCS performance.
echo 'tests/fixtures/' >> .gitignore
Once you have your database in the desired state:
meteor shell
> Fixtures.saveFixtures();
beforeEach(function(done) {
Meteor.call('loadFixtures', function() {
// Wait for aynchronous IO to complete before running test cases.
setTimeout(function() {
done();
}, 50);
});
});
Fixtures.saveFixtures({
*db*: (default: `<MONGO_URL database>`), a string name of the database to save,
*name*: (default: `'default'`), a string name of the fixtures
});
Fixtures.loadFixtures({
*db*: (default: `<MONGO_URL database>`), a string name of the database to load,
*name*: (default: `'default'`), a string name of the fixtures
});