Testing is an important part of a project. While developing Emily I had to set up an environment that would automate testing for several cases.
As I followed a full TDD process for developing Emily, I needed a way to get instant tests results. But Emily is designed to be executed in a browser, as well as in a node.js environment, and I wanted to pass the same tests for both.
So I started to look for a testing framework that would run in any JavaScript runtime and Jasmine appeared to be the perfect fit. It doesn’t rely on the DOM and it has the right documentation and tools for a quick and easy setup.
I npm installed an adapter for running the tests under node.js, managed to find a reporter for readable tests results in the shell and automated the task in my build process.
Everything went pretty well until I got stuck with running the specs with jsTestDriver when my modules under tests are loaded with require.js. JsTestDriver is needed for testing Emily’s modules in browsers.
I found a solution, thanks to two things:
Then I was able to run the same specs regardless of the environment.
The final step was to make the specs available for anyone to run. The goal here is to allow for developers to test Emily into their target environments by sharing a public HTML page that runs Jasmine against the built framework.
I’ve created a repository on github to showcase the whole solution. There’s a walkthrough in the wiki for reproducing the steps. Please feel free to comment and/or fork to improve the environment.
Here’s the link: https://github.com/podefr/jasmine-reqjs-jstd
And you, how do you test your code?