How to add test coverage in sonar property file?

Hello All, I am having one node.js code in which I have written one API, I am using jest for unit test cases.
All my code along with test cases are inside src folder.
All my test cases are inside test folder. So according to that I have added that sonar.tests=src/test in my property file. On console my test coverage is around 92% But its not reflecting it into sonar dashboard.
My jenkins pipeline is failing by sending error message like below:

File src/test/filename.test.js can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

sonar.language=js
sonar.sources=src
sonar.tests=src/test

Hey there.

You’ll need to set sonar.exclusions=src/test to make sure your test files aren’t indexed twice.

With regard to code coverage, it’s a matter of importing your coverage report using the appropriate analysis parameter (sonar.javascript.lcov.reportPaths)

I have added that sonar.exclusions=src/test and it worked. I am also making one mistake that I have added coverage folder inside my gitignore that’s why it is not able to get that coverage/lcov.info file.

Really Appreciated! Thanks for you help. @Colin

1 Like

Just a little tangent, but I was wondering exactly what you meant by the reference to the .gitignore and coverage/lcov.info.

You’re making it sound like having the coverage/lcov.info file (or the entire folder) in your .gitignore was a mistake. That is not a mistake. It is entirely appropriate. Putting “coverage/*” in your .gitignore will make git ignore those files, which is correct. You definitely do not want to check in that file.

3 Likes

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