Merge pull request #23264 from backstage/code-coverage/support-not-setting-scm-only-for-jacoco

[code-coverage] fix jacoco to not require scm-only
This commit is contained in:
Fredrik Adelöw
2024-02-26 19:37:34 +01:00
committed by GitHub
3 changed files with 16 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-code-coverage-backend': patch
---
Fix jacoco convertor to not require annotation to be set to scm-only.
@@ -54,4 +54,10 @@ describe('convert jacoco', () => {
expect(files.sort()).toEqual(expected.sort());
});
it('works when not providing files (as per not setting annotation to scm-only)', () => {
const files = converter.convert(fixture, []);
expect(files).toHaveLength(4);
});
});
@@ -40,7 +40,6 @@ export class Jacoco implements Converter {
*/
convert(xml: JacocoXML, scmFiles: Array<string>): Array<FileEntry> {
const jscov: Array<FileEntry> = [];
xml.report.package.forEach(r => {
const packageName = r.$.name;
r.sourcefile.forEach(sf => {
@@ -68,9 +67,12 @@ export class Jacoco implements Converter {
.map(f => f.trimEnd())
.find(f => f.endsWith(packageAndFilename));
this.logger.debug(`matched ${packageAndFilename} to ${currentFile}`);
if (Object.keys(lineHits).length > 0 && currentFile) {
if (
scmFiles.length === 0 ||
(Object.keys(lineHits).length > 0 && currentFile)
) {
jscov.push({
filename: currentFile,
filename: currentFile || packageAndFilename,
branchHits: branchHits,
lineHits: lineHits,
});