Code Monkey home page Code Monkey logo

karma-coverage's Introduction

karma-coverage Build Status

Generate code coverage using Istanbul.

Installation

The easiest way is to keep karma-coverage as a devDependency in your package.json.

{
  "devDependencies": {
    "karma": "~0.10",
    "karma-coverage": "~0.1"
  }
}

You can simple do it by:

npm install karma-coverage --save-dev

Configuration

Following code shows the default configuration...

// 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/'
    }
  });
};

Example use with a CoffeeScript project...

// karma.conf.js
module.exports = function(config) {
  config.set({
    files: [
      'src/**/*.coffee',
      'test/**/*.coffee'
    ],

    // 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 via Ibrik unless
      // specified otherwise in coverageReporter.instrumenter)
      'src/*.coffee': ['coverage'],

      // note: project files will already be converted to
      // JavaScript via coverage preprocessor.
      // Thus, you'll have to limit the CoffeeScript preprocessor
      // to uncovered files.
      'test/**/*.coffee': ['coffee']
    },

    // optionally, configure the reporter
    coverageReporter: {
      type : 'html',
      dir : 'coverage/'
    }
  });
};

Options

type

Type: String

Possible Values:

  • html (default)
  • lcov (lcov and html)
  • lcovonly
  • text
  • text-summary
  • cobertura (xml format supported by Jenkins)
  • teamcity (code coverage System Messages for TeamCity)

If you set type to text or text-summary, you may set the file option, like this.

coverageReporter: {
  type : 'text',
  dir : 'coverage/',
  file : 'coverage.txt'
}

If no filename is given, it will write the output to the console.

dir

Type: String

Description: This will be used to output coverage reports. When you set a relative path, the directory is resolved against the basePath.

multiple reporters

You can use multiple reporters, by providing array of options.

coverageReporter: {
  reporters:[
    {type: 'html', dir:'coverage/'},
    {type: 'teamcity'},
    {type: 'text-summary'}
  ],
}

instrumenter

Karma-coverage infers the instrumenter regarding of the file extension. The .coffee files are by default covered using Ibrik (an Istanbul analog for CoffeeScript files). It is possible to override this behavior and point out an instrumenter for the files matching a specific pattern. To do so, you need to declare an object under with the keys representing the pattern to match, and the instrumenter to apply. The matching will be done using minimatch. If two patterns match, the last one will take the precedence.

coverageReporter: {
  instrumenter: {
    '**/*.coffee': 'istanbul' // Force the use of the Istanbul instrumenter to cover CoffeeScript files
  },
  // ...
}

For more information on Karma see the homepage.

karma-coverage's People

Contributors

vojtajina avatar aymericbeaumet avatar dignifiedquire avatar abierbaum avatar samuelhorwitz avatar mokemokechicken avatar aprooks avatar constellation avatar kombucha avatar manevpe avatar mrzepinski avatar kylewelsby avatar juliemr avatar joseph-connolly avatar gvarsanyi avatar can3p avatar chrisgladd avatar

Watchers

 avatar James Cloos avatar  avatar

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.