Grunt to the Rescue
Not very challenging to do thanks to Grunt, but there are some important packages you will need.
Check out the example repository.
Our basic setup consists of the following packages in our package.json file:
- Phantomjs (Version 1.8.2-0 is required. At time of writing, there's a bug in version 1.9.x that will not allow us to run our jasmine tests through phantomjs.)
Once you have your package.json and Gruntfile.js in a directory, install the packages with the following command (in your project directory):
The specs are contained within the specs directory, following the server/client model:
The source files are located in the following directories:
Now we have Jasmine running our client-side specs, and we have Mocha (CLI) running our server-side specs. You can use Grunt watch to track your files for changes and re-run the tasks specified in the Gruntfile.js. The results of the tests will be displayed in terminal, and you could easily add notify too.
Grunt will watch your files for changes and rerun the tests with Watch.
To have Grunt watch your files for changes and rerun tests, in the project directory run the command:
Or you can run tests right away with the following:
Trial and Error
In the end, Mocha was good at server-side tests while Jasmine was good at client-side tests, so we thought, “why not use both?” Though using different testing frameworks felt a little strange to us at first, Grunt ran each test suite automatically (rather than running separate commands for each framework). It didn't cause us issues.