Files in test directory read as source code

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
  • Scanner command used when applicable (private details masked)
  • Languages of the repository
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
  • Potential workaround

We are using Github and Github actions, Typescript and Javascript, Jest. I am generating lcov reports but they are not being read properly. Some files with <80% coverage are being shown as 0%. When running the sonar scan, I get the following error

WARN: Found 3 inconsistencies in coverage report. Re-run analyse in debug mode to see details.

When I run debug:

Problem during processing LCOV report: can't save DA data for line 147 of coverage report file (java.lang.IllegalArgumentException: Line with number 167 doesn't belong to file example.ts)

I believe that the scanner is reading the test example.ts as the source code example.ts.

Our directory structure:

componentDir
--- __tests__
    --- example.ts
--- example.ts

Sonar args:

sonar.sources=application/
sonar.tests=application/
sonar.test.inclusions=application/**/__tests__/

Any thoughts on what I need to do to resolve this? It is becoming a problem for my team.

Hi Kate,

Have you tried adding the following?

sonar.exclusions=application/**/__tests__/

You can see an example and explanation here: How do SonarCloud properties work in relation to each other? - #2

Yes! That resolved it thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.