Getting started with Karma
Karma is now the cornerstone of my testing workflow. Karma, formerly (for obvious reasons) Testacular, is a fantastic automated test runner that keeps my tests running and my sanity intact. Maintained by an Angular.js team member at Google, Karma provides great functionality out of the box and is easily extendable.
Here's what it looks like to run tests: Run
The catch is that you have to prepare a configuration file to set up the tests you want. The file is pretty straightforward: Run
karma init and it'll walk you through all the basics and generate a file based on your needs. First, you must decide what test framework you will use:
Karma itself is test-framework agnostic and relies on plug-ins to know how to deal with frameworks. Plug-ins are available for most of the frameworks you'll want to use, including Jasmine, Mocha, and QUnit. If you're not using one of those, check Npm (the official package manager for Node.js) for a Karma plug-in before you get too invested. If no plug-in for your testing framework exists, you can write your own plug-in or switch to a less esoteric framework.
The next chore is to configure your browsers. Karma will automatically launch all the browsers you specify, including Chrome, Firefox, IE, and Opera. Additionally, you can launch and run your test in a headless environment with PhantomJS or SlimerJS. Not enough for you? With a little extra configuration, you can get Karma to hook into BrowserStack or Sauce to run your tests on any browser they have available.