Karma Angularity Solution
Requisite configuration and modules to test Angularity projects with Karma
Angularity
Angularity is an opinionated project structure for building applications in AngularJS.
This project is for use with the Webpack implementation, and is not suitable for the original Browserify-Sass Angularity implementation.
Rationale
The original Browserify-Sass Angularity was a global installation that included the Karma unit testing framework. This is not the case with the new Webpack implementation.
Use this package, along with the Webpack Angularity implementation, to unit tests Angularity projects.
Limitations
-
This package is not a global installation. You need to install as a development dependency in every single project you wish to build.
-
This package does not contain Karma, you will need to install separately (see below).
-
This package presumes npm scripts. If you want to run outside of scripts you will need some additional global installs (see below).
-
Favours Teamcity CI server, to the extent that it includes its reporter.
Installation
Do not follow the Angularity installation instructions.
Continue to use a Node version manager such as nvm for Mac, or nvm-windows for Windows. However you can run on NodeJS 4.0.0, meaning:
nvm install 4.0.0
nvm use 4.0.0
And additionally on Mac you may wish to set your default Node version:
nvm alias default 4.0.0
Now install this package as a local dev-dependency.
npm install --save-dev karma-angularity-solution
Co-requisites
Install webpack-angularity-solution as a local dev-dependency in order to build the test bundle.
npm install --save-dev webpack-angularity-solution
Note that you do not need any global installs if you only use npm scripts. But if you operate outside of npm scripts you will find that you are missing Karma, and cross-env as global installs.
Each project
package.json
Use the following dev-dependencies and scripts in your project.
{
"scripts": {
"test": "cross-env MODE=test npm run build && karma start",
"ci": "cross-env KARMA_REPORTER=teamcity MODE=test npm run build && karma start"
},
"devDependencies": {
"webpack-angularity-solution": "latest"
"karma-angularity-solution": "latest"
}
}
Some explanation:
karma.conf.js
Create a Karma configuration file that delegates to the karma-angularity-solution package. Use options taken from the same environment variables used in your package.json scripts.
module.exports = require('karma-angularity-solution')(process.env);
Some explanation:
Usage
Run the scripts that are defined in your package.json by using npm run ....
For example:
Options
-
port:int Optional port (that overrides angularity.json)
-
reporter:string Optional reporter name, or Array thereof (defaults to "spec")
-
browser:string Optional browser, or Array thereof (defaults to "Chrome")
-
logLevel:string Optional log-level (defaults to "LOG_INFO")