[Solved] App and database reset after each test

What is the proper way to set the app and database in a clean state before each test (mocha it)?

For the web app, is Meteor.logout(...) sufficient? I am using puppeteer: is there a global state like LocalStorage that should be reset somehow?

For the database in particular, I am interested in removing all data, but keeping defined indexes. So I assume each collection needs a Collection.remove({}). What about Meteor-specific collections? What is the proper way to empty them? For instance, I need to remove all users. Is there a way to automate listing of all collections to simplify this reset routine?

PS: Just stumbled on GitHub - xolvio/cleaner: Gives you methods to clear your Mongo database and collections for testing purposes which seems to do the job for the database. Why does it exclude collection names which start with 'velocity'?

this meteor package could help you: GitHub - xolvio/cleaner: Gives you methods to clear your Mongo database and collections for testing purposes

Great! Why does it exclude collection names which start with 'velocity' ?

I have no idea. If you don’t have those collections then it’ll work just fine.

Thanks @minhna. I managed to achieve what I wanted by copying the logic in xolvio/cleaner:

  • Have a reset function that loops through collections and calls .remove({}) on each of them.
  • Have a Meteor.isTest/Meteor.isAppTest conditional to enable a client-side method to call this function.
1 Like

“velocity” was the name of a Meteor-focused testing initiative back in the day. The group, xolv.io, was one of the main proponents and is the author of the package you mention. The initiative petered out before coming to fruition, and the efforts were absorbed by Meteor core.

By ignoring collections with that prefix, I assume it was going to be like a reserved keyword for collections internal to their tool, meant to persist across a test suite.

2 Likes