Gathering detailed insights and metrics for grunt-mocha-istanbul
Gathering detailed insights and metrics for grunt-mocha-istanbul
Gathering detailed insights and metrics for grunt-mocha-istanbul
Gathering detailed insights and metrics for grunt-mocha-istanbul
grunt-mocha-istanbul-extra
Almost config-free Istanbul code coverage reporter for Mocha usage in Grunt. Fully compliant with grunt-mocha-istanbule but more customizeable
grunt-mocha-phantom-istanbul
Grunt task for running mocha specs in a headless browser (PhantomJS) and generating code coverage from Istanbul instrumented source
grunt-mocha-phantom-istanbul-patch
Grunt task for running mocha specs in a headless browser (PhantomJS) and generating code coverage from Istanbul instrumented source
grunt-mocha-babel-istanbul
Almost config-free Istanbul code coverage reporter for Mocha usage in Grunt
Almost config-free Istanbul code coverage reporter for Mocha usage in Grunt
npm install grunt-mocha-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
75 Stars
88 Commits
23 Forks
3 Watchers
2 Branches
1 Contributors
Updated on Dec 09, 2022
Latest Version
5.0.2
Package Id
grunt-mocha-istanbul@5.0.2
Size
8.44 kB
NPM Version
3.10.5
Node Version
6.3.1
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
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 istanbul --save-dev
npm install grunt-mocha-istanbul --save-dev
Gruntfile.js
: grunt.loadNpmTasks('grunt-mocha-istanbul')
Although it's intended for use with Istanbul, you can freely
use this task with other command line compatible tool, by changing the scriptPath
option, such as:
1grunt.initConfig({
2 mocha_istanbul: {
3 target: {
4 options: {
5 scriptPath: require.resolve('coverage-tool/the/path/to/bin'), // usually in nameofcoveragelibrary/lib/cli
6 }
7 }
8 }
9});
Before anything, install babel required stuff.
npm install babel-cli babel-presets-2015 babel-register
Define your .babelrc file on the same level as Gruntfile.js
1{ 2 "presets": ["es2015"] 3}
Then you'll need to use Isparta, until Istanbul 1.0 is released. (or you can use 1.0.0-alpha.2)
1{ 2 mocha_istanbul: { 3 src: 'test', 4 options: { 5 scriptPath: require.resolve('isparta/lib/cli'), 6 nodeExec: require.resolve('.bin/babel-node') // for Windows, you MUST use .bin/babel-node.cmd instead 7 mochaOptions: ['--compilers', 'js:babel-register'], // if you are writing your tests with ES2015+ as well 8 } 9 } 10}
NOTE: for some unknown reason, using babel-node as nodeExec, with print
option makes it fail.
Most of the options that you pass to mocha is available in options
:
1module.exports = function(grunt){
2 grunt.initConfig({
3 mocha_istanbul: {
4 coverage: {
5 src: 'test', // a folder works nicely
6 options: {
7 mask: '*.spec.js'
8 }
9 },
10 coverageSpecial: {
11 src: ['testSpecial/*/*.js', 'testUnique/*/*.js'], // specifying file patterns works as well
12 options: {
13 coverageFolder: 'coverageSpecial',
14 mask: '*.spec.js',
15 mochaOptions: ['--harmony','--async-only'], // any extra options
16 istanbulOptions: ['--harmony','--handle-sigint']
17 }
18 },
19 coveralls: {
20 src: ['test', 'testSpecial', 'testUnique'], // multiple folders also works
21 options: {
22 coverage:true, // this will make the grunt.event.on('coverage') event listener to be triggered
23 check: {
24 lines: 75,
25 statements: 75
26 },
27 root: './lib', // define where the cover task should consider the root of libraries that are covered by tests
28 reportFormats: ['cobertura','lcovonly']
29 }
30 }
31 },
32 istanbul_check_coverage: {
33 default: {
34 options: {
35 coverageFolder: 'coverage*', // will check both coverage folders and merge the coverage results
36 check: {
37 lines: 80,
38 statements: 80
39 }
40 }
41 }
42 }
43
44 });
45
46 grunt.event.on('coverage', function(lcovFileContents, done){
47 // Check below on the section "The coverage event"
48 done();
49 });
50
51 grunt.loadNpmTasks('grunt-mocha-istanbul');
52
53 grunt.registerTask('coveralls', ['mocha_istanbul:coveralls']);
54 grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
55};
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.
Mochas parameters, check https://mochajs.org/#usage
Type: Array
Default Value: []
Type: Boolean
Default Value: false
Type: Array
Default Value: []
Type: String
Default Value: false
Type: Number
Default Value: false
Type: Boolean
Default Value: false
Type: String
Default Value: false
Type: Boolean
Default Value: false
Type: Boolean
Default Value: false
Type: Array
Default Value: false
An array of strings, any additional node executable parameters, manually set.
Eg.: nodeOptions: ['--throw-deprecation', '--require', 'some/module']
Type: String
Default Value: 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.
Type: Array
Default Value: false
An array of strings, any additional mocha parameters, manually set.
Eg.: mochaOptions: ['--harmony', '-s', '100']
Type: Array
Default Value: false
Setting this exclude files from coverage report, check istanbul help cover
. You may use glob matching in here.
Type: Array
Default Value: false
Setting this includes only those files in the coverage report, check istanbul help cover
. You may use glob matching in here.
Type: Array
Default Value: false
An array of strings, any additional istanbul parameters, manually set.
Eg.: istanbulOptions: ['--harmony', '--handle-sigint', 'some=value', '-s', 'value']
Type: String
Default Value: 'coverage'
Name of the output of the coverage folder
Type: Array
Default Value: ['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
Type: String
Default Value: 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.
Type: String
Default Value: 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.
Type: String
Default Value: '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
.
Type: Boolean
Default Value: 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
Type: Boolean
Default Value: false
Spits out the command line that would be called, just to make sure everything is alright
Type: String
Default Value: process.execPath
Sets the node executable that will invoke Istanbul and Mocha. Useful for setting something else than node, like babel-node
Type: String
Default Value: process.cwd()
Sets the current working directly. Note that changing this might have unexpected results, since the plugin and Grunt expects
to be working on the same level of Gruntfile.js
Type: Boolean
Default Value: false
Suppresses the output from Mocha and Istanbul
Type: Number
Default Value: false
Number of statements threshold to consider the coverage valid
Type: Number
Default Value: false
Number of lines threshold to consider the coverage valid
Type: Number
Default Value: false
Number of branches threshold to consider the coverage valid
Type: Number
Default Value: 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.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More