Skip to content

Commit d4cdac1

Browse files
fix: fix generated code coverage result percent (#1175)
* fix: fix generated code coverage result percent * test: add UT
1 parent fe0d16b commit d4cdac1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/utils/coverage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export const mapTestResults = <T extends Failures | Successes>(testResults: T[])
3636
}));
3737

3838
export const generateCoveredLines = (cov: CodeCoverage): [number[], number[]] => {
39-
const [lineCount, uncoveredLineCount] = getCoverageNumbers(cov);
39+
const [lineCount] = getCoverageNumbers(cov);
4040
const uncoveredLines = ensureArray(cov.locationsNotCovered).map((location) => parseInt(location.line, 10));
4141
const minLineNumber = uncoveredLines.length ? Math.min(...uncoveredLines) : 1;
42-
const lines = [...Array(lineCount + uncoveredLineCount).keys()].map((i) => i + minLineNumber);
42+
const lines = [...Array(lineCount).keys()].map((i) => i + minLineNumber);
4343
const coveredLines = lines.filter((line) => !uncoveredLines.includes(line));
4444
return [uncoveredLines, coveredLines];
4545
};

test/utils/coverage.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { expect } from 'chai';
99
import { ApexTestResultOutcome } from '@salesforce/apex-node';
1010
import { StandardColors } from '@salesforce/sf-plugins-core';
11-
import { coverageOutput, getCoveragePct, mapTestResults } from '../../src/utils/coverage.js';
11+
import { coverageOutput, generateCoveredLines, getCoveragePct, mapTestResults } from '../../src/utils/coverage.js';
1212

1313
// methods are mutating the object instead of returning new ones
1414
function getSampleTestResult() {
@@ -373,6 +373,9 @@ describe('coverage utils', () => {
373373
it('1 uncovered of 4', () => {
374374
expect(getCoveragePct(getSampleTestResult().codeCoverage[0])).equal(75);
375375
});
376+
it('will generate covered lines correctly', () => {
377+
expect(generateCoveredLines(getSampleTestResult().codeCoverage[0])).to.deep.equal([[12], [13, 14, 15]]);
378+
});
376379
it('rounds 3 uncovered out of 44 to the nearest integer', () => {
377380
expect(getCoveragePct(getSampleTestResult().codeCoverage[1])).equal(93);
378381
});

0 commit comments

Comments
 (0)