question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

not able to run the coverage for one file

See original GitHub issue

🚀 Feature Proposal

coverage shows for full run but for specific files nothing or mixed

I want to be able to run with:

  • o option from jest menu
  • jest --watch --coverage STRING_FOR_REGEX_TESTS_SELECTION
  • jest --watch --coverage --runTestsByPath SPECIFIC_FILE_PATH

And have the coverage for the files impacted only.

Motivation

it’s all about productivity.

1. Tech Debt of tests

When we work on tech debt of tests => it’s generally one by one (file by file). So I mostly run targeting the file i am working on. The run in watch mode is faster this way. I would like to see the coverage related to the current file i am targeting (should be faster to generate?)

2. Same thing apply for development of new features

Devs don’t do TDD most of the time and do the test after. Testing files one by one is faster especially if you split between multiple developers the work.

this is a reality happening in a lot of companies.

Example

Jest version: "23.6.0" jest config:

module.exports = {
  preset: 'jest-preset-angular',
  setupTestFrameworkScriptFile: '<rootDir>/src/setupJest.ts',
  roots: ['src/app'],
  moduleFileExtensions: ['ts', 'js']
};

in this repo branch: (sorry i didn’t clean i just commited the state since i am playing with jest to help in vscode-jest repo) https://github.com/nasreddineskandrani/full-example-angular/tree/jest-playaround

  1. clone the repo
  2. yarn install

– Example 1 Steps

  • yarn run testjest:watch -- --coverage
  • run all tests (the coverage is fine) and the coverage result is: image
  • now use w then o (Press o to only run tests related to changed files.) then you change the file src\app\game\game-a.service.spec.ts the condition true to false and vise versa Resulting coverage (PROBLEM): image

– Example 2 Steps

when i run: yarn run testjest:watch -- --coverage game-a.service.spec.ts I get: image

WHY HERO.SERVICE impacted here? setupJest.ts …?

– Example 3 Steps

when i run: yarn run testjest:watch --coverage --runTestsByPath src/app/game/game-a.service.spec.ts I get: image

WHY HERO.SERVICE impacted here? setupJest.ts …?

Result expected:

  • I want to be able to see only the coverage of the file i changed
  • I want to be able to see only the coverage of the file(s) i watch (with regex or path) => without doing any custom config since the file(s) impacted are known.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:17
  • Comments:24 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
mwalkerpearcommented, Jun 10, 2019

Doesn’t this solve the issue? --collectCoverageOnlyFrom

6reactions
joelbarbosacommented, Oct 19, 2019

sorry what I meant was yarn jest src/components/MyComponent/test/MyComponent.tsx --coverage --collectCoverageOnlyFrom=src/components/MyComponent/MyComponent.tsx the first path is for test folder

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run Jest tests with coverage for one file
The solution is to add one small option --collectCoverageFrom to collect only for a certain file (i.e. component). This is based on this ......
Read more >
Jest: run tests and generate coverage for specific file or folder
It will be good if I'm able to run tests of specific folder or file and generate the coverage for only for those...
Read more >
How to test coverage on specific files (with Jest)
Here's the trick:​​ All you have to do is type yarn test [regex] --coverage , and this will run coverage only on the...
Read more >
Code Coverage
After running the test and opening the HTML report, we see 76% code coverage in our application. Coverage report after a single test....
Read more >
Troubleshooting Code Coverage - Visual Studio (Windows)
The .pdb file must be generated from the same build as the .dll or .exe ... Code coverage analysis can't be performed on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found