Code Monkey home page Code Monkey logo

karma-istanbul-threshold's Introduction

karma-istanbul-threshold

Build Status

Checks coverage thresholds by using json coverage files generated by Istanbul, karma-coverage or karma-remap-istanbul.

While karma-coverage already allows threshold checks, it unfortunately does not play well with source maps.

karma-remap-istanbul can convert results generated by karma-coverage but does not offer threshold checking.

This plugin fills that gap by using a json file for threshold checking that can be generated by Istanbul or karma-coverage (which internally uses Istanbul). Those json files can be remapped by karma-remap-istanbul to enable source-map support for threshold checking.

Installation

The easiest way is to install karma-istanbul-threshold as a devDependency, by running

npm install karma-istanbul-threshold --save-dev

Configuration

Add the plugin, reporter and reporter configuration in your karma.conf.js.

{
  plugins: ['karma-istanbul-threshold'],
  reporters: ['progress', 'karma-istanbul-threshold'],
  istanbulThresholdReporter: {
    src: 'path/to/coverage-report.json',
    basePath: path.resolve(__dirname, 'path/to/source'),
    reporters: ['text'], // use 'text' reporter to get text reports like in the screenshot 
    //reporters: ['teamcity'],  // use 'teamcity' reporter to generate output for teamcity
    excludes: [
      'some/module/*.ts' // will exclude .ts files in `path/to/source/some/module`
    ],
    thresholds: {
      global: {
        statements: 90,
        branches: 90,
        lines: 70,
        functions: 90,
      },
      each: {
        statements: 80,
        branches: 80,
        lines: 60,
        functions: 80,
      },
    },    
  }
}

Example configuration with karma-coverage and karma-remap-istanbul

{
  preprocessors: {
    'build/**/!(*spec).js': ['coverage']
  },
  plugins: ['karma-remap-istanbul', 'karma-coverage', 'karma-istanbul-threshold'],
  reporters: ['progress', 'coverage', 'karma-remap-istanbul', 'istanbul-threshold'],
  // Creates coverage reports and stores as json
  coverageReporter: {
    reporters: [
      { type: 'json', dir: 'tmp/coverage', subdir: '.', file: 'coverage-unmapped.json' }
    ],
  },
  // Creates a source-mapped version of coverage report  
  remapIstanbulReporter: {
    src: 'tmp/coverage/coverage-unmapped.json',
    reports: {
      'json': 'tmp/coverage/coverage-mapped.json'
    },
  },
  // Uses source-mapped version to check coverage thresholds
  istanbulThresholdReporter: {
    src: 'tmp/coverage/coverage-mapped.json',
    basePath: path.resolve(__dirname, 'path/to/source'),
    reporters: ['text'], 
    thresholds: {
      global: {
        statements: 90,
        branches: 90,
        lines: 70,
        functions: 90,
      },
      each: {
        statements: 80,
        branches: 80,
        lines: 60,
        functions: 80,
      },
    },    
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.