diff --git a/src/components/fileviewercov.js b/src/components/fileviewercov.js index 4c3a1ff..1319611 100644 --- a/src/components/fileviewercov.js +++ b/src/components/fileviewercov.js @@ -91,17 +91,15 @@ const Test = ({ row, test, expand, handleTestOnExpand }) => ( // shows coverage percentage of a file export const CoveragePercentageViewer = ({ coverage }) => { - const coveredLines = coverage.coveredLines.length; - const totalLines = coveredLines + coverage.uncoveredLines.length; let percentageCovered; - if (coveredLines !== 0 || coverage.uncoveredLines.length !== 0) { + if (coverage.percentage) { percentageCovered = (
- {((coveredLines / totalLines) * 100).toPrecision(4)} - % - {coveredLines} lines covered out of {totalLines} coverable lines + {coverage.percentage.toPrecision(4)} + % - {coverage.numCovLines} lines covered out of {coverage.numTotalLines} coverable lines
); } else { diff --git a/src/utils/color.js b/src/utils/color.js index 0ec5d4b..8e8e645 100644 --- a/src/utils/color.js +++ b/src/utils/color.js @@ -2,6 +2,6 @@ import * as Chroma from 'chroma-js'; const getPercentCovColor = percent => // warm red, lemon yellow, neon green - Chroma.scale(['#ff4f5e', '#fff44f', '#54ffbd']).mode('lab')(percent); + Chroma.scale(['#ff4f5e', '#fff44f', '#54ffbd']).mode('lab')(percent / 100); export default getPercentCovColor; diff --git a/src/utils/data.js b/src/utils/data.js index 126e100..6010d69 100644 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -63,6 +63,12 @@ export const fileRevisionCoverageSummary = (coverage) => { }); }); s.uncoveredLines = _.uniq(s.uncoveredLines); + // calculate line coverage stats + s.numCovLines = s.coveredLines.length; + s.numUncovLines = s.uncoveredLines.length; + s.numTotalLines = s.numCovLines + s.numUncovLines; + s.percentage = (s.numCovLines !== 0 || + s.numUncovLines !== 0) ? ((s.numCovLines / s.numTotalLines) * 100) : undefined; return s; };