Published on April 12, 2014 by Toran Billups
The first step is to install the npm module itself after adding it to the package.json file. We will also install the phantomjs module with npm so users who don't have phantom installed globally can still run the test suite.
Next we need to load the npm module at the top of our Gruntfile.js and add the testem task with a few options.
We also need to introduce a new concat task that knows how to build our assets for testing specifically. The biggest difference between dist/test concat is that we include the debug version of ember to include the test helpers, we pull in all the transpiled test code, and finally we add a test-loader at the very end to "require" or kick off the tests when testem throws them into phantomjs.
Now before we can fire up our new "grunt test" command to see it work, we need to add a simple unit test quick to verify it can/does execute the tests. Create a directory under js called "tests" and add a simple qunit test with any filename you want. I'm using example_tests.js below.
Now to verify it all works execute the new "grunt test" command and you should see a single test was run.
Now that our grunt build includes support for unit testing with testem, we can move onto deployment!
If you want to follow along on github, this repository has a commit for each part in the series
Note: I didn't spend much time showing how to unit/integration test as this topic was focused on how to setup testem + grunt. If you want to see an example like this with an integration test helper + unit tests that actually import a production module checkout my other project ember-grunt-example on github.