Code coverage using Istanbul for Ember apps.
- If using Mocha, Testem
>= 1.6.0for which you need ember-cli> 2.4.3 - If using Mirage or Pretender, you need Pretender
>= 0.11.0
ember install ember-cli-code-coverage
Coverage will only be generated when an environment variable is true (by default COVERAGE) and running your test command like normal.
For example:
COVERAGE=true ember test
Configuration is optional. It should be put in a file at config/coverage-config.js.
-
coverageEnvVar: Defaults toCOVERAGE. This is the environment variable that when set will cause coverage metrics to be generated. -
reporters: Defaults to['lcov', 'html']. Thejson-summaryreporter will be added to anything set here, it is required. This can be any reporters supported by Istanbul. -
excludes: Defaults to['*/mirage/**/*']. An array of globs to exclude from instrumentation. Useful to exclude files from coverage statistics. -
coverageFolder: Defaults tocoverage. A folder relative to the root of your project to store coverage results.
Aka when using ember-cli-mirage or Pretender. You may require a version of Pretender that includes this fix.
To work, this addon has to post coverage results back to a middleware at /write-coverage.
// in mirage/config.js
this.passthrough('/write-coverage');
this.namespace = 'api'; // It's important that the passthrough for coverage is before the namespace, otherwise it will be prefixed.
This addon was inspired by ember-cli-blanket.
The primary differences are that this addon uses Istanbul rather than Blanket for coverage and it instruments your application code as part of the build, when enabled.