Last active
January 27, 2016 01:46
-
-
Save qnub/97d828f11c677007cb07 to your computer and use it in GitHub Desktop.
Meteor Jasmine client integration tests database reset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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