I been doing research recently on test driven development practices and tools for developing web applications with Meteor platform. While there is no official TDD approach, at least at the moment of writing, I was able to find several techniques contributed by growing community.
meteor-mocha-web allows you to easily and safely run mocha tests within the Meteor framework. This means you can write tests that use and examine Meteor collections.
And if you already familiar with the Mocha you’ll be able to start TDD in no time. The process fairly the same as you usually do on node and the browser.
Tip 1: Custom database name for tests
As you might be noticed the mocha-web examples running on the same database as your development instance of Meteor, so, the same database name is used for the development and testing, but this is not always useful especially as your project grow. At some point you might need to reset your test database while keep development data untouched.
Here is quick workaround on using different database name for testing:
Firstly, run development instance as usually:
And then, in a different terminal, run another instance of Meteor like this:
METEOR_MOCHA_TEST_DIR=tests MONGO_URL='mongodb://127.0.0.1:3002/meteor_test' mrt -p 8000
As you can see, with this instance we’re connecting to the mongodb bootstraped by the first instance, this way we can use the same mongodb server, but with a different database names for testing and development purposes;
Finally, tests will be available on
http://localhost:8000, so, open it in a browser or use with PhantomJS for tests execution.
NOTE: mrt is a shortcut for the Meteorite which is version manager and package manager for Meteor, which is required for those samples to work.
Tip 2: Continuous feedback with Grunt
Also, it would be nice to add Growl notifications as well as run tests on modified files only. I didn’t looked how well Grunt works with Growl, but there seems still a problems to trigger change event on individual files.