Jul 17, 2013

How to use Laika testing framework for Meteor on Ubuntu 13.04

Laika running 4 tests in Ubuntu.

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.

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:

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

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.

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

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:

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.

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.

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.

Leave a comment