Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

BBVAEngineering/ember-cli-code-coverage

 
 

Repository files navigation

DEPRECATED

ember-cli-code-coverage Build Status

Code coverage using Istanbul for Ember apps.

Requirements

  • If using Mocha, Testem >= 1.6.0 for which you need ember-cli > 2.4.3
  • If using Mirage you need ember-cli-mirage >= 0.1.13
  • If using Pretender (even as a dependency of Mirage) you need pretender >= 0.11.0
  • If using Mirage or Pretender, you need to set up a passthrough for coverage to be written.

Installation

  • ember install ember-cli-code-coverage

Usage

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

If you want your coverage to work on both Unix and Windows, you can do this:

npm install cross-env --save-dev

and then:

cross-env COVERAGE=true ember test

Configuration

Configuration is optional. It should be put in a file at config/coverage.js.

Options

  • coverageEnvVar: Defaults to COVERAGE. This is the environment variable that when set will cause coverage metrics to be generated.

  • reporters: Defaults to ['lcov', 'html']. The json-summary reporter 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 to coverage. A folder relative to the root of your project to store coverage results.

  • useBabelInstrumenter: Defaults to false. Whether or not to use Babel instrumenter instead of default instrumenter. The Babel instrumenter is useful when you are using features of ESNext as it uses your Babel configuration defined in ember-cli-build.js.

Example

  module.exports = {
    coverageEnvVar: 'COV'
  }

Create a passthrough when intercepting all ajax requests in tests

To work, this addon has to post coverage results back to a middleware at /write-coverage.

If you are using ember-cli-mirage you should add the following:

// 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.

If you are using ember-cli-pretender you should add the following:

// where ever you set up the Pretender Server

  var server = new Pretender(function () {
    this.post('/write-coverage', this.passthrough);
  });

Inspiration

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.

About

Code coverage for ember apps using Istanbul

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 91.4%
  • HTML 8.5%
  • Handlebars 0.1%