After upgrading from Jest 24 to Jest 25 we are seeing more files in our coverage reports that we used to have. It seems like the behaviour of the collectCoverageFrom glob patterns has changed.
Worked up to version: 24.9.0
Stopped working in version: 25.1.0
Our folder structure is the following:
client/extension/chrome/js/__tests__/Our jest.config.js has the following option:
collectCoverageFrom: [
'!**/__mocks__/**',
'!**/__tests__/**',
'extension/**'
],
The expectation is that coverage is collected from module.js but NOT from some_file.js. In Jest 24 this is the case, but in Jest 25 coverage is being collected from some_file.js even though we've set '!**/__tests__/**',.
To work around this, we had to explicitly add '!extension/chrome/js/__tests__/**' to the list of directories and that made Jest 25 ignore it.
Hopefully the details above are enough. If not, I can help setup a test repo to reproduce.
npx envinfo --preset jestPaste the results here:
System:
OS: macOS 10.15.2
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Binaries:
Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v10.17.0/bin/npm
npmPackages:
jest: 25.1.0
We ran into this as well. Jest 25 moved up to micromatch 4 which is where the problem seems to be: https://github.com/micromatch/micromatch/issues/179.
This is the workaround we are using for now: https://github.com/micromatch/micromatch/issues/179#issuecomment-579328061
Oh, this is very interesting! Thanks for that link @joelpalmer. Could you share which pattern you changed and to what?
Sure @SimenB - that workaround comment is actually from us: https://github.com/micromatch/micromatch/issues/179#issuecomment-579328061
But, to add a little more context, in jest.config.js:
collectCoverage: true,
collectCoverageFrom: [
'**/*.js',
- '!(coverage|config|scripts|tests)/**'
+ '!**/(coverage|config|scripts|tests)/**'
],
coverageReporters: ['html', 'lcovonly', 'text-summary'],
testEnvironment: 'node',
@joelpalmer thanks for the detail. I maintain micromatch, I'm looking into this.
I can confirm that joelpalmer solution works fine. I went through the same change of behavior but that did it.
Upgrading to Jest 25.2.4 has resolved this issue for us! We didn't have to make any changes to our collectCoverageFrom setting.
For me, the original issue is still occurring in 25.2.4. Even though I specified:
'!**/__tests__/**',
to be ignored, I'm still seeing directories from extension/chrome/js/__tests__/ inside my coverage report.
I don't think we've changed anything to address this. I don't really think we can work around it either, without downgrading micromatch which we really don't wanna do (it'd be a breaking change as well)
Sorry for the radio silence on this. I’ll try to get this resolved in micromatch ASAP.
Sent from my iPhone
On Mar 31, 2020, at 5:44 PM, Simen Bekkhus notifications@github.com wrote:
I don't think we've changed anything to address this. I don't really think we can work around it either, without downgrading micromatch which we really don't wanna do (it'd be a breaking change as well)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
@jonschlinkert are there any news on this issue on the micromatch side?
Most helpful comment
Sorry for the radio silence on this. I’ll try to get this resolved in micromatch ASAP.
Sent from my iPhone