Alexandro.Net

Version 1.0.0

@stackline/karma-coverage

A Karma plugin. Generate code coverage.

Independent maintenance of karma-coverage 2.2.1. Original authors and licenses are retained.

Installation

# Preserve existing imports with an npm alias
npm install karma-coverage@npm:@stackline/karma-coverage@1.0.0
# Or use the scoped package name in your imports
npm install @stackline/karma-coverage@1.0.0

Node.js: >=10.0.0. Read the compatibility and maintenance notes before migrating.

Usage and API

The reference below may retain upstream package names. Use the alias installation above to run those imports with this Stackline release.

@stackline/karma-coverage

Independent maintenance fork of karma-coverage@2.2.1. Original API, module format, runtime dependency ranges, and supported Node.js engines are preserved.

npm install @stackline/karma-coverage
# Preserve existing imports with an npm alias:
npm install karma-coverage@npm:@stackline/karma-coverage@1.0.0

See UPSTREAM.md for the exact source and issue review, and CHANGELOG.md for focused maintenance changes. Development and release tooling runs on Node.js 24; that does not change the library runtime requirement.

Maintained by Stackline. Issues · npm.

Upstream documentation

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.

Upstream issues and maintenance review

Upstream review

Based on karma-coverage@2.2.1, source 55eb8a85f8243af3ae9cf75460a780fc5c71761f. The registry gitHead source manifest contains the previous semantic-release version, but every upstream published runtime file matches this commit byte-for-byte. Only package metadata differs in the upstream tarball, whose integrity was checked independently.

Issue triage (2026-09-29)

No upstream maintainer was contacted. Runtime files and original license/authorship are retained. Development tooling uses Node24; package engine declarations remain unchanged.

Verification

npm ci --ignore-scripts, npm test, npm run test:package, npm audit --audit-level=low. Packed tests install the actual archive and exercise the exported plugin. Publication uses the exact CI tarball only after CI and CodeQL succeed.

Release changes

Stackline changes

1.0.0

2.2.1 (2023-06-23)

Bug Fixes

2.2.0 (2022-02-10)

Features

2.1.1 (2022-02-05)

Bug Fixes

2.1.0 (2021-12-01)

Bug Fixes

Features

2.0.3 (2020-07-24)

Bug Fixes

2.0.2 (2020-04-13)

Bug Fixes

2.0.1 (2019-08-20)

2.0.0 (2019-08-20)

Bug Fixes

Chores

BREAKING CHANGES

The istanbul package is deprecated in favor several split packages that control different aspects of how istanbul works. This commit adds the recommended packages that will be used in future commits as karma-coverage's usage of istanbul is updated to the latest api.

This commit refactors the in memory report implementation to use the new istanbul report API.

Report creation is removed from newer versions of the istanbul API, so this commit adds a set of utility functions to wrap around the new API and provide similar functionality as the old API. The top level export uses the new utility function to register the in-memory report.

This commit updates the preprocessor to use istanbul-lib-instrument instead of the deprecated istanbul package. The biggest change in this refactor is using a callable function instead of a constructor when creating instrumenters

The old istanbul package exposed the Instrumenter directly, allowing the preprocessor to create an instance of it. istanbul-lib-instrument, however, exposes a callable function that creates an Instrumenter. This commit updates the preprocessor to follow this new pattern of using a callable function. In order to ensure backwards compatibility, a utility function is added to wrap constructors with a callable function for creation automatically.

This change allows the following configuration for creating instrumenters:

  1. An object that contains an Instrumenter constructor
  2. An Instrumenter constructor itself
  3. A callable function that returns an Instrumenter instance.

This commit also uses the istanbul-lib-source-maps package to handle storing source maps. A global source map store registers source maps so they can be used later on in the reporter.

This commit updates the reporter by using the istanbul-lib-coverage package api for handling coverage checking/management and the istanbul-lib-report package api for handling reporting.

The new apis remove the need for collectors and remove the need to handle disposing collectors.

This commit removes the source-cache-store and source-cache files as they are no longer being used. The source-map-store and istanbul-lib-source-maps are used instead, so these files are no longer needed.

This commit updates the report creator utility to allow resetting the custom reporter map.

This commit updates the preprocessor to properly access file coverage when storing it in the global coverage map (when includeAllSources is true). The previous method did not work because the returned instrumented code from the default istanbul instrumenter returns the coverage map in a POJO object instead of JSON notation. This breaks the coverage regex used to match and parse the coverage map.

The istanbul instrumenter offers the ability to receive the coverage map for the last instrumented file through a separate function, so that is tested for and used if it is supported. The original method is used as a fallback for backwards compatibility.

This commit also addresses changes from the v0 instanbul instrumenter options. The changes are additive only to maintain backwards compatibility for other instrumenters.

This commit fixes errors with accessing data properly during the checkCoverage method. A previous commit updated the implementation to use istanbul-lib-coverage, but this involved an api change to access the raw coverage data (which checkCoverage uses).

This commit also fixes the checking coverage for each file by using a map to store file coverage summaries instead of merging summaries like the global results. Per file coverage now works as expected.

This commit updates the mocking done in unit tests to properly mock the new istanbul API. Additionally, new unit test suites are added for the utility methods report-creator and source-map-store.

1.1.2 (2018-05-03)

Bug Fixes

BREAKING CHANGES

1.1.1 (2016-07-23)

Bug Fixes

1.1.0 (2016-07-07)

Features

1.0.0 (2016-05-04)

0.5.5 (2016-03-07)

Bug Fixes

0.5.4 (2016-03-03)

Bug Fixes

0.5.3 (2015-10-20)

Bug Fixes

0.5.2 (2015-09-08)

Bug Fixes

0.5.1 (2015-08-28)

Bug Fixes

0.5.0 (2015-08-06)

Bug Fixes

<a name"0.4.2">

0.4.2 (2015-06-12)

Bug Fixes

<a name"0.4.1">

0.4.1 (2015-06-09)

Features

<a name"0.4.0">

0.4.0 (2015-06-09)

Bug Fixes

Breaking Changes

<a name"0.3.1">

0.3.1 (2015-06-09)

Bug Fixes

Features

<a name"0.3.0">

0.3.0 (2015-06-09)

Features

Breaking Changes

Removed Ibrik instrumenter that need to be installed explicitly.

Quick list of known community instrumenters :

(626e7b0c)

<a name"0.2.7">

0.2.7 (2015-06-09)

Bug Fixes

<a name"0.2.6">

0.2.6 (2015-06-09)

Bug Fixes

<a name"0.2.5">

0.2.5 (2015-06-09)

Features

<a name"0.2.4">

0.2.4 (2015-06-09)

Bug Fixes

<a name"0.2.3">

0.2.3 (2015-06-09)

Features

<a name"0.2.2">

0.2.2 (2015-06-09)

Features

<a name"0.2.1">

0.2.1 (2015-06-09)

Features

<a name"0.2.0">

0.2.0 (2015-06-09)

Features

Breaking Changes

coverageReporter: {
  type: 'json'
}

// or with multiple reporters
coverageReporter: {
  reporters: [
    {type: 'html', dir: 'coverage'},
    {type: 'json', dir: 'coverage'},
  ]
}

(1256fb8b)

<a name"0.1.5">

0.1.5 (2015-06-09)

Bug Fixes

Features

<a name"0.1.4">

0.1.4 (2015-06-09)

Features

<a name"0.1.3">

0.1.3 (2015-06-09)

Bug Fixes

Features

<a name"0.1.2">

0.1.2 (2015-06-09)

<a name"0.1.1">

0.1.1 (2015-06-09)

Bug Fixes

<a name"0.1.0">

0.1.0 (2015-06-09)

<a name"0.0.5">

0.0.5 (2015-06-09)

Bug Fixes

Features

<a name"0.0.4">

0.0.4 (2015-06-09)

Features

<a name"0.0.3">

0.0.3 (2015-06-09)

Bug Fixes

Features

<a name"0.0.2">

0.0.2 (2015-06-09)

Release files and references

Package bytes, npm provenance and the immutable GitHub release were verified for this version. Security checks describe the reviewed release; documented compatibility risks and upstream reports are not blanket claims of resolution.