karma-angularity-solution v1.2.1
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.0And additionally on Mac you may wish to set your default Node version:
nvm alias default 4.0.0Now install this package as a local dev-dependency.
npm install --save-dev karma-angularity-solutionCo-requisites
Install webpack-angularity-solution as a local dev-dependency in order to build the test bundle.
npm install --save-dev webpack-angularity-solutionNote 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 webpack -d --progress && karma start",
"ci": "cross-env KARMA_REPORTER=teamcity MODE=test webpack -d --progress && karma start"
},
"devDependencies": {
"webpack-angularity-solution": "latest"
"karma-angularity-solution": "latest"
}
}Some explanation:
cross-env
Any setting passed to `cross-env` corresponds to environment variables. By convention they are `UPPERCASE`. These environment variables are private to the executable that follows so you don't need to worry about name conflicts across different projects.
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.
/* global process:true */
module.exports = require('karma-angularity-solution')(process.env);Some explanation:
Options by
process.envThis `process.env` may be passed in entirety. The solution will automatically convert any upper-case option `SOME_OPTION` to camel-case `someOption` and parse strings to the correct type. Note however that Array parsing is **not** supported.
Usage
Run the scripts that are defined in your package.json by using npm run ....
For example:
run unit tests using
npm run testrun with the TeamCity reporter using
npm run ci
Options
port:intOptional port (that overridesangularity.json)reporter:stringOptional reporter name, or Array thereof (defaults to"spec")browser:stringOptional browser, or Array thereof (defaults to"Chrome")logLevel:stringOptional log-level (defaults to"LOG_INFO").Legal values include `"LOG_DISABLE"`|`"LOG_ERROR"`|`"LOG_WARN"`|`"LOG_INDO"`|`"LOG_DEBUG"`.
Environment variables
All settings may be parsed from uppercase environment variables. For example, to suppress logging during the test:
{
"scripts": {
"silent": "cross-env LOG_LEVEL=LOG_DISABLE MODE=test webpack -d --progress && karma start"
...
}
}