Jest: Can't get the coverage with Jest 24

Created on 11 Feb 2019  路  10Comments  路  Source: facebook/jest

馃悰 Bug Report

I can't get the coverage anymore with Jest 24.

To Reproduce

Steps to reproduce the behavior:

This is my jest configuration:
{
"verbose": true,
"clearMocks": true,
"restoreMocks": true,
"setupFilesAfterEnv": [
"/config/enzyme-setup.js"
],
"collectCoverage": true,
"collectCoverageFrom": [
"/.{js}",
"!
/node_modules/",
"!index.js",
"!config/
",
"!coverage/",
"!webpack.dev.config.js",
"!client/index.js",
"!client/store/
",
"!client/reducers/",
"!client/sagas/
",
"!client/style/"
],
"testMatch": [
"
/__tests__/?(
.)(spec|test).js"
],
"moduleNameMapper": {
"\.(scss)$": "/config/module-mock.js"
},
"snapshotSerializers": [
"enzyme-to-json/serializer"
]
}

Expected behavior

I suppose it should still work as per documentation.

Bug Needs Repro

Most helpful comment

"**/*.{js}", looks iffy to me (try just "**/*.js").

Anyways, please put together a reproduction like the template asked you to. Just config isn't enough

All 10 comments

testMatch is likely invalid. Can you use default one and check again? (just delete it from config)

Ahh, I don't know why, but copy/paste didn't work.

"testMatch": [
"*/__tests__/?(.)(spec|test).js"
],

This is how it is. And it's valid, because my tests are passing, but the coverage is not there.

PS I removed it just for test, same result.

"**/*.{js}", looks iffy to me (try just "**/*.js").

Anyways, please put together a reproduction like the template asked you to. Just config isn't enough

Pff, thanks man. This syntax worked in v23.

Yes, it's still an invalid glob. This is mentioned at the top of the list of breaking changes in the blog post: https://jestjs.io/blog/2019/01/25/jest-24-refreshing-polished-typescript-friendly#breaking-changes

Great you got it working, though!

Thanks for you help, Simen!

Can also change to '**/*.{js,}' if you want to keep the same curly-brace syntax, but only one file extension.

This comment worked: https://github.com/facebook/jest/issues/7865#issuecomment-462389513 馃憤 Thanks

@maneetgoyal The comment did not work for me, sadly. I have created another issue for this problem here.

@JimTheMan In my case, I was also missing the moduleFileExtensions property and was using .ts files instead.

So, the Jest (v. 24.9.0) config eventually had these properties:

  // An array of file extensions your modules use
  moduleFileExtensions: ["ts", "js"],
  // Needed to collect coverage data
  collectCoverage: true,
  // Needed to specify from where to collect the coverage data
  collectCoverageFrom: ["./src/**/*.ts"],
  // "text" reporter logs the coverage report in the console
  coverageReporters: ["text", "html"],
  // Stores coverage report in this directory
  coverageDirectory: "./coverage"

Hope it helps a bit.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gustavjf picture gustavjf  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

kentor picture kentor  路  3Comments

samzhang111 picture samzhang111  路  3Comments

stephenlautier picture stephenlautier  路  3Comments