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

Jest 20: mapCoverage #201

Closed
joscha opened this issue May 8, 2017 · 15 comments · Fixed by #202
Closed

Jest 20: mapCoverage #201

joscha opened this issue May 8, 2017 · 15 comments · Fixed by #202

Comments

@joscha
Copy link
Contributor

joscha commented May 8, 2017

  • Issue

With mapCoverage set to true, I seem to get this:

code_coverage_report_for_all_files

in the reports with:

code_coverage_report_for_src_base_serialization_file__users_joscha_dev_canva_web_src_base_serialization_deserialization_ts

when I drill into the file.

If I disable mapCoverage everything seems to work as expected regarding the coverage, but the mapping is shifted.

  • Expected behavior

No file:// links

@kulshekhar
Copy link
Owner

Can you create a minimal repo that reproduces this?

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

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.

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

This shows the problem: https://github.com/joscha/jest-20 - I haven't found out where exactly it blows up.

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

When I remove "extends": "./tsconfig.json" it seems to generate the coverage properly, I am just not able to say why.

@kulshekhar
Copy link
Owner

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.

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

have a look at the HTML report please in target/coverage/lcov/report.

I actually think "outDir": "target", is the problem.

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

when I remove

    "outDir": "target",

from tsconfig.json in the sample repo, then

code_coverage_report_for_all_files

becomes:

code_coverage_report_for_all_files_and_1__joscha_canvabox___tmp_jest-20__zsh_

are we doing anything special with outDir in ts-jest?

@kulshekhar
Copy link
Owner

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?

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

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?

@kulshekhar
Copy link
Owner

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 :)

@joscha
Copy link
Contributor Author

joscha commented May 8, 2017

PR is here: #202

@joscha
Copy link
Contributor Author

joscha commented May 9, 2017

Unfortunately, this is still not fixed due to jestjs/jest#3524

@thymikee
Copy link
Contributor

@kulshekhar
Copy link
Owner

@thymikee does this mean we can use instrument as a proxy for collectCoverage?

@thymikee
Copy link
Contributor

Yes

kulshekhar added a commit that referenced this issue May 10, 2017
Use 'instrument' as proxy for 'collectCoverage'

Fixes #207 
Also fixes #201 - again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants