Sonar Ignoring test coverage of test runner files

Using SonarQube 8.3.1.34397 and sonar-scanner-4.3.0.2102-linux

I am having trouble getting SonarQube to ignore files for test coverage. I have a JS repository utilizing Jest for test coverage metrics and the test runners are in a file next to the .js file with a name of .test.js. For example functions.js has tests in a file next to it in functions.test.js. SonarQube finds all of the .js files and treats them as sources files and reports no coverage on the .test.js files.

I have Jest outputting lcov reports and point SonarQube to the lcov.info file:

sonar.javascript.lcov.reportPaths=./test-js/coverage/lcov.info

I have sources set as:

sonar.sources=.
sonar.exclusions=**/node_modules/**/*, \
    **/external/**/*, \
    ./test-js/**/*.test.js, \
    ./test-js/jest.config.js, \

I have tests set as:

sonar.tests=.
sonar.test.inclusions= ./test-js/**/*.test.js, \
    ./test-js/jest.config.js, \

I have also tried adding:

sonar.coverage.exclusions=./test-js/**/*.test.js, \
    ./test-js/jest.config.js, \

But nothing I’ve tried seems to work. I’ve tried all various combinations of the above and nothing seems make SonarQube ignore the .test.js files.

Anybody have any ideas?

1 Like

I think I may have found my issue - it didn’t like the ‘./’ prefix on those paths…

I was able to get it working with this config:

# where source files are
sonar.sources=.
sonar.exclusions= \
    **/external/**/*, \

# files to ignore for coverage
sonar.coverage.exclusions= \
    test-js/**/*.test.js, \
    test-js/jest.config.js, \

# files to get coverage information
sonar.javascript.lcov.reportPaths=test-js/coverage/lcov.info