Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest coverage ignore

I'm trying to ignore a couple of files from my code coverage output. On reading the docs coveragePathIgnorePatterns it looks like I can ignore folders.

I'm trying to ignore dummy and helpers folders from my coverage, but they seem to always be included:

Jest config:

{
  "browser": true,
  "collectCoverageFrom": ["<rootDir>/src/**/*.{js,jsx}", "!<rootDir>/__tests__/__dummy__/test.js"],
  "coveragePathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/__tests__/__helpers__/", "<rootDir>/__tests__/__dummy__/"],
  "roots": [
    "<rootDir>/__tests__/",
    "<rootDir>/src/"
  ],
  "modulePaths": [
    "<rootDir>/src/"
  ],
  "modulePathIgnorePatterns": [
    "<rootDir>/lib/",
    "<rootDir>/node_modules/",
    "<rootDir>/__tests__/__helpers__/",
    "<rootDir>/__tests__/__dummy__/"
  ],
  "setupTestFrameworkScriptFile": "@djforth/jest-matchers",
  "testPathIgnorePatterns": [
    "<rootDir>/__tests__/__dummy__",
    "<rootDir>/__tests__/__dummy__",
    "<rootDir>/lib",
    "<rootDir>/node_modules",
    "<rootDir>/bower_components"
  ],
  "verbose": true
}

I get the following report:

-----------------------|----------|----------|----------|----------|----------------|
File                   |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-----------------------|----------|----------|----------|----------|----------------|
All files              |    98.87 |    96.48 |     92.5 |    99.55 |                |
 __helpers__           |    84.21 |      100 |    54.55 |    90.91 |                |
  test.js              |    84.21 |      100 |    54.55 |    90.91 |              6 |
 __tests__/__helpers__ |      100 |      100 |      100 |      100 |                |
  create_spy_obj.js    |      100 |      100 |      100 |      100 |                |
 src                   |      100 |       80 |     87.5 |      100 |                |
  index.js             |      100 |       80 |     87.5 |      100 |                |
 src/utils             |      100 |    97.73 |      100 |      100 |                |
  compile_spies.js     |      100 |    81.82 |      100 |      100 |                |
  create_callbacks.js  |      100 |      100 |      100 |      100 |                |
  create_spies.js      |      100 |    97.44 |      100 |      100 |                |
  create_stubs.js      |      100 |      100 |      100 |      100 |                |
  get_spy.js           |      100 |      100 |      100 |      100 |                |
  merger.js            |      100 |      100 |      100 |      100 |                |
  reset_spies.js       |      100 |      100 |      100 |      100 |                |
  title_keys.js        |      100 |      100 |      100 |      100 |                |
-----------------------|----------|----------|----------|----------|----------------|
like image 830
DJ Forth Avatar asked Mar 03 '17 12:03

DJ Forth


2 Answers

Not sure why this not work for you but we do it the other way around:

"collectCoverageFrom": ["src/**/*.js"],
like image 183
Andreas Köberle Avatar answered Sep 28 '22 17:09

Andreas Köberle


I have finally figured out what was coursing my issue.

Jest uses Istanbul under the hood. When I set up the project I copied over my .babelrc config and neglected to realize I had left in my old Jasmine config. I had changed to Jest convention of adding tests to __tests__/**/*.test.js, However in .babelrc config I had:

"plugins": [
    [
      "istanbul",
      {
        "exclude": [
          "spec/**/*.spec.js"
        ]
      }
    ],
    "rewire"
  ]

So once I removed the exclude the coverage displays correctly. It looks like if you specify in .babelrc config it overrides the jest config.

like image 29
DJ Forth Avatar answered Sep 28 '22 18:09

DJ Forth