Yeoman Testing With Coffeescript

By Chris Rittersdorf on 28 Jun 2013

Matthew Seeley and I have been building an AngularJS app using Yeoman. So far it's been great! Yeoman gives you Grunt tasks, AngularJS generators, and Bower package management right out of the box. In addition, it gives you a base configuration for running Angular tests with Karma.

Unfortunately we ran into a situation that brought our productivity to a screeching halt. Our tests written in CoffeeScript were not executing. After a some investigation, we found found a solution to this problem.

Re-Configuring Karma

A configuration file is used to tell Karma how to execute the test suite:

./karma.conf.js

By default karma.conf.js has a section which describes the files that load for the test execution. It looks something like this:

With this configuration, the compiled CoffeeScript files were left out of our test suite. To fix this we modified this section to include the compiled javascript files in the .tmp directory:

During the grunt coffee task, our CoffeeScript files are compiled to JavaScript and placed into the .tmp directory. By adding the .tmp directories to our karma.config.js file, the test suite includes the files that we meant to test in the first place, and they all passed!