grunt-contrib-jasmine, using istanbulCode coverage template mix-in for
npm install grunt-template-jasmine-istanbul --save-dev
The file path where to store the
String | Object | Array
String is given, it will be used as the path where a HTML report is generated.
Object is given, it must have the properties
type is a
options are used to create the report by passing it to
For example, if you want to generate a Cobertura report at
bin/coverage/cobertura, use this:
report:type: 'cobertura'options:dir: 'bin/coverage/cobertura'
Array is given, it must consist of
Objects of the form just described.
The supported types are:
A globbing pattern or multiple patterns for the source files to instrument.
All source files that do match will be instrumented, those who don't won't.
['**/*', '!src/main/js/uninteresting.js'] will result in all source files being instrumented except
Whether or not the
src scripts are replaced by the paths to their instrumented versions.
This is useful when you want the mixed-in template to work with the original sources, and you want to serve the instrumented sources by redirecting request on the server side.
If you don't want the sources to be replaced, set it to
If it is a function, it receives the arguments
source which represent the URI to the instrumented file and the uninstrumented file respectively, relative to the directory specified by
Thresholds for any of the metrics that Istanbul measures. If a threshold is not met, a warning is emitted. See example below for available metrics.
String | Object
Default: jasmine's default template
The template to mix-in coverage.
The options to pass to the mixed-in template.
There are multiple examples at a example repository.
Have a look at this example.
// Example configurationgrunt
Is it really that easy?
baseUrl to that location may screw up your whole configuration, because paths relative to the original sources are broken.
Therefore, if this happens to you, instead of directly loading the instrumented sources, set
replace: false, intercept request to the original sources and redirect them to the instrumented versions.
You can do this on both the client side, or the server side.
Look at the corresponding
Grunfile.js files and be filled with horror: Yes, this is nasty, but it (seems to) works.
Do you have another template you want to use, but you also want to collect code coverage at the same time?
Then you can use a mixed-in template, that's what they are for.
The idea behind a mixed-in template is simple:
Istanbul generates code coverage information by instrumenting the sources before they are run and by generating reports after they have run.
Therefore this templates acts as a test pre- and post-processor, but it doesn't interfere with the actual running of the tests.
This makes it possible to use another template as a mix-in template to run the tests, defined by
templateOptions.template and can be configured with
A Single Requirement
A mixed-in template needs to load the instrumented sources in order for the coverage reports to be correctly generated.
This template copies instrumented versions of the sources to a temporary location at
If your mixed-in template simply includes the sources, as the default template does, you don't need to account for that, since this template replaces the
src option with the paths to the instrumented versions.
If your mixed-in template loads the sources differently, e.g. directly from the file system, you may need to reconfigure the mixed-in template.
- v0.5.0, 01.06.16, Upgrade
gruntand dev deps to work with the latest version of Grunt 1.0, use caret qualifier for versions
- v0.4.0, 09.11.15, Upgrade
lodashto only use
- v0.3.4, 28.06.15, closes #40, Don't throw error in reporter if coverage was not run.
- v0.3.3, 27.01.15, closes #36, require lodash 3
- v0.3.2, 23.01.15, closes #33 and #28
- v0.3.1, 02.02.14, closes #14 and #17, added
filesoption and function support for
- v0.3.0, 02.02.14, fixes #18 and #26, now requires grunt-contrib-jasmine v0.6.0
- v0.2.6, 02.02.14, merged #13 from @llacroix, windows paths are converted to URIs
- v0.2.5, 10.08.13, reporter is now moved to and loaded from jasmine's temporary directory, fixes #11
- v0.2.4, 26.05.13, merged #12 from @kayhadrin, instrumented versions of files loaded via absolute paths on windows are now created at a valid path
- v0.2.3, 12.05.13, merged
thresholdsfrom @larsthorup #9 which can abort a build with too low coverage
- v0.2.2, 11.05.13, added
replaceoption, so it can be prevented that the original
srcoption is replaced with their instrumented versions