0
votes

We are using some sort of custom templating engine that contains normal HTML syntax and some custom tags and among other it can contain some sort of scripting that is executed on the server side. We wrote some unit tests that prove the content of those custom templates and raise error when there are some script elements used that are forbidden.

We are using Jest as test runner and we are creating Sonar Qube test report with jest-sonar-reporter. I have set sonar.tests to point to our tests as sonar.tests=spec. In Sonar Qube UI under Administration > Web area, I have extended sonar.web.file.suffixes with our extension as well. When we start Sonar Qube in our deployment pipeline, I see in the logs

07:08:49.291 INFO: Sensor Generic Test Executions Report
07:08:49.291 WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
07:08:49.291 INFO: Parsing /codebuild/output/src915641274/src/reports/test-report.xml
07:08:49.491 INFO: Imported test execution data for 0 files
07:08:49.491 INFO: Test execution data ignored for 2 unknown files, including:
/codebuild/output/src943613774/src/spec/isml.spec.js
/codebuild/output/src943613774/src/spec/files.spec.js

Our sonar-project.properties look like this:

sonar.host.url=<host_url>
sonar.login=<token>

sonar.projectKey=<project_key>
sonar.projectName=<project_name>

sonar.sources=cartridge,spec

sonar.verbose=true

sonar.inclusions=**/js/**/*.js,**/templates/**/*.isml

sonar.tests=spec
sonar.testExecutionReportPaths=reports/test-report.xml

In this project I have js and web as languages. If I go in Sonar Qube UI and check this project under Measures > Coverage > Tests, I do not see any coverage tests being imported. So my question is did I understand the JUnit coverage import wrong or am I missing something in my Sonar Qube configuration?

1
It appears that your test reports include absolute file paths ("/codebuild/...") do those paths actually exist, or are the leading slashes in error? - G. Ann - SonarSource Team
I just checked generated XML report and the file paths are absolute <file path="/codebuild/output/src560066792/src/spec/isml.spec.js">. Does that mean my file path should begin from spec/isml.spec.js. - daniyel
It may be that your inclusions are interfering with this. Try dropping that parameter & analyzing again - G. Ann - SonarSource Team
This one I should remove or comment out? sonar.inclusions=**/js/**/*.js,**/templates/**/*.isml. Problem is that I would get some bunch of other files in Sonar Qube that I do not want. - daniyel
When you use inclusions, you're saying "analyze only these files", and I believe that's excluding your tests. If you really want to narrow the set, try setting (preferably via the UI) exclusions instead. - G. Ann - SonarSource Team

1 Answers

0
votes

Solution:

The [value] in JUnit report at <file path="[value]">, needs to be relative to the sonar.tests= value.

project
├── src
│   └── ...
└── spec
    ├── isml.spec.js
    └── files.spec.js

So in my case I used sed command and trimmed the "absolute" part of the path.