Jest: Coverage hasn't worked since last major semver update

Created on 14 Aug 2016  路  18Comments  路  Source: facebook/jest

Hello,

I've been trying to troubleshoot this on my own off and on for the last few days, but unfortunately I haven't been able to figure out what's going on. Issue #433 seems to be the closest thing to what I have going on, but none of the suggestions there helped.

Before the last major semver update, everything was working totally fine. Now, when I run jest with the same configs as before I get this.

64 tests passed (64 total in 16 test suites, run time 2.022s)
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files |      100 |      100 |      100 |      100 |                |
----------|----------|----------|----------|----------|----------------|

For some reason, no tests are making it to the results table and, although coverage report is being generated, it's completely blank.

image

Here's my configs:

"jest": {
    "scriptPreprocessor": "jestPreprocessor.js",
    "testFileExtensions": [
      "ts",
      "tsx",
      "js"
    ],
    "moduleFileExtensions": [
      "js",
      "ts",
      "tsx",
      "json"
    ],
    "unmockedModulePathPatterns": [
      "react",
      "react-dom",
      "react-addons-test-utils",
      "fbjs",
      "enzyme",
      "sinon",
      "lib/js/utils/Constants",
      "lib/js/utils/Mocks"
    ],
    "verbose": true,
    "collectCoverage": true,
    "coverageDirectory": "tmp/coverage"
  },

It looks like a week or so ago collectCoverageFrom has been added to master, but that hasn't been released yet, so that's not really an option for now.

Here's the repo: https://github.com/dsifford/academic-bloggers-toolkit

Happy to answer any questions you might have. Thanks in advance for your work on this!

Most helpful comment

also now you can add something like this to your jest config

"jest": {
    "collectCoverageFrom": ["src/**/*.{js,ts,tsx}", "!**/{vendor,__tests__}/**"]
}

and this will also collect coverage for all files that are not tested but match this set of globs

All 18 comments

hey @dsifford
thanks for reporting the issue!
i was able to find the problem. The new version of Istanbul uses babel to instrument the file, and basically this condition (https://github.com/facebook/jest/blob/429b2d1947cc427d01c33bddeae1378221a2a4f5/packages/jest-runtime/src/transform.js#L254) always returns false because of the .tsx file extension.

all make a fix for it on monday!

@dmitriiabramov Wow, that's great to hear! Thanks so much again for your work on this!

I'm getting the same issue. Looking forward to the fix!

@dmitriiabramov Thanks again for the quick fix with this.

Does Jest have pre-release or nightly branches that I can pull with these changes? If not, any idea when the next update will be pushed through?

we're going to release the next version in about two weeks or so.
@cpojer are you going to push anything to npm this week?

I'm more or less continuously pushing a test tag this week. You can try npm install --save-dev jest@test to try it out. It's your own risk though, we are currently making many awesome changes but some of them might break (please report it though if it is a real bug!).

I published @dmitriiabramov's fix a minute ago, so please feel free to try it out. It's [email protected] or jest@test should work too.

Awesome, sounds good. Thanks again so much!

Not sure if you guys are aware, but the issue is persisting with jest@test. Didn't seem to make any change; even after flushing the cache.

Still no coverage being rendered. Happy to answer any specific questions either of you may have.

@dsifford the bug was actually in jest-runtime not jest itself.
so you'll have to do something like rm -rf node_modules/*jest* and then npm i jest@test --save-dev

jest tried it on academic-bloggers-toolkit

screen shot 2016-08-16 at 8 13 20 pm

also now you can add something like this to your jest config

"jest": {
    "collectCoverageFrom": ["src/**/*.{js,ts,tsx}", "!**/{vendor,__tests__}/**"]
}

and this will also collect coverage for all files that are not tested but match this set of globs

@dmitriiabramov Ah, ok sorry about the confusion.

Thanks for the clarification. Got it working now.

Also: collectCoverageFrom = 馃敟 馃憤 馃憤

I tried using collectCoverageFrom, after putting that in the config,I received:

ERROR: TypeError: Cannot read property 'instrument' of undefined

"jest": {
    "verbose": true,
    "coverageDirectory": "coverage",
    "automock": false,
    "scriptPreprocessor": "<rootDir>/jestProcessor.js",
    "collectCoverageFrom": ["src/**/*.{js,ts,tsx}", "!**/{vendor,__tests__}/**"]
  }

@calclavia is there any stack trace? does it happen after/before or during the test run?

It happens during the test run. I'll try to come up with a stack trace soon.

I have the same issue.

I use a custom preprocessor (because jest fails when using CSS modules). When removing that custom preprocessor, then it seems to pick up the code without a problem. Could it be related to that? My preprocessor is pretty much this one:
https://github.com/justinsisley/Jest-CSS-Modules/blob/master/index.js

Stacktrace:

              Failed to collect coverage from /Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/src/components/Links/LinksPage.js
              ERROR: TypeError: Cannot read property 'instrument' of undefined
              STACK: TypeError: Cannot read property 'instrument' of undefined
    at Object.process (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/babel-jest/build/index.js:37:30)
    at Object.process (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/tools/jestPreprocessor.js:9:20)
    at transformSource (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest-runtime/build/transform.js:293:27)
    at transformSource (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest-runtime/build/index.js:91:38)
    at module.exports (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest/node_modules/jest-cli/build/generateEmptyCoverage.js:22:12)
    at /Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest/node_modules/jest-cli/build/reporters/CoverageReporter.js:87:13
    at Set.forEach (native)
    at CoverageReporter._addUntestedFiles (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest/node_modules/jest-cli/build/reporters/CoverageReporter.js:82:13)
    at CoverageReporter.onRunComplete (/Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest/node_modules/jest-cli/build/reporters/CoverageReporter.js:56:10)
    at /Users/joachimseminck/Projects/jseminck-be/jseminck-be-main/node_modules/jest/node_modules/jest-cli/build/TestRunner.js:437:14

Thanks. I'll try to test it today. I ended up throwing the preprocessor away in favour of another method. :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antho2407 picture Antho2407  路  3Comments

stephenlautier picture stephenlautier  路  3Comments

nsand picture nsand  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

kentor picture kentor  路  3Comments