1 | # karma-coverage-istanbul-reporter
|
2 | [![Build Status](https://travis-ci.org/mattlewis92/karma-coverage-istanbul-reporter.svg?branch=master)](https://travis-ci.org/mattlewis92/karma-coverage-istanbul-reporter)
|
3 | [![codecov](https://codecov.io/gh/mattlewis92/karma-coverage-istanbul-reporter/branch/master/graph/badge.svg)](https://codecov.io/gh/mattlewis92/karma-coverage-istanbul-reporter)
|
4 | [![npm version](https://badge.fury.io/js/karma-coverage-istanbul-reporter.svg)](http://badge.fury.io/js/karma-coverage-istanbul-reporter)
|
5 | [![npm](https://img.shields.io/npm/dm/karma-coverage-istanbul-reporter.svg)](http://badge.fury.io/js/karma-coverage-istanbul-reporter)
|
6 | [![GitHub issues](https://img.shields.io/github/issues/mattlewis92/karma-coverage-istanbul-reporter.svg)](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues)
|
7 | [![GitHub stars](https://img.shields.io/github/stars/mattlewis92/karma-coverage-istanbul-reporter.svg)](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/stargazers)
|
8 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/mattlewis92/karma-coverage-istanbul-reporter/master/LICENSE)
|
9 |
|
10 | > A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage.
|
11 |
|
12 | ## About
|
13 | This is a reporter only and does not perform the actual instrumentation of your code. Babel users should use the [istanbul babel plugin](https://github.com/istanbuljs/babel-plugin-istanbul) to instrument your code and webpack + typescript users should use the [istanbul-instrumenter-loader](https://github.com/deepsweet/istanbul-instrumenter-loader) and then use this karma reporter to do the actual reporting. See the [test config](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/blob/master/test/karma.conf.js) for an e2e example of how to combine them.
|
14 |
|
15 | ## Installation
|
16 |
|
17 | ```bash
|
18 | npm install karma-coverage-istanbul-reporter --save-dev
|
19 | ```
|
20 |
|
21 | ## Configuration
|
22 |
|
23 | ```js
|
24 | // karma.conf.js
|
25 | const path = require('path');
|
26 |
|
27 | module.exports = function (config) {
|
28 |
|
29 | config.set({
|
30 |
|
31 | // ... rest of karma config
|
32 |
|
33 | // anything named karma-* is normally auto included so you probably dont need this
|
34 | plugins: ['karma-coverage-istanbul-reporter'],
|
35 |
|
36 | reporters: ['coverage-istanbul'],
|
37 |
|
38 | // any of these options are valid: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-api/lib/config.js#L33-L39
|
39 | coverageIstanbulReporter: {
|
40 |
|
41 | // reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib
|
42 | reports: ['html', 'lcovonly', 'text-summary'],
|
43 |
|
44 | // base output directory. If you include %browser% in the path it will be replaced with the karma browser name
|
45 | dir: path.join(__dirname, 'coverage'),
|
46 |
|
47 | // if using webpack and pre-loaders, work around webpack breaking the source path
|
48 | fixWebpackSourcePaths: true,
|
49 |
|
50 | // stop istanbul outputting messages like `File [${filename}] ignored, nothing could be mapped`
|
51 | skipFilesWithNoCoverage: true,
|
52 |
|
53 | // Most reporters accept additional config options. You can pass these through the `report-config` option
|
54 | 'report-config': {
|
55 |
|
56 | // all options available at: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/html/index.js#L135-L137
|
57 | html: {
|
58 | // outputs the report in ./coverage/html
|
59 | subdir: 'html'
|
60 | }
|
61 |
|
62 | },
|
63 |
|
64 | // enforce percentage thresholds
|
65 | // anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
|
66 | thresholds: {
|
67 | emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
|
68 | global: { // thresholds for all files
|
69 | statements: 100,
|
70 | lines: 100,
|
71 | branches: 100,
|
72 | functions: 100
|
73 | },
|
74 | each: { // thresholds per file
|
75 | statements: 100,
|
76 | lines: 100,
|
77 | branches: 100,
|
78 | functions: 100,
|
79 | overrides: {
|
80 | 'baz/component/**/*.js': {
|
81 | statements: 98
|
82 | }
|
83 | }
|
84 | }
|
85 | }
|
86 |
|
87 | }
|
88 |
|
89 | });
|
90 |
|
91 | }
|
92 | ```
|
93 |
|
94 | ### List of reporters and options
|
95 | * [clover](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/clover/index.js#L8-L9)
|
96 | * [cobertura](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/cobertura/index.js#L9-L10)
|
97 | * [html](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/html/index.js#L135-L137)
|
98 | * [json-summary](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/json-summary/index.js#L8)
|
99 | * [json](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/json/index.js#L8)
|
100 | * lcov
|
101 | * [lcovonly](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/lcovonly/index.js#L8)
|
102 | * none
|
103 | * [teamcity](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/teamcity/index.js#L9-L10)
|
104 | * [text-lcov](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/text-lcov/index.js#L9)
|
105 | * [text-summary](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/text-summary/index.js#L9)
|
106 | * [text](https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/text/index.js#L159-L160)
|
107 |
|
108 | ## Credits
|
109 | * [Original karma-coverage source](https://github.com/karma-runner/karma-coverage/blob/master/lib/reporter.js)
|
110 | * [Example of using the new reporter API](https://github.com/facebook/jest/blob/master/scripts/mapCoverage.js)
|
111 | * [Karma remap istanbul](https://github.com/marcules/karma-remap-istanbul)
|
112 |
|
113 | ## License
|
114 | MIT
|