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

Coverage hasn't worked since last major semver update #1425

Closed
dsifford opened this issue Aug 14, 2016 · 19 comments
Closed

Coverage hasn't worked since last major semver update #1425

dsifford opened this issue Aug 14, 2016 · 19 comments

Comments

@dsifford
Copy link

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!

@aaronabramov
Copy link
Contributor

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!

@dsifford
Copy link
Author

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

@calclavia
Copy link

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

@aaronabramov
Copy link
Contributor

#1430

@dsifford
Copy link
Author

@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?

@aaronabramov
Copy link
Contributor

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?

@cpojer
Copy link
Member

cpojer commented Aug 16, 2016

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 jest@14.2.2-alpha.22bd3c33 or jest@test should work too.

@cpojer cpojer closed this as completed Aug 16, 2016
@dsifford
Copy link
Author

Awesome, sounds good. Thanks again so much!

@dsifford
Copy link
Author

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.

@aaronabramov
Copy link
Contributor

@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

@aaronabramov
Copy link
Contributor

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

@dsifford
Copy link
Author

@DmitriiAbramov Ah, ok sorry about the confusion.

Thanks for the clarification. Got it working now.

Also: collectCoverageFrom = 🔥 👍 👍

@calclavia
Copy link

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__}/**"]
  }

@aaronabramov
Copy link
Contributor

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

@calclavia
Copy link

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

@jseminck
Copy link
Contributor

jseminck commented Aug 28, 2016

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

@aaronabramov
Copy link
Contributor

that should be fixed by #1482

@jseminck
Copy link
Contributor

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

@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

5 participants