karma-sonarqube-reporter
A Karma reporter plugin for generating SonarQube generic test reports.
Installation
npm install karma-sonarqube-reporter --save-dev
Configuration
Adjust your karma.conf.js
file:
Create a new plugin entry
plugins: [
require('karma-sonarqube-reporter')
]
Add configuration parameters
sonarqubeReporter: {
basePath: 'src/app',
filePattern: '**/*spec.ts',
outputFolder: 'reports',
encoding: 'utf-8',
reportName: (metadata) => {
return metadata.concat('xml').join('.');
}
}
Activate sonarqube
reporter
reporters: ['sonarqube']
Click here to see a full example.
Running
If your project uses Angular CLI run ng test
and check the output folder.
$ ls reports
firefox.54.0.0.linux.0.0.0.xml
chrome.65.0.3325.linux.0.0.0.xml
The report files' schema is defined on the SonarQube Generic Test Data page.
Add the following property to your sonar-project.properties
:
sonar.testExecutionReportPaths= \
reports/firefox.54.0.0.linux.0.0.0.xml, \
reports/chrome.65.0.3325.linux.0.0.0.xml
Finally, start SonarQube Scanner on your project folder.
That's all!