Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude pattern or folder in istanbul coverage

I have an istanbul coverage that i use in my package.json like below.

"test:coverage": "./node_modules/.bin/babel-istanbul --include-all-sources cover ./node_modules/.bin/_mocha ./src/**/__tests__/*.js",

And i jave an .istanbul.yml script like below.

verbose: true
instrumentation:
    extension: .js
    root: ./src
    default-excludes: true
    excludes: ['./src/**/__tests__/**', './src/electron.js']
    embed-source: false
    variable: __coverage__
    compact: true
    preserve-comments: false
    complete-copy: false
    save-baseline: false
    baseline-file: ./coverage/coverage-baseline.json
reporting:
    print: summary
    reports:
        - lcov
    dir: ./coverage
    watermarks:
        statements: [50, 80]
        lines: [50, 80]
        functions: [50, 80]
        branches: [50, 80]
hooks:
    hook-run-in-context: false
    post-require-hook: null

I am trying to exclude the tests folder and the electron.js files from the coverage. However , the file and the folder are not excluding. Please where do i go wrong and how can i fix this ? Any help would be appreciated.

like image 351
Nuru Salihu Avatar asked Oct 19 '25 21:10

Nuru Salihu


2 Answers

Incase if some one is still having this issue. Below is how i solved mine by modifying

instrumentation:
  root: src
  include-all-sources: true
  verbose: true
  excludes: ["**/__tests__/**" ,"./electron.js"]
reporting:
  dir: "coverage"
like image 54
Nuru Salihu Avatar answered Oct 22 '25 06:10

Nuru Salihu


What worked for us was adding the exclude syntax in our babel config:

plugins: [
    [
      'istanbul',
      {
        exclude: ['**/example/**/**/*'],
      },
    ],
  ],

We clearly hand't read thoroughly the docs! https://github.com/istanbuljs/babel-plugin-istanbul#ignoring-files

like image 35
gkri Avatar answered Oct 22 '25 05:10

gkri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!