Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JestJS - show all uncovered lines in coverage report

When I run the Jest coverage report, it prints out each type of coverage and the percentage by file. The last column that shows the uncovered lines gets truncated when there are more than ~4-5 lines. Is there a way to print all of the uncovered lines?

-------------------------------|----------|----------|----------|----------|----------------|
File                           |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-------------------------------|----------|----------|----------|----------|----------------|
All files                      |    75.57 |    69.18 |    74.21 |    75.83 |                |
 js/components/catalyst        |    80.74 |    72.97 |    80.16 |    81.85 |                |
  JobGroup.jsx                 |    57.14 |       50 |    44.44 |       60 |... 33,34,38,73 |
...etc

This shows me that JobGroup.jsx has lines 33,34,38, and 73, but there are more, and I'd like to see them all at once.

like image 830
L. Cromer Avatar asked Jan 09 '18 00:01

L. Cromer


People also ask

What are uncovered lines in jest?

Testing uncovered linesThey are marked red, because they are completely untouched by any test. These lines are within an if-statement that is only entered when the passed two values together will be greater than 100.

How do I display code coverage?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.

How do I get code coverage results?

Code coverage results are displayed in the Coverage tool window, in the Project tool window, and in the editor after you run at least one configuration with coverage. Results of the code coverage analysis are saved to the coverage folder in the IDE system directory.

What uncovered code?

Uncover is a simple and easy to use command-line tool for measuring code coverage of applications. Code coverage is an important part of software testing. It gives you information on which areas of your code are exercised in testing and which are not, enabling you to improve your test suites to test more of your code.


2 Answers

Is there a way to print all of the uncovered lines?


I'm using React + TypeScript + Jest. In my project, I run npm test -- --coverage, and the file with the remaining uncovered lines is under the coverage directory:

<project name>\<directory>\<directory>\coverage\lcov-report\index.html

(Your file path may have a variation on the coverage part. :-))

Then I navigate to the file of interest:

code coverage results for file of interest

All lines highlighted in pink are uncovered:

line highlighted in pink

like image 153
Super Jade Avatar answered Oct 19 '22 17:10

Super Jade


This is an alternative solution that some may find helpful.

Personally, I use VSCode, and there is a plugin available called "Code Coverage", it does something similar to the other answer here, by Super Jade, except it will highlight the code after you run a coverage test, like so.

enter image description here

enter image description here

like image 35
humans Avatar answered Oct 19 '22 18:10

humans