We have issues with the reported “Lines to Cover” and “Coverage” metric.
Our Project has the following monorepo-structure:
root/
- frontend/
- backend/
- sonar-project.properties
Both front- and backend are written in Typescript and are independent node projects with their own jest unit-test suite. We generate separate test reports for both projects to the following locations:
- backend/reports/test-reporter.xml
- frontend/reports/test-reporter.xml
- backend/reports/coverage/lcov.info
- frontend/reports/coverage/lcov.info
We link all those files in our sonar-project.properties, which is located in the root folder.
sonar-project.properties
sonar.sources=frontend/src,backend/src,shared
sonar.tests=frontend/src,backend/src,backend/test
sonar.test.inclusions=**/*.spec.js,**/*.spec.ts,**/*.e2e-spec.ts,**/*.e2e-spec.js
sonar.typescript.lcov.reportPaths=backend/reports/coverage/lcov.info,frontend/reports/coverage/lcov.info
sonar.testExecutionReportPaths=backend/reports/test-reporter.xml,frontend/reports/test-reporter.xml
The content of the files looks fine:
frontend/reports/test-reporter.xml (abstract)
<testExecutions version="1">
<file path="frontend\src\helpers\generator-helpers.spec.ts">
<testCase name="Generator Helpers randomNumber should return a random number between 1 and 100" duration="3" />
</file>
</testExecutions>
frontend/reports/coverage/lcov.info (abstract)
SF:frontend\src\helpers\generator-helpers.ts
FN:11,randomNumber
FN:20,randomPassword
FN:27,(anonymous_2)
FN:33,(anonymous_3)
FN:34,(anonymous_4)
FN:35,(anonymous_5)
FNF:6
FNH:6
FNDA:10,randomNumber
FNDA:1,randomPassword
FNDA:4,(anonymous_2)
FNDA:8,(anonymous_3)
FNDA:17,(anonymous_4)
FNDA:8,(anonymous_5)
DA:11,1
DA:12,10
DA:20,1
DA:21,1
DA:22,1
DA:23,1
DA:24,1
DA:25,1
DA:26,1
DA:27,1
DA:28,4
DA:29,8
DA:32,1
DA:33,8
DA:34,17
DA:35,8
DA:36,1
LF:17
LH:17
BRDA:11,0,0,1
BRDA:11,1,0,1
BRF:2
BRH:2
end_of_record
TN:
However, the reported coverage on SonarCloud is only partially complete. The test frontend/src/helpers/generator-helpers.spec.ts is correctly detected and visible in SonarCloud. However, the file covered by the test frontend/reports/coverage/lcov.info is not showing up in the “Coverage > Lines to Cover” panel. In fact, only 29 of our source code files show up, some from the backend, some from the frontend, but with no clearly visible pattern which files show and which don’t. When I navigate to the file using the “Tree”-View, I can find the file, but all lines of code are neither marked as “Covered” or “Uncovered by Tests” (see image below)
This has the following effects:
- The metric “Lines to Cover” is far to small (only reporting ~250 lines currently while the repo has ~1500 LoC, according to the SonarCloud project dashboard, most of it being TypeScript code.
- We can not reliably detect which Files are still untested, since most of them do not show up in the “Lines to Cover” section
- The reported coverage is wrong since both files covered by test but also files NOT covered by tests are missing
- Our quality gateway constantly fails since the reported coverage is not sufficient
We use jest@27.0.6 and the reporter jest-sonar@0.2.12 with typescript@4.4.3 on node@16.16.2.
Since we are out of ideas how to solve this problem, I would appreciate some help.
