question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
yss14commented, 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
3reactions
SimenBcommented, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest collectCoverageFrom and coverageThreshold not working
This means when I run npm t jest must show me error about global coverage does not 100%. But I don't see any...
Read more >
Configuring Jest
If a file matches the specified glob pattern, coverage information will be collected for it even if no tests exist for this file...
Read more >
Configuring code coverage in Jest, the right way
If you're using Jest, here are three options that should always be present in your Jest configuration: collectCoverage; collectCoverageFrom ...
Read more >
Configuring Code Coverage for TypeScript Files in Jest
The second one is going to be not with the exclamation points source/**/*.d.ts. We're telling it to collect coverage from all your typescript...
Read more >
Two useful ways to easily run a single test using Jest
So, the single test ran with the name should return an empty array if no data is found within helper.spec.js to get coverage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found