Skip to content

Commit

Permalink
add branches data
Browse files Browse the repository at this point in the history
  • Loading branch information
Azowyl committed Dec 30, 2022
1 parent 09e8e58 commit 75bd54b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/coverallsRequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface CoverallsSourceFile {
name: string;
sourceDigest: string;
coverage: Array<number | null>;
branches: number[];
}

export interface CoverallsRequestObject {
Expand Down Expand Up @@ -54,12 +55,14 @@ class CoverallsRequestBuilder {

withSourceFile(
filePath: string,
coverage: Array<number | null>
coverage: Array<number | null>,
branches: number[]
): CoverallsRequestBuilder {
this.requestObject.sourceFiles = this.requestObject.sourceFiles.concat({
name: filePath,
sourceDigest: FileUtils.md5Digest(filePath),
coverage,
branches,
});

return this;
Expand Down
14 changes: 13 additions & 1 deletion src/parsers/lcov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LcovToCoverallsParser implements CoverallsParser {
this.getLinesCoverage(
data.lines,
FileUtils.linesCount(data.file)
)
),
this.getBranchesData(data.branches)
);
});

Expand All @@ -45,6 +46,17 @@ class LcovToCoverallsParser implements CoverallsParser {

return coverage;
}

private getBranchesData(branchesData: LCOVRecord['branches']): number[] {
return branchesData.details
.map((branchData) => [
branchData.line,
branchData.block,
branchData.branch,
branchData.taken,
])
.flat();
}
}

export default LcovToCoverallsParser;
13 changes: 9 additions & 4 deletions test/fixtures/repo/coverage/lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ FNF:1
FNH:1
FNDA:1,covered
DA:2,1
LF:1
LH:1
BRF:0
BRH:0
DA:3,1
DA:5,0
LF:3
LH:2
BRDA:1,0,0,1
BRDA:2,1,0,1
BRDA:2,1,1,0
BRF:3
BRH:2
end_of_record
TN:
SF:test/fixtures/repo/src/uncovered.ts
Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/repo/src/covered.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
function covered(): number {
return 1 + 1;
function covered(conditional = true): number {
if (conditional) {
return 1 + 1;
} else {
return 2 + 1;
}
}

export default covered;
19 changes: 19 additions & 0 deletions test/parsers/__snapshots__/lcov.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,27 @@ CoverallsRequestBuilder {
"servicePullRequest": "",
"sourceFiles": [
{
"branches": [
1,
0,
0,
1,
2,
1,
0,
1,
2,
1,
1,
0,
],
"coverage": [
null,
1,
1,
null,
0,
null,
null,
null,
null,
Expand All @@ -22,6 +40,7 @@ CoverallsRequestBuilder {
"sourceDigest": "sourceDigest",
},
{
"branches": [],
"coverage": [
null,
0,
Expand Down

0 comments on commit 75bd54b

Please sign in to comment.