forked from romeovs/lcov-reporter-action
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: more testeable code, multiple comments
- Loading branch information
Andres Adjimann
committed
Sep 11, 2023
1 parent
0a2dcdf
commit 42d0a9b
Showing
9 changed files
with
260 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
import { percentage } from "./lcov"; | ||
|
||
export const checkCoverage = (minCoverage, toCheck) => { | ||
const checkCoverage = (toCheck) => { | ||
let accum = 0; | ||
for (const lcovObj of toCheck) { | ||
const coverage = percentage(lcovObj.lcov); | ||
const isValidBuild = coverage >= minCoverage; | ||
const isValidBuild = coverage >= toCheck.minCoverage; | ||
if (!isValidBuild) { | ||
return { isValidBuild, coverage, name: lcovObj.packageName }; | ||
} | ||
accum += coverage; | ||
} | ||
|
||
return { | ||
isValidBuild: true, | ||
coverage: toCheck.length === 0 ? 0 : accum / toCheck.length, | ||
name: "average", | ||
}; | ||
}; | ||
|
||
export const checks = ({ rootLcov, lcovArray, options, setFailed, info }) => { | ||
const excludedFiles = (options.excluded || "") | ||
.split(" ") | ||
.map((x) => x.trim()) | ||
.filter((x) => x.length > 0); | ||
const toCheck = lcovArray | ||
.filter((x) => !excludedFiles.some((y) => x.packageName === y)) | ||
.map((x) => ({ minCoverage: options.minCoverage, ...x })); | ||
if (rootLcov && !options.excludeRoot) { | ||
toCheck.unshift({ | ||
packageName: "root_package", | ||
lcov: rootLcov, | ||
minCoverage: options.minCoverage, | ||
}); | ||
} | ||
const { isValidBuild, coverage, name } = checkCoverage(toCheck); | ||
if (!isValidBuild) { | ||
setFailed( | ||
`${coverage.toFixed(2)}% for ${name} is less than min_coverage ${ | ||
options.minCoverage | ||
}.`, | ||
); | ||
} else { | ||
info( | ||
`Coverage: ${coverage.toFixed( | ||
2, | ||
)}% is greater than or equal to min_coverage ${ | ||
options.minCoverage | ||
}.`, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { readLcov } from "./monorepo"; | ||
import { comments } from "./comment"; | ||
import { checks } from "./check"; | ||
import { badges } from "./badge"; | ||
|
||
export const codeCoverageAssistant = async ({ | ||
readLCovs, | ||
lcovFile, | ||
baseFile, | ||
options, | ||
upsert, | ||
mkDir, | ||
writeBadge, | ||
setFailed, | ||
info, | ||
}) => { | ||
const lcovArray = await readLCovs("lcov.info"); | ||
const lcovBaseArray = | ||
lcovArray.length > 0 && (await readLCovs("lcov-base")); | ||
// Always process root file if exists. | ||
const rootLcov = lcovFile && (await readLcov(lcovFile)); | ||
const rootBaseLcov = rootLcov && baseFile && (await readLcov(baseFile)); | ||
// We cannot comment if is not a pull_request | ||
if (options.pullRequest && options.maxLines > 0) { | ||
await comments({ | ||
rootLcov, | ||
rootBaseLcov, | ||
lcovArray, | ||
lcovBaseArray, | ||
options, | ||
upsert, | ||
}); | ||
} | ||
if (options.badgePath) { | ||
await badges({ rootLcov, lcovArray, options, mkDir, writeBadge }); | ||
} | ||
if (options.minCoverage) { | ||
await checks({ rootLcov, lcovArray, options, setFailed, info }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.