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

Jest 16: coverage empty with collectCoverageFrom #1849

Closed
maiis opened this issue Oct 3, 2016 · 13 comments
Closed

Jest 16: coverage empty with collectCoverageFrom #1849

maiis opened this issue Oct 3, 2016 · 13 comments

Comments

@maiis
Copy link

maiis commented Oct 3, 2016

Hi,

I've just upgraded to jest 16, and since my test coverage are empty.

If I remove the collectCoverageFrom option from the config it seams to works 😳

Apart from that, loving the new features 😍Keep it up 🍻

  "collectCoverageFrom": [
    "<rootDir>/src/main/webapp/scripts/**/*.js"
  ],
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
jest version = 16.0.0
test framework = jasmine2
config = {
  "preprocessorIgnorePatterns": [
    "node_modules"
  ],
  "modulePaths": [
    "MYPATH/src/main/webapp/scripts"
  ],
  "moduleNameMapper": [
    [
      "^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$",
      "MYPATH/src/test/javascript/file-mock.js"
    ],
    [
      "^.+\\.(css|less)$",
      "MYPATH/src/test/javascript/style-mock.js"
    ]
  ],
  "testPathDirs": [
    "MYPATH/src/main/webapp/scripts"
  ],
  "testResultsProcessor": "MYPATH/node_modules/jest-teamcity-reporter",
  "collectCoverageFrom": [
    "MYPATH/src/main/webapp/scripts/**/*.js"
  ],
  "coverageThreshold": {
    "global": {
      "branches": 95,
      "functions": 95,
      "lines": 95,
      "statements": 95
    }
  },
  "rootDir": "MYPATH",
  "name": "-MYNAME",
  "testRunner": "MYPATH/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "MYPATH/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/var/folders/x3/142j64696f11fhmkr3f2q6g42rxg89/T/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "testPathIgnorePatterns": [
    "/node_modules/"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "collectCoverage": true,
  "cache": false,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}
@cpojer
Copy link
Member

cpojer commented Oct 4, 2016

Can you provide a repository that highlights this issue so we can fix it? :)

@difelice
Copy link

difelice commented Oct 4, 2016

If you remove <rootDir> should work since it's relative from root:

"collectCoverageFrom": [
    "src/main/webapp/scripts/**/*.js"
  ],

Another issue I found is that the command-line argument --collectCoverageFrom is ignored if a config file is provided, even without that option:

jext-config.json:

{
  "verbose": false
}
$ jest -c jest-config.json --coverage --collectCoverageFrom=**/*.js

UPDATE
I could be wrong, but I noticed that the client argument is a string, but looks like the same config option expects an array

UPDATE 2
Even though the normalize takes care of the type, the argv option is discard later on.

@cpojer
Copy link
Member

cpojer commented Oct 5, 2016

@difelice does it work if you provide the argument --collectCoverageFrom twice (with different arguments)?

@cpojer
Copy link
Member

cpojer commented Oct 5, 2016

@maiis @difelice is right; collectCoverageFrom shouldn't contain rootDir.

@maiis
Copy link
Author

maiis commented Oct 5, 2016

@cpojer @difelice thank you very much! Working without rootDir.

=============================== Coverage summary ===============================
Statements   : 97.4% ( 636/653 )
Branches     : 91.8% ( 235/256 )
Functions    : 98.09% ( 154/157 )
Lines        : 97.53% ( 631/647 )
================================================================================

@difelice
Copy link

difelice commented Oct 6, 2016

@cpojer jest-cli seems to ignore or override --collectCoverageFrom if the --config is provided, even without collectCoverageFrom in it.

@mlippens
Copy link

mlippens commented Feb 1, 2018

It's quite confusing that collectCoverageFrom must not contain rootDir while others must use it.

@MichalLytek
Copy link

MichalLytek commented Feb 16, 2018

It's quite confusing that collectCoverageFrom must not contain rootDir while others must use it.

Agree, it's really not intuitive design 😞 I've spend a few minutes googling why it fails.

@thymikee
Copy link
Collaborator

thymikee commented Feb 16, 2018

@19majkel94 check out latest version https://github.com/facebook/jest/blob/master/CHANGELOG.md#chore--maintenance 😉

EDIT: in case the link breaks: #5524

@MichalLytek
Copy link

@thymikee Thanks, I've installed jest just 5 days ago and it was 22.2.2 😄

@jintoppy
Copy link

I am getting this issue with jest version "24.9.0". Added the below option.
collectCoverageFrom: [ 'src/**/*.{js}' ]

if I remove this option, it works. It was working fine, but, then, when I did a fresh install, it started failing. I am guessing, some dependency package got updated?

@nareshg4
Copy link

Hi All,

We are also facing the same issue, our pipelines were working fine untill past few days & suddenly the coverage started showing as 0.

Any help is much appreciated.

INFO] ----------|----------|----------|----------|----------|-------------------|
[INFO] File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
[INFO] ----------|----------|----------|----------|----------|-------------------|
[INFO] All files | Unknown | Unknown | Unknown | Unknown | |
[INFO] ----------|----------|----------|----------|----------|-------------------|

[ERROR] Test Suites: 0 of 521 total

@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 11, 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

8 participants