Skip to content

Coverage data was not found when using "--collectCoverageFrom" #5580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noelebrun opened this issue Feb 15, 2018 · 13 comments
Closed

Coverage data was not found when using "--collectCoverageFrom" #5580

noelebrun opened this issue Feb 15, 2018 · 13 comments

Comments

@noelebrun
Copy link

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!

@rickhanlonii
Copy link
Member

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

@yss14
Copy link

yss14 commented Apr 13, 2018

@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

@tiendq
Copy link
Contributor

tiendq commented May 6, 2018

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"
  ]
}

@SimenB
Copy link
Member

SimenB commented May 6, 2018

I'll quote Rick from above 🙂

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

@tiendq
Copy link
Contributor

tiendq commented May 6, 2018

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

:)

@rickhanlonii

@SimenB
Copy link
Member

SimenB commented May 6, 2018

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?

@tiendq
Copy link
Contributor

tiendq commented May 6, 2018

@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?

@SimenB
Copy link
Member

SimenB commented May 6, 2018

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

@tiendq
Copy link
Contributor

tiendq commented May 6, 2018

@SimenB I raised an issue here #6141

@dereklin
Copy link

dereklin commented Jun 26, 2018

@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...

@dereklin
Copy link

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",

@kamilszkutnik
Copy link

kamilszkutnik commented Jul 3, 2018

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

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

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants