- Version 10.0.1
- Project Flyweb Production
- Section blog
There are many KarmaJS config files, but this is my config file
To develop an Angular project with an Test-driven development (TDD) approach, using a software like KarmaJS is essential. My Angular project uses RequireJS to load, so Karma needs to be loaded with RequireJS too.
Install Karma and some plugins via Node:
# Install Karma:
$ npm install karma --save-dev
# Install plugins that your project needs:
$ npm install karma-jasmine karma-chrome-launcher --save-dev
This Karma plugin is a Adapter for the RequireJS framework - there is a very good documentation link on the gitub page - https://github.com/karma-runner/karma-requirejs
This Karma plugin launches the headless PhantomJS Browser. Karma will launch PhantomJS in the terminal - https://github.com/karma-runner/karma-phantomjs-launcher
Bonus: Karma Spec Reporter
I liked the output from this test reporter software. The only drawback was a little issue with filtering the output (issue #19) - but it can be kinda fixed with a config parameter. Don’t forget to activate the new Spec Reporter - https://github.com/mlex/karma-spec-reporter
Tips & Tricks
I had a few troubles getting Karma up and running, here are the things I’ve learned while setting everything up.
- Set the config parameter
logLevelto get the very helpful error messages
- Don’t forget to load the RequireJS with the
- It was essential to load AngularJS before everything else gets loaded via the
filessetting. This costed me a few hours.
- Exclude the projects RequireJS „main“ config file.
proxiescan get a bit tricky too. The
urlRootvalue must always be
/base/at least on my test server. I as well needed to set the
proxiesparameter, since I use vHosts or rather a Router to serve my local development server with the address flyweb.dev