Multi-module generic test execution report not picked up by scanner

Scenario:

  • nodejs project with two subdirectories, each of which contain a separate sub-module
  • configuration:
sonar.sources=
sonar.sourceEncoding=UTF-8

sonar.modules=cdk, code

cdk.sonar.projectBaseDir=cdk
cdk.sonar.sources=lib

code.sonar.projectName=code
code.sonar.projectBaseDir=code
code.sonar.sources=src
code.sonar.tests=test

sonar.javascript.lcov.reportPaths=code/coverage/lcov.info
sonar.testExecutionReportPaths=code/coverage/test_results.xml

Problem:

  • test execution reports and coverage reports are not picked up by scanner
    Both of the files, lcov.info and test_results.xml contain relative paths, like: test/.../.../<>.ts.

The problem here is that the relative path does not contain code - what is correct, because the tests are run from within the code directory and the scanner says they are ignored:

15:00:59.118 DEBUG: 'code/test/model/user.spec.ts' indexed as test with language 'ts'
...
15:01:10.570 INFO: Test execution data ignored for 5 unknown files, including:
test/model/user.spec.ts

The documentation states:
The value specified here becomes the new “analysis directory”, and other paths are then specified as though the analysis were starting from the specified value of sonar.projectBaseDir.

That means that setting code.sonar.projectBaseDir=code should fix this but it doesn’t. What I can see is that this setting has no effect at all (or it is inferred from the sonar.modules stanza.

Additionally, sonar.javascript.lcov.reportPath cannot be specified per-module because then the scanner ignores it and says that the needed properties were not set.

INFO: SonarScanner 4.5.0.2216
Enterprise EditionVersion 8.5 (build 37579)

PS. This looks really similar to this issue, but it seems noone opened a proper ticket for it.

OK, so it seems that the bug is for sonar.testExecutionReportPaths, that is not module-aware.

I got test execution + coverage to work by the following config & hack:

sonar.sources=
sonar.sourceEncoding=UTF-8

sonar.modules=cdk, code

cdk.sonar.projectBaseDir=cdk
cdk.sonar.sources=lib

code.sonar.projectBaseDir=code
code.sonar.sources=src
code.sonar.tests=test
code.sonar.javascript.lcov.reportPaths=coverage/lcov.info

# this is buggy
sonar.testExecutionReportPaths=code/coverage/test_results.xml

So, the bug is:

  • if I put sonar.testExecutionReportPaths on as code.sonar.testExecutionReportPaths then it is skipped at all
  • for the above configuration to work, i needed to replace all the paths in code/coverage/test_results.xml to be code/test/ instead of test/

Hi,

Glad you got it to work.
Yes, the Generic reports are only loaded once for the entire project, not for each module. The paths in it must be relative to the root project directory.
I couldn’t find the text you quoted in the documentation, but I see that documentation mentions:

Insert a file element for each test file. Its path attribute can be either absolute or relative to the root of the module.

This is incorrect because the file paths need to be relative to the project (root module). We’ll fix this.

Thanks for the reply. The cited paragraph is on that page for projectBaseDir.

I consider this still as a missing functionality (if not a bug), it should be possible to specify
Otherwise this is inconsistent with the ability to specify sonar.testExecutionReportPaths per module, the same way as lcov configuration.