Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

karma-coverage-istanbul-reporter

mattlewis922.3mMIT3.0.3TypeScript support: definitely-typed

A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage.

karma-plugin, karma-reporter, coverage, istanbul, istanbuljs

readme

karma-coverage-istanbul-reporter

Sponsorship Build Status codecov npm version npm Twitter Follow

A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage.

About

This is a reporter only and does not perform the actual instrumentation of your code. Babel users should use the istanbul babel plugin to instrument your code and webpack + typescript users should use the coverage-istanbul-loader and then use this karma reporter to do the actual reporting. See the test config for an e2e example of how to combine them.

Installation

npm install karma-coverage-istanbul-reporter --save-dev

Configuration

// karma.conf.js
const path = require('path');

module.exports = function(config) {
  config.set({
    // ... rest of karma config

    // anything named karma-* is normally auto included so you probably dont need this
    plugins: ['karma-coverage-istanbul-reporter'],

    reporters: ['coverage-istanbul'],

    coverageIstanbulReporter: {
      // reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib
      reports: ['html', 'lcovonly', 'text-summary'],

      // base output directory. If you include %browser% in the path it will be replaced with the karma browser name
      dir: path.join(__dirname, 'coverage'),

      // Combines coverage information from multiple browsers into one report rather than outputting a report
      // for each browser.
      combineBrowserReports: true,

      // if using webpack and pre-loaders, work around webpack breaking the source path
      fixWebpackSourcePaths: true,

      // Omit files with no statements, no functions and no branches covered from the report
      skipFilesWithNoCoverage: true,

      // Most reporters accept additional config options. You can pass these through the `report-config` option
      'report-config': {
        // all options available at: https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html/index.js#L257-L261
        html: {
          // outputs the report in ./coverage/html
          subdir: 'html'
        }
      },

      // enforce percentage thresholds
      // anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
      thresholds: {
        emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
        // thresholds for all files
        global: {
          statements: 100,
          lines: 100,
          branches: 100,
          functions: 100
        },
        // thresholds per file
        each: {
          statements: 100,
          lines: 100,
          branches: 100,
          functions: 100,
          overrides: {
            'baz/component/**/*.js': {
              statements: 98
            }
          }
        }
      },

      verbose: true // output config used by istanbul for debugging
    }
  });
};

List of reporters and options

Credits

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.0.3 (2020-05-28)

Bug Fixes

  • duplicated files when "skipFilesWithNoCoverage=false" on windows (052f6ab)

3.0.2 (2020-05-05)

Bug Fixes

  • return correct exit code when thresholds are not met (that works with the karma api) (a0cbdd8), closes #80

3.0.1 (2020-05-04)

Bug Fixes

  • set correct process exit code when thresholds are not met (9ba3fe0), closes #80

3.0.0 (2020-05-01)

⚠ BREAKING CHANGES

  • node 6 and node 8 are no longer supported. To use this package you must upgrade to node 10 or higher.

Features

  • upgrade to latest istanbul api (28cbbfb)

2.1.1 (2019-11-21)

Bug Fixes

2.1.0 (2019-07-24)

Features

  • config: support istanbul-api instrumentation configuration (c4f7a9c), closes #73

2.0.6 (2019-07-20)

Bug Fixes

  • get source code from sourceMapStore on write report (619d90d), closes #72

2.0.5 (2019-02-17)

Bug Fixes

  • correctly strip source file prefixes when no webpack.context is defined (3c48bf8)
  • don't double-report files with mixed slashes in their names on windows (38087c2)

2.0.4 (2018-09-08)

Bug Fixes

  • handle source roots being undefined on windows (8eba911), closes #55

2.0.3 (2018-09-01)

Bug Fixes

  • update istanbuljs to 2.x (a835e22), closes #52
  • use correct source file path separators on windows (938e93c), closes #47

2.0.2 (2018-08-24)

Bug Fixes

  • files with no coverage should be preserved by default (#54) (e5a5545), closes #53

2.0.1 (2018-05-23)

Bug Fixes

  • don't log errors twice when using multiple reporters (a17b6ca), closes #44

2.0.0 (2018-05-17)

Features

  • drop support for node 4 (26ad3af)

BREAKING CHANGES

  • node 4 is no longer supported

1.4.3 (2018-05-17)

Bug Fixes

  • verbose: pass the verbose option to istanbul if set (9473517), closes #43

1.4.2 (2018-03-06)

Bug Fixes

  • all browsers should have their own output folder when not combined (4aad40b), closes #39

1.4.1 (2018-01-24)

Bug Fixes

  • handle no config being set (5483e2b), closes #36

1.4.0 (2018-01-23)

Features

  • add combineBrowserReports option (2ae16ee), closes #34

1.3.3 (2017-12-26)

Bug Fixes

  • don't prepend the webpack context to absolute source roots (138e8f8), closes #33

1.3.1 (2017-12-23)

Bug Fixes

  • prepend the webpack context to the source root if not set (4138b80), closes #32

1.3.0 (2017-05-26)

Features

  • thresholds: allow overriding per file thresholds (1a894f0), closes #20
  • thresholds: allow threshold logs not to be emitted as errors (2de647c), closes #19

1.2.1 (2017-04-30)

Bug Fixes

  • don't throw when there are no sources as part of the sourcemap (4fc5311), closes #15

1.2.0 (2017-04-15)

Features

  • thresholds: allow per file enforcement of threshold reporting (f6d71b3), closes #12

1.1.0

  • Add the skipFilesWithNoCoverage option

1.0.0

  • Add the %browser% placeholder in the dir option to allow multiple browsers to output coverage

0.3.0

  • Add coverage thresold enforcement via the thresholds option

0.2.0

  • Add the fixWebpackSourcePaths option

0.1.0

  • Initial release