Skip to content
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

No code coverage #632

Closed
MathRobin opened this issue Dec 4, 2015 · 12 comments
Closed

No code coverage #632

MathRobin opened this issue Dec 4, 2015 · 12 comments

Comments

@MathRobin
Copy link

Hi, I have a problem with code coverage. This the tests results :

[...]
24 tests passed (24 total in 9 test suites, run time 2.353s)
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|

All reports generated

Process finished with exit code 0

All my tests succeed (count 73 expect). But no cover. I'm just testing normal node code. I use babel-jest, here you have the config in package.json :

"scripts": {
  "test": "jest"
},
"jest": {
  "collectCoverage": true,
  "moduleFileExtensions": [
    "js",
    "json"
  ],
  "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
  "testDirectoryName": "unit",
  "testFileExtensions": [
    "js"
  ],
  "testPathDirs": [
    "<rootDir>/tests/"
  ]
}

Here is my project architecture :

./
|-- app
|   |-- routes
|   |   |-- private
|   |   |-- public
|-- tests
|   |-- unit
|   |   |-- routes
|   |   |   |-- private
|   |   |   |-- public

The tests/unit folder contains the same architecture as app folder as you can see.

Have you an idea about why I don't have any reports ? Thanks in advance !

@cpojer
Copy link
Member

cpojer commented Dec 4, 2015

Hey! Which version of node, npm and jest are you using?

@MathRobin
Copy link
Author

Last jest, last node 5.x and last npm 3.x

@cpojer
Copy link
Member

cpojer commented Dec 5, 2015

This is not great. Can you try running jest with --coverage and tell me if it yields something different? Can you maybe create a reduced example that I can dig into to figure out what is wrong?

@MathRobin
Copy link
Author

Yes, tried the same doesn't get more. I will make you an example yes

@quantizor
Copy link
Contributor

Add collectCoverageOnlyFrom with specific file names and it will work.

"collectCoverageOnlyFrom": {
        "index.js": true,
        "MyFolder/index.js": true
}

etc

@cyjia
Copy link

cyjia commented Dec 29, 2015

I found following lines in file jest-cli/src/HasteModuleLoader/HasteModuleLoader.js.

const onlyCollectFrom = this._config.collectCoverageOnlyFrom;
const shouldCollectCoverage =
      this._config.collectCoverage === true && !onlyCollectFrom
      || (onlyCollectFrom && onlyCollectFrom[modulePath] === true);

collectCoverageOnlyFrom is filled with {} by default, so shouldCollectCoverage will always be false unless you provide one with files.
I think the intention is to gather all coverage by default, this should be a bug.

@MathRobin
Copy link
Author

I confirm that when I list every file by hand, it's working.

I've tried with a small extract of the project, but here I get the coverage without listing. I bet it was because of paths but after a day passed on it with a colleague, not found where is the difference...

@aospan
Copy link

aospan commented Jan 12, 2016

same problem described here #433

as workaround you can create fake tests/package.json with {} inside. In this case node-haste create correct requiredModules and you will see coverage for all files (direct dependent from test file).

@mattlo
Copy link

mattlo commented Jan 14, 2016

Also running into this issue. Listing the direct paths under collectCoverageOnlyFrom works but its not practical.

@jasonmerino
Copy link

I'm also running into this issue. Getting 100% across the board when I actually only have partial tests on a single file.

@cpojer
Copy link
Member

cpojer commented Feb 18, 2016

Fixed by 0.9.0.

@cpojer cpojer closed this as completed Feb 18, 2016
@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 14, 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