- Version 10.0.1
- Project Flyweb Production
- Section blog
- Tags
Published This Post is a few years old and the Information provided might be out of date!
Karma config file for Angular / requireJS Project
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.
Installation
Install Karma and some plugins via Node:
https://karma-runner.github.io/0.13/intro/installation.html
# Install Karma:
$ npm install karma --save-dev
# Install plugins that your project needs:
$ npm install karma-jasmine karma-chrome-launcher --save-dev
RequireJS Plugin
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
Jasmine Plugin
This Karma plugin is a adapter for Jasmine testing framework. Jasmine is a framework for testing JavaScript code - https://github.com/karma-runner/karma-jasmine
PhantomJS Plugin
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
logLevel
to get the very helpful error messages - Don’t forget to load the RequireJS with the
frameworks
parameter - It was essential to load AngularJS before everything else gets loaded via the
files
setting. This costed me a few hours. - Exclude the projects RequireJS „main“ config file.
- The
basePath
,urlRoot
andproxies
can get a bit tricky too. TheurlRoot
value must always be/base/
at least on my test server. I as well needed to set theproxies
parameter, since I use vHosts or rather a Router to serve my local development server with the address flyweb.dev