Jest: Coverage data was not found when using "--collectCoverageFrom"

Created on 15 Feb 2018  路  12Comments  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?
Bug

What is the current behavior?
When I'm using the Jest CLI like this:
jest --coverage --collectCoverageFrom "_path of a file_"
I get this error: Jest: Coverage data for global was not found.

My goal is to execute the coverage only on some files.

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

Repl.it don't seems to work, but just type
jest --coverage --collectCoverageFrom "_path of a file_"

What is the expected behavior?
Display the coverage table of the files specified by the collectCoverageFrom option.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

"jest": { "collectCoverage": true, "collectCoverageFrom": [ "src/**/*.js" ], "coverageThreshold": { "global": { "branches": 100, "functions": 100, "lines": 100, "statements": 0 } }, "moduleFileExtensions": [ "js" ], }

Jest 22.2.2
Node 8.9.4
yarn 1.3.2
macOS 10.13.4

Thanks!

Most helpful comment

@noelebrun Did you solved this problem?

I currently facing the same error with my typescript ts-jest setup.

This is my config:

{
    "transform": {
        "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(unit\\.test))\\.(tsx?)$",
    "moduleFileExtensions": [
        "ts",
        "js"
    ],
    "globals": {
        "ts-jest": {
            "skipBabel": true
        }
    },
    "testPathIgnorePatterns": [],
    "collectCoverage": true,
    "collectCoverageFrom": [
        "./src/utils/**/*.ts"
    ],
    "coverageThreshold": {
        "global": {
            "branches": 100,
            "functions": 100,
            "lines": 80,
            "statements": -10
        }
    }
}

And this is the console output:

> cross-env NODE_ENV=testing jest --forceExit --coverage --config=jest-unit.config.json

 PASS  src/tests/unit-tests/prune-object-properties.unit.test.ts
 PASS  src/tests/unit-tests/sample.unit.test.ts
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Jest: Coverage data for global was not found.

Test Suites: 2 passed, 2 total
Tests:       7 passed, 7 total
Snapshots:   0 total
Time:        2.267s
Ran all test suites.

I also tried to provide coverageDirectory, but without any change to the error message.

My dependencies:

  • jest: 22.4.3
  • ts-jest: 22.4.2

All 12 comments

Hey @noelebrun, thanks for the report. This seems to be working in latest:

If you truly believe this is a bug, please push a repo that we can reproduce with

Otherwise we recommend using StackOverflow or our discord channel for questions

You'll find more on Jest docs help page

@noelebrun Did you solved this problem?

I currently facing the same error with my typescript ts-jest setup.

This is my config:

{
    "transform": {
        "^.+\\.tsx?$": "ts-jest"
    },
    "testRegex": "(/__tests__/.*|(\\.|/)(unit\\.test))\\.(tsx?)$",
    "moduleFileExtensions": [
        "ts",
        "js"
    ],
    "globals": {
        "ts-jest": {
            "skipBabel": true
        }
    },
    "testPathIgnorePatterns": [],
    "collectCoverage": true,
    "collectCoverageFrom": [
        "./src/utils/**/*.ts"
    ],
    "coverageThreshold": {
        "global": {
            "branches": 100,
            "functions": 100,
            "lines": 80,
            "statements": -10
        }
    }
}

And this is the console output:

> cross-env NODE_ENV=testing jest --forceExit --coverage --config=jest-unit.config.json

 PASS  src/tests/unit-tests/prune-object-properties.unit.test.ts
 PASS  src/tests/unit-tests/sample.unit.test.ts
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Jest: Coverage data for global was not found.

Test Suites: 2 passed, 2 total
Tests:       7 passed, 7 total
Snapshots:   0 total
Time:        2.267s
Ran all test suites.

I also tried to provide coverageDirectory, but without any change to the error message.

My dependencies:

  • jest: 22.4.3
  • ts-jest: 22.4.2

I still get the same error.

node 10.0.0
jest 22.4.3

jest --config=jest.json --coverage

jest.json

{
  "testEnvironment": "node",
  "coverageThreshold": {
    "global": {
      "branches": 90,
      "functions": 90,
      "lines": 90,
      "statements": -10
    }
  },
  "collectCoverageFrom" : [
    "**/*.js"
  ]
}

I'll quote Rick from above 馃檪

If you truly believe this is a bug, please push a repo that we can reproduce with

@SimenB Fortunately, I just pushed this repo to github this morning, you can check it here https://github.com/Tiendq/lego-part-loader

:)

@rickhanlonii

There are no tests in that repo though. Adding a dummy test gives the following output:

image

I suppose we could improve the message when there are no tests, or just skip the coverage report when there are none?

@SimenB Yeah, that's exactly what we could enhance Jest :) It's definitely better to show "no test found" instead of current unclear error message. Thanks.

I suppose we could improve the message when there are no tests, or just skip the coverage report when there are none?

That's a separate issue though, mind opening up a new one?

@SimenB I raised an issue here https://github.com/facebook/jest/issues/6141

@yss14 Did you figure out a solution? I experienced a similar issue. I was able to get coverage after removing the "collectCoverageFrom" configuration block. Then I was able to put in the filters in collectCoverageFrom block.

Maybe your ""./src/utils/*/.ts"" was not pointing to the right place? Just a guess...

It used to support this syntax in "collectCoverageFrom":

"{apps|libs}/**/src/**/*.ts",

Now I need to do it in two lines:

"apps/**/src/**/*.ts",
"libs/**/src/**/*.ts",

@dereklin
try
"{apps,libs}/**/src/**/*.ts",

instead of
"{apps|libs}/**/src/**/*.ts",

Was this page helpful?
0 / 5 - 0 ratings