source: trip-planner-front/node_modules/karma-coverage/docs/configuration.md@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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