Socket
Socket
Sign inDemoInstall

karma-coverage

Package Overview
Dependencies
66
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-coverage

A Karma plugin. Generate code coverage.


Version published
Maintainers
4
Weekly downloads
1,553,879
increased by0.17%
Install size
13.6 MB

Weekly downloads

Package description

What is karma-coverage?

The karma-coverage npm package is a plugin for the Karma test runner that generates code coverage reports. It uses Istanbul under the hood to instrument the code and then record the coverage data when the tests are run. The reports can be generated in various formats and can be integrated into continuous integration workflows to ensure code quality.

What are karma-coverage's main functionalities?

Coverage Reporting

This feature allows you to generate coverage reports in various formats such as HTML, LCOV, and JSON. The code sample shows how to configure Karma to use the karma-coverage plugin to generate an HTML coverage report.

module.exports = function(config) {
  config.set({
    // other Karma configuration...
    reporters: ['progress', 'coverage'],
    preprocessors: {
      '**/*.js': ['coverage']
    },
    coverageReporter: {
      type : 'html',
      dir : 'coverage/'
    }
  });
};

Threshold Enforcement

This feature allows you to enforce coverage thresholds. If the code does not meet the specified thresholds for statements, branches, functions, or lines, Karma will exit with an error. The code sample demonstrates how to set these thresholds in the Karma configuration.

module.exports = function(config) {
  config.set({
    // other Karma configuration...
    reporters: ['progress', 'coverage'],
    coverageReporter: {
      check: {
        global: {
          statements: 80,
          branches: 80,
          functions: 80,
          lines: 80
        }
      }
    }
  });
};

Other packages similar to karma-coverage

Readme

Source

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.

Keywords

FAQs

Last updated on 23 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc