Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding files from coverage when using Mocha and Istanbul

How can I exclude folders and files (by path) from coverage report when using mocha and instanbul?

I want to exclude by a configuration and not

/*istanbul ignore next*/ 

in each file.

(The generated report use by Jenkins)

Thanks,

like image 310
Shai M. Avatar asked May 19 '15 13:05

Shai M.


People also ask

How do I ignore in Istanbul?

It is up to the caller to scope this as narrowly as possible. For example, if you have a source file that is wrapped in a function expression, adding /* istanbul ignore next */ at the top of the file will ignore the whole file!


2 Answers

You can ignore files matching a certain pattern using the -x parameter.

 istanbul help cover   ...  -x <exclude-pattern> [-x <exclude-pattern>]         one or more fileset patterns e.g. "**/vendor/**"  ... 
like image 130
Blaise Avatar answered Sep 29 '22 00:09

Blaise


If you run istanbul help config you'll see istanbul's default configuration. You can copy/paste the default config into a .istanbul.yml file at the root of your source tree, then store the exclusions in it.

Here's what mine looks like (this makes it easy to exclude many directories):

verbose: false instrumentation:     root: .     extensions:         - .js     default-excludes: true     excludes: ['**/tinymce/**', '**/lib/**', '**/tools/**', '**/build/**']     embed-source: false     variable: __coverage__     compact: true     preserve-comments: false     complete-copy: false     save-baseline: false     baseline-file: ./coverage/coverage-baseline.json     include-all-sources: true     include-pid: false     es-modules: false reporting:     print: summary     reports:         - lcov     dir: ./tools/coverage     watermarks:         statements: [50, 80]         lines: [50, 80]         functions: [50, 80]         branches: [50, 80]     report-config:         clover: {file: clover.xml}         cobertura: {file: cobertura-coverage.xml}         json: {file: coverage-final.json}         json-summary: {file: coverage-summary.json}         lcovonly: {file: lcov.info}         teamcity: {file: null, blockName: Code Coverage Summary}         text: {file: null, maxCols: 0}         text-lcov: {file: lcov.info}         text-summary: {file: null} hooks:     hook-run-in-context: false     post-require-hook: null     handle-sigint: false check:     global:         statements: 0         lines: 0         branches: 0         functions: 0         excludes: []     each:         statements: 0         lines: 0         branches: 0         functions: 0         excludes: [] 
like image 41
Rob Johansen Avatar answered Sep 29 '22 00:09

Rob Johansen