Gathering detailed insights and metrics for grunt-mocha-babel-istanbul
Gathering detailed insights and metrics for grunt-mocha-babel-istanbul
Gathering detailed insights and metrics for grunt-mocha-babel-istanbul
Gathering detailed insights and metrics for grunt-mocha-babel-istanbul
Almost config-free Istanbul code coverage reporter for Mocha usage in Grunt
npm install grunt-mocha-babel-istanbul
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
66 Commits
1 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Jun 24, 2015
Latest Version
2.5.0
Package Id
grunt-mocha-babel-istanbul@2.5.0
Size
7.30 kB
NPM Version
2.10.1
Node Version
0.12.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Mocha reporter to generate coverage report of istanbul instrumented code, for grunt This doesn't force you to use PhantomJS, or instrument code for server or client-side.
npm install grunt-mocha-babel-istanbul --save-dev
mocha
, grunt
and istanbul
to be installed locally on your project (aka, having them in your devDependencies)grunt.loadNpmTasks('grunt-mocha-istanbul')
Since Istanbul has 2 versions (ES5 and ES6/harmony), it's up to you to install the desired version of Istanbul, it's now defined as a a peer dependency.
Introduced new task istanbul_check_coverage
to enable coverage checking on more than one test run. See below for example.
mocha_istanbul_check
was removed and became part of the options under the check
objectMost of the options that you pass to mocha is available in options
:
1
2module.exports = function(grunt){
3 grunt.initConfig({
4 mocha_istanbul: {
5 coverage: {
6 src: 'test', // a folder works nicely
7 options: {
8 mask: '*.spec.js'
9 }
10 },
11 coverageSpecial: {
12 src: ['testSpecial/*/*.js', 'testUnique/*/*.js'], // specifying file patterns works as well
13 options: {
14 coverageFolder: 'coverageSpecial',
15 mask: '*.spec.js',
16 mochaOptions: ['--harmony','--async-only'], // any extra options
17 istanbulOptions: ['--harmony','--handle-sigint']
18 }
19 },
20 coveralls: {
21 src: ['test', 'testSpecial', 'testUnique'], // multiple folders also works
22 options: {
23 coverage:true, // this will make the grunt.event.on('coverage') event listener to be triggered
24 check: {
25 lines: 75,
26 statements: 75
27 },
28 root: './lib', // define where the cover task should consider the root of libraries that are covered by tests
29 reportFormats: ['cobertura','lcovonly']
30 }
31 }
32 },
33 istanbul_check_coverage: {
34 default: {
35 options: {
36 coverageFolder: 'coverage*', // will check both coverage folders and merge the coverage results
37 check: {
38 lines: 80,
39 statements: 80
40 }
41 }
42 }
43 }
44
45 });
46
47 grunt.event.on('coverage', function(lcovFileContents, done){
48 // Check below on the section "The coverage event"
49 done();
50 });
51
52 grunt.loadNpmTasks('grunt-mocha-babel-istanbul');
53
54 grunt.registerTask('coveralls', ['mocha_istanbul:coveralls']);
55 grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
56};
If there's a mocha.opts
file inside the first src
folder or file defined, it will warn if you are overwriting any options.
Coverage is written to coverage
folder by default, in the same level as the Gruntfile.js
The check
will fail the build if the thresholds are not met. It's a great possibility for CI-builds.
options.require
(default: []
)options.ui
(default: false
)options.globals
(default: []
)options.reporter
(default: false
)options.timeout
(default: false
)options.slow
(default: false
)options.grep
(default: false
)options.recursive
(default: false
)options.noColors
(default: false
)Mochas parameters, check [http://visionmedia.github.io/mocha/#usage]
options.mochaOptions
(default: false
)An array of strings, any additional mocha parameters, manually set. Eg.: ['--harmony']
options.istanbulOptions
(default: false
)An array of strings, any additional istanbul parameters, manually set. Eg.: ['--harmony', '--handle-sigint']
options.scriptPath
(default: istanbulPath
)Allows to override the default istanbul path to use another coverage library, such as ibrik. Need to set the full path to the bin (script that accepts stdin arguments) and is compatible with cover
.
options.coverage
(default: false
)Setting this to true makes the task emit a grunt event coverage
, that will contain the lcov data from
the file, containing the following callback function(lcovcontent, done)
, and you must manually call
done()
when you are finished, else the grunt task will HANG, and won't allow any other tasks to finish. See more information below
options.dryRun
(default: false
)Spits out the command line that would be called, just to make sure everything is alright
options.excludes
(default: false
)Setting this exclude files from coverage report, check istanbul help cover
. You may use glob matching in here.
options.mask
(default: false
)The mask for the tests to be ran. By default, mocha will execute the test
folder and all test files. Will override any files specified in src
and instead use the mask on those files' folders.
options.quiet
(default: false
)Suppresses the output from Mocha and Istanbul
options.coverageFolder
(default: coverage
)Name of the output of the coverage folder
options.reportFormats
(default: ['lcov']
)Name of report formats. You can specify more than one. If you intend to use the coverage
option to
true
or do any checks, you must add: ['yourformat','lcovonly']
, since it's needed for the lcov.info
file to be created.
html - produces a bunch of HTML files with annotated source code
lcovonly - produces an lcov.info file
lcov - produces html + lcov files. This is the default format
cobertura - produces a cobertura-coverage.xml file for easy Hudson integration
text-summary - produces a compact text summary of coverage, typically to console
text - produces a detailed text table with coverage for all files
teamcity - produces service messages to report code coverage to TeamCity
options.root
(default: false
)The root path to look for files to instrument, defaults to .
. Can help to exclude directories that are not
part of the code whose coverage should be checked.
options.print
(default: false
)The type of report to print to console. Can be one of 'summary', 'detail', 'both', or 'none'. By default, Istanbul will print the 'summary' report.
options.check.statements
(default: false
)Number of statements threshold to consider the coverage valid
options.check.lines
(default: false
)Number of lines threshold to consider the coverage valid
options.check.branches
(default: false
)Number of branches threshold to consider the coverage valid
options.check.functions
(default: false
)Number of functions threshold to consider the coverage valid
When you set the option coverage
to true
, you'll receive the coverage/lcov.info
file contents:
1grunt.event.on('coverage', function(lcov, done){ 2 console.log(lcov); 3 done(); // or done(false); in case of error 4});
This is mainly useful so you can send it to, for example, coveralls (using coveralls):
1grunt.event.on('coverage', function(lcov, done){ 2 require('coveralls').handleInput(lcov, function(err){ 3 if (err) { 4 return done(err); 5 } 6 done(); 7 }); 8});
This way, Travis-CI can send the Istanbul generated LCOV directly to Coveralls.io website in this example, but you could create any transform for Jenkins, TeamCity, Hudson, etc.
No vulnerabilities found.
No security vulnerabilities found.