1 | # Configuration
|
2 |
|
3 | ### `type`
|
4 |
|
5 | **Type:** String
|
6 |
|
7 | **Description:** Specify a reporter type.
|
8 |
|
9 | **Possible Values:**
|
10 | * `html` (default)
|
11 | * `lcov` (lcov and html)
|
12 | * `lcovonly`
|
13 | * `text`
|
14 | * `text-summary`
|
15 | * `cobertura` (xml format supported by Jenkins)
|
16 | * `teamcity` (code coverage System Messages for TeamCity)
|
17 | * `json` (json format supported by [`grunt-istanbul-coverage`](https://github.com/daniellmb/grunt-istanbul-coverage))
|
18 | * `in-memory` (supported since v0.5.4)
|
19 |
|
20 | ### `dir`
|
21 |
|
22 | **Type:** String
|
23 |
|
24 | **Description:** This will be used to output coverage reports. When
|
25 | you set a relative path, the directory is resolved against the `basePath`.
|
26 |
|
27 | ### `subdir`
|
28 |
|
29 | **Type:** String
|
30 |
|
31 | **Description**: This will be used in complement of the `coverageReporter.dir`
|
32 | option to generate the full output directory path. By default, the output
|
33 | directory is set to `./config.dir/BROWSER_NAME/`, this option allows you to
|
34 | custom the second part. You can either pass a `string` or a `function` which will be
|
35 | called with the browser name passed as the only argument.
|
36 |
|
37 | ```javascript
|
38 | coverageReporter: {
|
39 | dir: 'coverage',
|
40 | subdir: '.'
|
41 | // Would output the results into: .'/coverage/'
|
42 | }
|
43 | ```
|
44 |
|
45 | ```javascript
|
46 | coverageReporter: {
|
47 | dir: 'coverage',
|
48 | subdir: 'report'
|
49 | // Would output the results into: .'/coverage/report/'
|
50 | }
|
51 | ```
|
52 |
|
53 | ```javascript
|
54 | coverageReporter: {
|
55 | dir: 'coverage',
|
56 | subdir: function(browser) {
|
57 | // normalization process to keep a consistent browser name across different
|
58 | // OS
|
59 | return browser.toLowerCase().split(/[ /-]/)[0];
|
60 | }
|
61 | // Would output the results into: './coverage/firefox/'
|
62 | }
|
63 | ```
|
64 |
|
65 | ### `file`
|
66 |
|
67 | **Type:** String
|
68 |
|
69 | **Description:** If you use one of these reporters, `cobertura`, `lcovonly`, `teamcity`, `text` or `text-summary`,you may set the `file` option to specify the output file.
|
70 |
|
71 | ```javascript
|
72 | coverageReporter: {
|
73 | type : 'text',
|
74 | dir : 'coverage/',
|
75 | file : 'coverage.txt'
|
76 | }
|
77 | ```
|
78 |
|
79 | ### `check`
|
80 |
|
81 | **Type:** Object
|
82 |
|
83 | **Description:** This will be used to configure minimum threshold enforcement for coverage results. If the thresholds are not met, karma will return failure. Thresholds, when specified as a positive number are taken to be the minimum percentage required. When a threshold is specified as a negative number it represents the maximum number of uncovered entities allowed.
|
84 |
|
85 | For example, `statements: 90` implies minimum statement coverage is 90%. `statements: -10` implies that no more than 10 uncovered statements are allowed.
|
86 |
|
87 | `global` applies to all files together and `each` on a per-file basis. A list of files or patterns can be excluded from enforcement via the `exclude` property. On a per-file or pattern basis, per-file thresholds can be overridden via the `overrides` property.
|
88 |
|
89 | ```javascript
|
90 | coverageReporter: {
|
91 | check: {
|
92 | global: {
|
93 | statements: 50,
|
94 | branches: 50,
|
95 | functions: 50,
|
96 | lines: 50,
|
97 | excludes: [
|
98 | 'foo/bar/**/*.js'
|
99 | ]
|
100 | },
|
101 | each: {
|
102 | statements: 50,
|
103 | branches: 50,
|
104 | functions: 50,
|
105 | lines: 50,
|
106 | excludes: [
|
107 | 'other/directory/**/*.js'
|
108 | ],
|
109 | overrides: {
|
110 | 'baz/component/**/*.js': {
|
111 | statements: 98
|
112 | }
|
113 | }
|
114 | }
|
115 | }
|
116 | }
|
117 | ```
|
118 |
|
119 | ### `watermarks`
|
120 |
|
121 | **Type:** Object
|
122 |
|
123 | **Description:** This will be used to set the coverage threshold colors. The first number is the threshold between Red and Yellow. The second number is the threshold between Yellow and Green.
|
124 |
|
125 | ```javascript
|
126 | coverageReporter: {
|
127 | watermarks: {
|
128 | statements: [ 50, 75 ],
|
129 | functions: [ 50, 75 ],
|
130 | branches: [ 50, 75 ],
|
131 | lines: [ 50, 75 ]
|
132 | }
|
133 | }
|
134 | ```
|
135 |
|
136 | ### `includeAllSources`
|
137 |
|
138 | **Type:** Boolean
|
139 |
|
140 | **Description:** You can opt to include all sources files, as indicated by the coverage preprocessor, in your code coverage data, even if there are no tests covering them. (Default `false`)
|
141 |
|
142 | ```javascript
|
143 | coverageReporter: {
|
144 | type : 'text',
|
145 | dir : 'coverage/',
|
146 | file : 'coverage.txt',
|
147 | includeAllSources: true
|
148 | }
|
149 | ```
|
150 |
|
151 | ### `sourceStore`
|
152 |
|
153 | **Type:** istanbul.Store
|
154 |
|
155 | **Description:** You can opt to specify a source store allowing for external coverage collectors access to the instrumented code.
|
156 |
|
157 | ```javascript
|
158 | coverageReporter: {
|
159 | type : 'text',
|
160 | dir : 'coverage/',
|
161 | file : 'coverage.txt',
|
162 | sourceStore : require('istanbul').Store.create('fslookup')
|
163 | }
|
164 | ```
|
165 |
|
166 | ### `reporters`
|
167 |
|
168 | **Type:** Array of Objects
|
169 |
|
170 | **Description:** You can use multiple reporters, by providing array of options.
|
171 |
|
172 | ```javascript
|
173 | coverageReporter: {
|
174 | reporters:[
|
175 | {type: 'html', dir:'coverage/'},
|
176 | {type: 'teamcity'},
|
177 | {type: 'text-summary'}
|
178 | ],
|
179 | }
|
180 | ```
|
181 |
|
182 | ### `instrumenter`
|
183 |
|
184 | **Type:** Object
|
185 |
|
186 | **Description:** Karma-coverage can infers the instrumenter regarding of the file extension. It is possible to override this behavior and point out an
|
187 | instrumenter for the files matching a specific pattern.
|
188 | To do so, you need to declare an object under with the keys represents the
|
189 | pattern to match, and the instrumenter to apply. The matching will be done
|
190 | using [minimatch](https://github.com/isaacs/minimatch).
|
191 | If two patterns match, the last one will take the precedence.
|
192 |
|
193 | For example you can use [Ibrik](https://github.com/Constellation/ibrik) (an
|
194 | [Istanbul](https://github.com/gotwarlost/istanbul) analog for
|
195 | CoffeeScript files) with:
|
196 |
|
197 | ```javascript
|
198 | coverageReporter: {
|
199 | instrumenters: { ibrik : require('ibrik') },
|
200 | instrumenter: {
|
201 | '**/*.coffee': 'ibrik'
|
202 | },
|
203 | // ...
|
204 | }
|
205 | ```
|
206 |
|
207 | You can pass options additional options to specific instrumenter with:
|
208 |
|
209 | ```javascript
|
210 | var to5Options = { experimental: true };
|
211 |
|
212 | // [...]
|
213 |
|
214 | coverageReporter: {
|
215 | instrumenters: { isparta : require('isparta') },
|
216 | instrumenter: {
|
217 | '**/*.js': 'isparta'
|
218 | },
|
219 | instrumenterOptions: {
|
220 | isparta: { to5 : to5Options }
|
221 | }
|
222 | }
|
223 | ```
|
224 |
|
225 | ### `useJSExtensionForCoffeeScript`
|
226 |
|
227 | **Type:** boolean
|
228 |
|
229 | **Description:** If set to `true`, then CoffeeScript files instrumented
|
230 | with [Ibrik](https://github.com/Constellation/ibrik) will use the `.js`
|
231 | extension for the transpiled source (without this option, the JavaScript
|
232 | files will keep the original `.coffee` extension). This option is required
|
233 | if you use a module loader such as [RequireJS](http://requirejs.org/) that
|
234 | expects files to use a `.js` extension.
|
235 |
|
236 | Example of using RequireJS with CoffeeScript:
|
237 |
|
238 | ```coffeescript
|
239 | coverageReporter:
|
240 | useJSExtensionForCoffeeScript: true
|
241 | instrumenters:
|
242 | ibrik : require('ibrik')
|
243 | instrumenter:
|
244 | '**/*.coffee': 'ibrik'
|
245 | # ...
|
246 | ```
|
247 |
|
248 | ### `reporter[type='in-memory']`
|
249 |
|
250 | This is a different kind of reporter. Instead of writing a report physicaly
|
251 | to disk, it raises an event `coverage_complete`. This event can only be caught
|
252 | when using karma via the [public api](http://karma-runner.github.io/0.13/dev/public-api.html)
|
253 |
|
254 | ```javascript
|
255 | var Server = require('karma').Server
|
256 | var server = new Server({files: [/*...*/], port: 9876, coverageReporter: { type: 'in-memory' }, preprocessors: { '**/*.js': 'coverage' }, reporters: ['coverage'] }, function(exitCode) {
|
257 | console.log('Karma has exited with ' + exitCode)
|
258 | process.exit(exitCode)
|
259 | })
|
260 |
|
261 | server.on('coverage_complete', function (browser, coverageReport) {
|
262 | console.log('Covrage report: ', coverageReport)
|
263 | })
|
264 |
|
265 | server.start();
|
266 |
|
267 | karma.runner.run({port: 9876});
|
268 | ```
|
269 |
|
270 | The coverage report will be a merged result in json format. |
\ | No newline at end of file |