Jareth
Jareth

Reputation: 441

Sonarqube test report "report refers to a file which is not configured as a test file" when tests and source are together

I am using TypeScript and Jest and have my tests next to my source files. e.g:

When I try and import the text-report.xml (which looks to be fine and matches the format), I get an error saying:

'Line X report refers to a file which is not configured as a test file: /someDir/someCode.spec.ts'

What configuration do I need in in the Sonarqube properties so that it understand which files are tests and which are source?

Upvotes: 12

Views: 16769

Answers (4)

Jareth
Jareth

Reputation: 441

Seems it doesn't detect files in sub-folders using ".". Only way I was able to get it working was to list all of the folders.

sonar.sources=helpers,managers,routes,schemas,types
sonar.tests=helpers,managers,routes,schemas,types
sonar.exclusions=**/*.js,test-data,dist,coverage
sonar.test.inclusions=**/*.spec.ts
sonar.testExecutionReportPaths=test-report.xml
sonar.javascript.lcov.reportPaths=coverage/lcov.info

Upvotes: 13

Dmitri R117
Dmitri R117

Reputation: 2822

A bad value in the sonar.test.inclusions= setting in the sonar.properties (or whatever SQ filename you are using for properties) file is what caused the error for me. Sonar needs that setting to identify the test files.

You can use something like:

sonar.test.inclusions=src/__test__/**/*.test.ts,src/**/*.spec.ts

Upvotes: 0

RAVI SINGH
RAVI SINGH

Reputation: 409

For me even after adding sonar.test.inclusions=**/*-spec.js , test reports were not coming. It worked after adding sonar.tests=.(same as sonar.sources)

Upvotes: 2

ttoshev
ttoshev

Reputation: 156

You can try

sonar.sources = **/someDir/**/*
sonar.tests = **/someDir/*
//or
sonar.sources = **/someDir/*
sonar.tests = **/someDir/*

Depending on if you have any sub-directories. Might be a better alternative to listing all locations for both tests and sources.

Upvotes: 4

Related Questions