apex-code-coverage-transformer
Version:
Transform Salesforce Apex code coverage JSONs into other formats accepted by SonarQube, GitHub, GitLab, Azure, Bitbucket, etc.
46 lines • 1.5 kB
JavaScript
;
import { BaseHandler } from './BaseHandler.js';
import { HandlerRegistry } from './HandlerRegistry.js';
/**
* Handler for generating SonarQube Generic Coverage reports.
*
* This is the default format and is compatible with SonarQube and SonarCloud.
*
* @see https://docs.sonarqube.org/latest/analysis/generic-test/
*/
export class SonarCoverageHandler extends BaseHandler {
coverageObj;
constructor() {
super();
this.coverageObj = { coverage: { '@version': '1', file: [] } };
}
processFile(filePath, _fileName, lines) {
const fileObj = {
'@path': filePath,
lineToCover: [],
};
for (const [lineNumberString, value] of Object.entries(lines)) {
const covered = value === 1;
fileObj.lineToCover.push({
'@lineNumber': Number(lineNumberString),
'@covered': covered,
});
}
this.coverageObj.coverage.file.push(fileObj);
}
finalize() {
if (this.coverageObj.coverage?.file) {
this.coverageObj.coverage.file = this.sortByPath(this.coverageObj.coverage.file);
}
return this.coverageObj;
}
}
// Self-register this handler
HandlerRegistry.register({
name: 'sonar',
description: 'SonarQube Generic Coverage format',
fileExtension: '.xml',
handler: () => new SonarCoverageHandler(),
compatibleWith: ['SonarQube', 'SonarCloud'],
});
//# sourceMappingURL=sonar.js.map