diff --git a/src/utils/coverage.ts b/src/utils/coverage.ts index bdbb30bd..03ab3ce5 100644 --- a/src/utils/coverage.ts +++ b/src/utils/coverage.ts @@ -36,10 +36,10 @@ export const mapTestResults = (testResults: T[]) })); export const generateCoveredLines = (cov: CodeCoverage): [number[], number[]] => { - const [lineCount, uncoveredLineCount] = getCoverageNumbers(cov); + const [lineCount] = getCoverageNumbers(cov); const uncoveredLines = ensureArray(cov.locationsNotCovered).map((location) => parseInt(location.line, 10)); const minLineNumber = uncoveredLines.length ? Math.min(...uncoveredLines) : 1; - const lines = [...Array(lineCount + uncoveredLineCount).keys()].map((i) => i + minLineNumber); + const lines = [...Array(lineCount).keys()].map((i) => i + minLineNumber); const coveredLines = lines.filter((line) => !uncoveredLines.includes(line)); return [uncoveredLines, coveredLines]; }; diff --git a/test/utils/coverage.test.ts b/test/utils/coverage.test.ts index a6d0bcf1..cb93e634 100644 --- a/test/utils/coverage.test.ts +++ b/test/utils/coverage.test.ts @@ -8,7 +8,7 @@ import { expect } from 'chai'; import { ApexTestResultOutcome } from '@salesforce/apex-node'; import { StandardColors } from '@salesforce/sf-plugins-core'; -import { coverageOutput, getCoveragePct, mapTestResults } from '../../src/utils/coverage.js'; +import { coverageOutput, generateCoveredLines, getCoveragePct, mapTestResults } from '../../src/utils/coverage.js'; // methods are mutating the object instead of returning new ones function getSampleTestResult() { @@ -373,6 +373,9 @@ describe('coverage utils', () => { it('1 uncovered of 4', () => { expect(getCoveragePct(getSampleTestResult().codeCoverage[0])).equal(75); }); + it('will generate covered lines correctly', () => { + expect(generateCoveredLines(getSampleTestResult().codeCoverage[0])).to.deep.equal([[12], [13, 14, 15]]); + }); it('rounds 3 uncovered out of 44 to the nearest integer', () => { expect(getCoveragePct(getSampleTestResult().codeCoverage[1])).equal(93); });