-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
not able to run the coverage for one file #7427
Comments
hey @nasreddineskandrani, thanks for using Jest - this is not a bug, but it is a pretty good feature request Can you update the description to use the feature request template? |
done. waiting for feedback :) |
Wow, awesome change thanks 👍 |
Is anybody working on this right now? |
Nope, feel free to tackle it if you've got some time! |
Doesn't this solve the issue? |
|
This does not work for me, it runs a full test run regardless of what is specified - i.e. |
please, try this way. yarn jest app/components/search/tests/SearchPage.js --coverage --collectCoverageFrom=app/components/search/SearchPage.js |
While the test suite appears to run, I get a |
eg. |
Should this work with TypeScript too? I'm trying the following but it still craps out yarn jest MyComponent --coverage --collectCoverageOnlyFrom=src/components/MyComponent/MyComponent.tsx I get |
try this way. |
Thanks, but same result |
sorry what I meant was |
My setup is a little different so for me, running: yarn jest src/components/Button/Button.test.tsx --coverage --collectCoverageOnlyFrom=src/components/Button/Button.tsx Still results in Example output:
|
Maybe you need to see some jest config with typescript: |
any update on this? is there an option to collect coverage from tested files only? |
is there any way to get coverage correctly with --coverage --changedSince=master? |
It works |
I close it since it's solved. Thanks |
Can you please open this again ? It is broken on jest 26.6.3 yarn jest src/components/MyComponent/MyComponent.test.tsx --coverage --collectCoverageOnlyFrom=src/components/MyComponent/MyComponent.tsx |
Hi! I wanted to do this directly from the Jest CLI options, but since none worked, I did a workaround that may fit your use case. I only wanted to know what was the coverage of the files I was writing tests for, and piping the output with grep was enough:
This will log something like this: PASS {path of a file that matched your pattern}
PASS {path of a file that matched your pattern}
{path of one parent directory} | 100 | 83.33 | 100 | 100 | |
{path of one of your files} | 100 | 83.33 | 100 | 100 | 24 |
{path of one of your files} | 100 | 83.33 | 100 | 100 | 103 |
Jest: "global" coverage threshold for statements (x%) not met: y%
Jest: "global" coverage threshold for lines (x%) not met: y%
Jest: "global" coverage threshold for functions (x%) not met: y%
Test Suites: x passed, x total
Tests: y passed, y total
Snapshots: 0 total
Time: Xs
Ran all test suites matching /myPattern/i. If a test fails it'll still display the expectation errors, only without colors. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 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 menujest --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:
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
yarn install
-- Example 1 Steps
yarn run testjest:watch -- --coverage
w
theno
(Press o to only run tests related to changed files.)then you change the file
src\app\game\game-a.service.spec.ts
the conditiontrue
tofalse
and vise versaResulting coverage (PROBLEM):
-- Example 2 Steps
when i run:
yarn run testjest:watch -- --coverage game-a.service.spec.ts
I get:
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:
WHY HERO.SERVICE impacted here? setupJest.ts ....?
Result expected:
=> without doing any custom config since the file(s) impacted are known.
The text was updated successfully, but these errors were encountered: