Skip to content

bySabi/karma-istanbuljs-reporter

Repository files navigation

karma-istanbuljs-reporter

npm version npm downloads Build Status Windows Tests Donate

a Karma plugin for generate code coverage using new, v1, Istanbul API

This reporter try to mimic behaviours and settings of nyc tool more than karma-coverage

Instrumentation

Use babel-istanbul-plugin for source instrumentation. Don´t forget exclude test files from instrumentation using exclude/include rules

Installation

npm

npm install karma-istanbuljs-reporter --save-dev

Usage

Add karma.conf.js file to project.

Examples of karma.conf.js

Basic

module.exports = function(config) {
  config.set({
  ...
    reporters: ['progress', 'istanbul'],
    istanbulReporter: {
      reporters: [
        { type: 'text' }
      ]
    },
  ...
  });
}

Multiple reporters

module.exports = function(config) {
  config.set({
  ...
    reporters: ['progress', 'istanbul'],
    istanbulReporter: {
      dir: 'cover/',     // changed default output dir from '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' }
      ]
    },
  ...
  });
}

Supported reporters istanbul-reports

Checking coverage

karma-istanbuljs-reporter can fail tests if coverage falls below a threshold.

module.exports = function(config) {
  config.set({
  ...
    reporters: ['progress', 'istanbul'],
    istanbulReporter: {
      checkCoverage: true
    },
  ...
  });
}

Default thresholds

{
  lines: 90,
  functions: 0,
  statements: 0,
  branches: 0
}

Checking coverage with custom thresholds

module.exports = function(config) {
  config.set({
  ...
    reporters: ['progress', 'istanbul'],
    istanbulReporter: {
      checkCoverage: {
        lines: 95,
        functions: 95,
        statements: 95,
        branches: 95
      }
    },
  ...

WIP: 'Include all sources' feature

issues#1

Example

Credits

author

contributors

Contributing

  • Documentation improvement
  • Feel free to send any PR

License

ISC