Jest 20: mapCoverage
joscha opened this issue ยท 15 comments
Can you create a minimal repo that reproduces this?
not yet, it seems to have something to do with:
"modulePaths": ["<rootDir>/src"],
Before Jest 20 I was able to just have:
"roots": ["<rootDir>/src"],
but after upgrading everything that had a relative import import x from 'bla/foo';
seemed to fail:
โ Test suite failed to run
Cannot find module 'base/serialization' from 'fixtures_proto.ts'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:172:17)
at Object.<anonymous> (src/base/serialization/tests/fixtures/fixtures_proto.ts:5:25)
where it worked with Jest 19, so I changed roots
to modulePaths
, e.g. now I have:
"modulePaths": ["<rootDir>/src"],
adding roots
additionally doesn't seem to change anything.
This shows the problem: https://github.com/joscha/jest-20 - I haven't found out where exactly it blows up.
When I remove "extends": "./tsconfig.json"
it seems to generate the coverage properly, I am just not able to say why.
I just ran:
git clone https://github.com/joscha/jest-20
cd jest-20
yarn install
yarn test
and got these results:
yarn test v0.23.4
$ rm -rf ./target/coverage
$ jest --config jestconfig.json --ci --coverage --no-cache
PASS src/other/__tests__/index.ts
โ should work (4ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.373s
Ran all test suites.
console.log src/base/bla/index.ts:3
hello
=============================== Coverage summary ===============================
Statements : 100% ( 4/4 )
Branches : 100% ( 0/0 )
Functions : 100% ( 1/1 )
Lines : 100% ( 2/2 )
================================================================================
Done in 9.24s.
have a look at the HTML report please in target/coverage/lcov/report
.
I actually think "outDir": "target",
is the problem.
We're not doing anything explicitly but it appears that having this value set is causing problems during testing.
There are two ways this can be fixed - by deleting outDir
from the config during testing (hardcoded in ts-jest) or by setting its value to null
in the tsconfig that testing uses (this works but gives a type warning in the editor).
I'm leaning towards the former as I don't see any need for outDir
during testing. I think this can safely be hardcoded. What do you think?
I have set it to null
for now, but I think removing it automatically would make sense. There is no output except coverage during a test run anyway, so it should be safe. Maybe add a comment to README to hint at it. Do you want me to create a PR for this?
Sure, that'd be great!
- add
delete config.outDir;
here with a comment stating why and add a link to this issue. - change the version in package.json to 20.0.1
Thanks :)
Unfortunately, this is still not fixed due to jestjs/jest#3524
@thymikee does this mean we can use instrument
as a proxy for collectCoverage
?
Yes