Skip to content
A Karma plugin. Generate code coverage.
JavaScript
Branch: master
Clone or download

Latest commit

semantic-release-bot chore(release): 2.0.2 [skip ci]
## [2.0.2](v2.0.1...v2.0.2) (2020-04-13)

### Bug Fixes

* **reporter:** update calls to  match new API in istanbul-lib-report fix [#398](#398) ([#403](#403)) ([4962a70](4962a70))
* remove information about old istanbul lib ([#404](#404)) ([5cf931a](5cf931a))
Latest commit 32acafa Apr 13, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Fix exclude typo on the check object Oct 17, 2017
examples fix(preprocessor): Support CoffeeScript when using RequireJS Nov 14, 2015
lib fix(reporter): update calls to match new API in istanbul-lib-report fix Mar 24, 2020
test ci(test): use eslint as ci command and add all js files to check by e… Mar 30, 2020
.eslintrc ci(test): use eslint as ci command and add all js files to check by e… Mar 30, 2020
.gitattributes chore: add .gitattributes to deal with Win line endings Jun 7, 2013
.gitignore docs: Cleanup documentation and add running coffee example Jun 11, 2015
.mailmap chore: update contributors Jun 9, 2015
.npmignore docs: Cleanup documentation and add running coffee example Jun 11, 2015
.travis.yml chore: add semantic-release for project - fix #408 (#413) Apr 13, 2020
CHANGELOG.md chore(release): 2.0.2 [skip ci] Apr 13, 2020
CONTRIBUTING.md chore: rename to Karma Mar 19, 2013
LICENSE chore: fix the license Oct 31, 2013
README.md fix: remove information about old istanbul lib (#404) Mar 19, 2020
gruntfile.js ci(test): use eslint as ci command and add all js files to check by e… Mar 30, 2020
package-lock.json chore: add semantic-release for project - fix #408 (#413) Apr 13, 2020
package.json chore: add semantic-release for project - fix #408 (#413) Apr 13, 2020
release.config.js chore: add semantic-release for project - fix #408 (#413) Apr 13, 2020

README.md

karma-coverage

js-standard-style npm version npm downloads

Build Status Dependency Status devDependency Status

Generate code coverage using Istanbul.

Installation

The easiest way is to install karma-coverage as a devDependency, by running

npm install karma karma-coverage --save-dev

Configuration

For configuration details see docs/configuration.

Examples

Basic

// karma.conf.js
module.exports = function(config) {
  config.set({
    files: [
      'src/**/*.js',
      'test/**/*.js'
    ],

    // coverage reporter generates the coverage
    reporters: ['progress', 'coverage'],

    preprocessors: {
      // source files, that you wanna generate coverage for
      // do not include tests or libraries
      // (these files will be instrumented by Istanbul)
      'src/**/*.js': ['coverage']
    },

    // optionally, configure the reporter
    coverageReporter: {
      type : 'html',
      dir : 'coverage/'
    }
  });
};

CoffeeScript

For an example on how to use with CoffeeScript see examples/coffee. For an example of how to use with CoffeeScript and the RequireJS module loader, see examples/coffee-requirejs (and also see the useJSExtensionForCoffeeScript option in docs/configuration.md).

Advanced, multiple reporters

// karma.conf.js
module.exports = function(config) {
  config.set({
    files: [
      'src/**/*.js',
      'test/**/*.js'
    ],
    reporters: ['progress', 'coverage'],
    preprocessors: {
      'src/**/*.js': ['coverage']
    },
    coverageReporter: {
      // specify a common output directory
      dir: 'build/reports/coverage',
      reporters: [
        // reporters not supporting the `file` property
        { type: 'html', subdir: 'report-html' },
        { type: 'lcov', subdir: 'report-lcov' },
        // reporters supporting the `file` property, use `subdir` to directly
        // output them in the `dir` directory
        { type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
        { type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
        { type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
        { type: 'text', subdir: '.', file: 'text.txt' },
        { type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
      ]
    }
  });
};

FAQ

Don't minify instrumenter output

When using the istanbul instrumenter (default), you can disable code compaction by adding the following to your configuration.

// karma.conf.js
module.exports = function(config) {
  config.set({
    coverageReporter: {
      instrumenterOptions: {
        istanbul: { noCompact: true }
      }
    }
  });
};

For more information on Karma see the homepage.

You can’t perform that action at this time.