UNPKG

debt-collector

Version:

a nodejs tool to identify, track and mesure technical debt

18 lines (17 loc) 810 B
const getSatementOrFunctionCoverage = (coverage, key) => { const length = Object.values(coverage[key]).length; const nbZeros = Object.values(coverage[key]).filter((value) => value === 0).length; return (length - nbZeros) / length; }; export const getFileCoverage = (coverage) => { const statementsCoverage = getSatementOrFunctionCoverage(coverage, 's'); const functionsCoverage = getSatementOrFunctionCoverage(coverage, 'f'); const allBranches = Object.values(coverage.b).flat(); const nbZerosBranches = allBranches.filter((value) => value === 0).length; const branchesCoverage = (allBranches.length - nbZerosBranches) / allBranches.length; return { statements: statementsCoverage, branches: branchesCoverage, functions: functionsCoverage, }; };