UNPKG

4.42 kBMarkdownView Raw
1gulp-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
6Works on top of any Node.js unit test framework.
7
8Installation
9---------------
10
11```shell
12npm install --save-dev gulp-istanbul
13```
14
15Example
16---------------
17
18Then, add it to your `gulpfile.js`:
19
20```javascript
21var istanbul = require('gulp-istanbul');
22var mocha = require('gulp-mocha'); // Using mocha here, but any test framework will work
23
24gulp.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
36API
37--------------
38
39### istanbul(opt)
40
41Instrument files passed in the stream.
42
43#### opt
44Type: `Object` (optional)
45```js
46{
47 coverageVariable: 'someVariable',
48 ...other Instrumeter options...
49}
50```
51
52##### coverageVariable
53Type: `String` (optional)
54Default: `'$$cov_' + new Date().getTime() + '$$'`
55
56The global variable istanbul uses to store coverage
57
58See also:
59- [istanbul coverageVariable][istanbul-coverage-variable]
60- [SanboxedModule][sandboxed-module-coverage-variable]
61
62##### includeUntested
63Type: `Boolean` (optional)
64Default: `false`
65
66Flag to include test coverage of files that aren't `require`d by any tests
67
68See also:
69- [istanbul "0% coverage" issue](https://github.com/gotwarlost/istanbul/issues/112)
70
71##### Other Istanbul Instrutrumenter options
72
73See:
74- [istanbul Instrumenter documentation][istanbul-coverage-variable]
75
76
77### istanbul.summarizeCoverage(opt)
78
79get coverage summary details
80
81#### opt
82Type: `Object` (optional)
83```js
84{
85 coverageVariable: 'someVariable'
86}
87```
88##### coverageVariable
89Type: `String` (optional)
90Default: `'$$cov_' + new Date().getTime() + '$$'`
91
92The global variable istanbul uses to store coverage
93
94See also:
95- [istanbul coverageVariable][istanbul-coverage-variable]
96- [SanboxedModule][sandboxed-module-coverage-variable]
97
98#### returns
99Type: `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
109See also:
110- [istanbul utils.summarizeCoverage()][istanbul-summarize-coverage]
111
112
113### istanbul.writeReports(opt)
114
115Create the reports on stream end.
116
117#### opt
118Type: `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
129Type: `String` (optional)
130Default: `./coverage`
131
132The folder in which the reports are to be outputted.
133
134#### reporters
135Type: `Array` (optional)
136Default: `[ 'lcov', 'json', 'text', 'text-summary' ]`
137
138The 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
150See also `require('istanbul').Report.getReportList()`
151
152##### coverageVariable
153Type: `String` (optional)
154Default: `'$$cov_' + new Date().getTime() + '$$'`
155
156The global variable istanbul uses to store coverage
157
158See also:
159- [istanbul coverageVariable][istanbul-coverage-variable]
160- [SanboxedModule][sandboxed-module-coverage-variable]
161
162License
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