how to use laika testing framework for meteor on ubuntu 13.04


As a Meteor developer, I have the need to write test cases for my code. While Meteor does not have an official testing framework yet, Laika is an incredibly rich third-party framework for writing test cases both in the client and the server components of a Meteor project. It took me a while to understand how to install and configure Laika, especially because I am not a Node.js developer.

In this short post, I note down the required steps to make Laika work on Ubuntu 13.04. It is a future reference for myself, but I am sharing it here as somebody else may benefit from it.

With respect to Meteor, Laika requires a separate instance of MongoDB. Let’s install it quick and dirty to let our Ubuntu user have full write permissions on its data folder.

sudo apt-get install mongodb
sudo mkdir -p /data/db
sudo chown -R `whoami`:`whoami` /data

I was having issues with Ubuntu’s version of Node.js. Therefore, I installed Node Version Manager, an excellent script that lets us have different Node.js versions installed on the same system.

First, we install it with the following single line:

curl | sh

Then, we make sure that the file ~/.bashrc contains the following line at the end of it:

[[ -s /home/dgraziotin/.nvm/ ]] && . /home/dgraziotin/.nvm/ # This loads NVM

The script adds the same line in ~/.bashrc. However, it was not working for me.

Time to install and use the latest version of Node.js (v0.10.13 when this post was written). Node.js installation will include Node Package Manager, or npm, which is employed to download and install Laika and its dependency PhantomJS.

nvm install 0.10
nvm use 0.10

npm install phantomjs
npm install laika

For our convenience, we append this other line in ~/.bashrc, so that we can directly call Laika from the command line.

export PATH=~/node_modules/laika/bin:~/node_modules/phantomjs/bin:$PATH

That’s it. We are ready to run our first test suite. We open a second terminal (or another terminal tab) and start MongoDB as follows:

mongod --smallfiles --noprealloc --nojournal

Back to the original terminal (or tab), we change directory to the one holding the Meteor project. Then, we issue the command laika to start the tests.

nvm use 0.1.0
cd ~/path/to/project/root

Laika running 4 tests in Ubuntu. Laika running 4 tests in Ubuntu.

I used to stay in the tests/ folder while launching tests. This is how it usually works with other programming languages and unittests. However, this does not work with Laika. We have to stay in the root folder of the Meteor project when issuing the laika command.

It is worth noting that MongoDB is automatically started at each system reboot. There is no need to start it manually. However, there is the need to stop it in order to issue the command with the previously reported options. They are required to speed up the testing process.

I wrote this little tutorial as a reminder for the next time I need to setup a testing framework for a Meteor project. Hopefully, it will help other people there.

I do not use a commenting system anymore, but I would be glad to read your feedback. Feel free to contact me.