karma-coverage

A Karma plugin. Generate code coverage.

  • Owner: karma-runner/karma-coverage
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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.

Main metrics

Overview
Name With Ownerkarma-runner/karma-coverage
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2013-02-28 07:44:44
Pushed At2024-10-09 18:56:48
Last Commit At2023-06-23 09:32:56
Release Count41
Last Release Namev2.2.1 (Posted on )
First Release Namev0.0.2 (Posted on )
用户参与
Stargazers Count772
Watchers Count21
Fork Count247
Commits Count274
Has Issues Enabled
Issues Count264
Issue Open Count116
Pull Requests Count91
Pull Requests Open Count21
Pull Requests Close Count129
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private