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.

Jest 16: coverage empty with collectCoverageFrom

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
mlippenscommented, Feb 1, 2018

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

5reactions
difelicecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to collect coverage in Jest - Stack Overflow
I tried using "collectCoverageFrom" : ["**/src/**/*.js"] but it throws me Unknown for all params. Am I missing something here? jest-setup.json:
Read more >
Configuring Jest for Next.JS (React) and Babel from scratch
Step 3: Create the configuration files. Let's begin with 'package.json'. You'll add the following nodes under ā€œscriptā€: test, test:coverage, devĀ ...
Read more >
Configuring Jest
You can collect coverage from those files with setting forceCoverageMatch . ... it will be present in the object with its value set...
Read more >
Configuring Jest compiled - w3resource
Because it retrofits all executed files with coverage collection statements, this mayslow down your test significantly slow. collectCoverageFrom ...
Read more >
Configuring Jest to show code coverage for all of your files
exports = { collectCoverage: true, collectCoverageFrom: ['src/**/*.{js,jsx}'], };. Now all you would have to do is runĀ ...
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