Skip to content

Instantly share code, notes, and snippets.

@qnub
Last active January 27, 2016 01:46
Show Gist options
  • Save qnub/97d828f11c677007cb07 to your computer and use it in GitHub Desktop.
Save qnub/97d828f11c677007cb07 to your computer and use it in GitHub Desktop.
Meteor Jasmine client integration tests database reset
if (process.env.IS_MIRROR) {
Meteor.methods({
'loadFixtures': function(){
console.log('Loading default fixtures');
// TODO: add your fixtures here
Accounts.createUser({
email: '[email protected]',
password: '123456'
});
console.log('Finished loading default fixtures');
},
'clearDB': function(){
console.log('Clear DB');
var collectionsRemoved = 0;
var db = Meteor.users.find()._mongo.db;
db.collections(function (err, collections) {
var appCollections = _.reject(collections, function (col) {
return col.collectionName.indexOf('velocity') === 0 ||
col.collectionName === 'system.indexes';
});
_.each(appCollections, function (appCollection) {
appCollection.remove(function (e) {
if (e) {
console.error('Failed removing collection', e);
fut.return('fail: ' + e);
}
collectionsRemoved++;
console.log('Removed collection');
if (appCollections.length === collectionsRemoved) {
console.log('Finished resetting database');
}
});
});
});
console.log('Finished clearing');
}
});
}
@jimmiebtlr
Copy link

Where do you put this file? I have mine in test/jasmine/server/integration/fixtures.js, but the Meteor.call in the client integration's are returning method not found.

@leogodin217
Copy link

jimmiebtlr -You put it under the /server folder. You are creating a method on the server that the tests can use. It will not work inside the test client suite.

@takahser
Copy link

@legodin217 how do u create a method on the server which is visible/callable at the client side? could you give us an example? thank you

update

it's all well documented here: https://meteor-testing.readme.io/docs/jasmine-database-fixtures-for-integration-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment