1 | gulp-istanbul [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
|
2 | ===========================
|
3 |
|
4 | [Istanbul][istanbul] unit test coverage plugin for [gulp][gulp].
|
5 |
|
6 | Works on top of any Node.js unit test framework.
|
7 |
|
8 | Installation
|
9 | ---------------
|
10 |
|
11 | ```shell
|
12 | npm install --save-dev gulp-istanbul
|
13 | ```
|
14 |
|
15 | Example
|
16 | ---------------
|
17 |
|
18 | Then, add it to your `gulpfile.js`:
|
19 |
|
20 | ```javascript
|
21 | var istanbul = require('gulp-istanbul');
|
22 | var mocha = require('gulp-mocha'); // Using mocha here, but any test framework will work
|
23 |
|
24 | gulp.task('test', function (cb) {
|
25 | gulp.src(['lib/**/*.js', 'main.js'])
|
26 | .pipe(istanbul()) // Covering files
|
27 | .on('finish', function () {
|
28 | gulp.src(['test/*.js'])
|
29 | .pipe(mocha())
|
30 | .pipe(istanbul.writeReports()) // Creating the reports after tests runned
|
31 | .on('end', cb);
|
32 | });
|
33 | });
|
34 | ```
|
35 |
|
36 | API
|
37 | --------------
|
38 |
|
39 | ### istanbul(opt)
|
40 |
|
41 | Instrument files passed in the stream.
|
42 |
|
43 | #### opt
|
44 | Type: `Object` (optional)
|
45 | ```js
|
46 | {
|
47 | coverageVariable: 'someVariable',
|
48 | ...other Instrumeter options...
|
49 | }
|
50 | ```
|
51 |
|
52 | ##### coverageVariable
|
53 | Type: `String` (optional)
|
54 | Default: `'$$cov_' + new Date().getTime() + '$$'`
|
55 |
|
56 | The global variable istanbul uses to store coverage
|
57 |
|
58 | See also:
|
59 | - [istanbul coverageVariable][istanbul-coverage-variable]
|
60 | - [SanboxedModule][sandboxed-module-coverage-variable]
|
61 |
|
62 | ##### includeUntested
|
63 | Type: `Boolean` (optional)
|
64 | Default: `false`
|
65 |
|
66 | Flag to include test coverage of files that aren't `require`d by any tests
|
67 |
|
68 | See also:
|
69 | - [istanbul "0% coverage" issue](https://github.com/gotwarlost/istanbul/issues/112)
|
70 |
|
71 | ##### Other Istanbul Instrutrumenter options
|
72 |
|
73 | See:
|
74 | - [istanbul Instrumenter documentation][istanbul-coverage-variable]
|
75 |
|
76 |
|
77 | ### istanbul.summarizeCoverage(opt)
|
78 |
|
79 | get coverage summary details
|
80 |
|
81 | #### opt
|
82 | Type: `Object` (optional)
|
83 | ```js
|
84 | {
|
85 | coverageVariable: 'someVariable'
|
86 | }
|
87 | ```
|
88 | ##### coverageVariable
|
89 | Type: `String` (optional)
|
90 | Default: `'$$cov_' + new Date().getTime() + '$$'`
|
91 |
|
92 | The global variable istanbul uses to store coverage
|
93 |
|
94 | See also:
|
95 | - [istanbul coverageVariable][istanbul-coverage-variable]
|
96 | - [SanboxedModule][sandboxed-module-coverage-variable]
|
97 |
|
98 | #### returns
|
99 | Type: `Object`
|
100 | ```js
|
101 | {
|
102 | lines: { total: 4, covered: 2, skipped: 0, pct: 50 },
|
103 | statements: { total: 4, covered: 2, skipped: 0, pct: 50 },
|
104 | functions: { total: 2, covered: 0, skipped: 0, pct: 0 },
|
105 | branches: { total: 0, covered: 0, skipped: 0, pct: 100 }
|
106 | }
|
107 | ```
|
108 |
|
109 | See also:
|
110 | - [istanbul utils.summarizeCoverage()][istanbul-summarize-coverage]
|
111 |
|
112 |
|
113 | ### istanbul.writeReports(opt)
|
114 |
|
115 | Create the reports on stream end.
|
116 |
|
117 | #### opt
|
118 | Type: `Object` (optional)
|
119 | ```js
|
120 | {
|
121 | dir: './coverage',
|
122 | reporters: [ 'lcov', 'json', 'text', 'text-summary' ],
|
123 | reportOpts: { dir: './coverage' },
|
124 | coverageVariable: 'someVariable'
|
125 | }
|
126 | ```
|
127 |
|
128 | #### dir
|
129 | Type: `String` (optional)
|
130 | Default: `./coverage`
|
131 |
|
132 | The folder in which the reports are to be outputted.
|
133 |
|
134 | #### reporters
|
135 | Type: `Array` (optional)
|
136 | Default: `[ 'lcov', 'json', 'text', 'text-summary' ]`
|
137 |
|
138 | The list of reporters to use, one of:
|
139 | - 'clover'
|
140 | - 'cobertura'
|
141 | - 'html'
|
142 | - 'json'
|
143 | - 'lcov'
|
144 | - 'lcovonly'
|
145 | - 'none'
|
146 | - 'teamcity'
|
147 | - 'text'
|
148 | - 'text-summary'
|
149 |
|
150 | See also `require('istanbul').Report.getReportList()`
|
151 |
|
152 | ##### coverageVariable
|
153 | Type: `String` (optional)
|
154 | Default: `'$$cov_' + new Date().getTime() + '$$'`
|
155 |
|
156 | The global variable istanbul uses to store coverage
|
157 |
|
158 | See also:
|
159 | - [istanbul coverageVariable][istanbul-coverage-variable]
|
160 | - [SanboxedModule][sandboxed-module-coverage-variable]
|
161 |
|
162 | License
|
163 | ------------
|
164 |
|
165 | [MIT License](http://en.wikipedia.org/wiki/MIT_License) (c) Simon Boudrias - 2013
|
166 |
|
167 | [istanbul]: http://gotwarlost.github.io/istanbul/
|
168 | [gulp]: https://github.com/gulpjs/gulp
|
169 |
|
170 | [npm-url]: https://npmjs.org/package/gulp-istanbul
|
171 | [npm-image]: https://badge.fury.io/js/gulp-istanbul.svg
|
172 |
|
173 | [travis-url]: http://travis-ci.org/SBoudrias/gulp-istanbul
|
174 | [travis-image]: https://secure.travis-ci.org/SBoudrias/gulp-istanbul.svg?branch=master
|
175 |
|
176 | [depstat-url]: https://david-dm.org/SBoudrias/gulp-istanbul
|
177 | [depstat-image]: https://david-dm.org/SBoudrias/gulp-istanbul.svg
|
178 |
|
179 | [istanbul-coverage-variable]: http://gotwarlost.github.io/istanbul/public/apidocs/classes/Instrumenter.html
|
180 | [istanbul-summarize-coverage]: http://gotwarlost.github.io/istanbul/public/apidocs/classes/ObjectUtils.html#method_summarizeCoverage
|
181 | [sandboxed-module-coverage-variable]: https://github.com/felixge/node-sandboxed-module/blob/master/lib/sandboxed_module.js#L240
|