[code-coverage] fix jacoco to not require scm-only

Currently the jacoco plugin only works if you have the annotation set to
scm-only.

Signed-off-by: Rickard Dybeck <dybeck@spotify.com>
This commit is contained in:
Rickard Dybeck
2024-02-26 10:50:54 -05:00
parent 8cc5dd9d29
commit cceebae5ac
3 changed files with 16 additions and 3 deletions
@@ -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,
});