Issue #79 - Move coverage percentage logic to coverage parse logic (#124)

This commit is contained in:
Dottori 2018-02-15 15:19:29 -05:00 коммит произвёл Armen Zambrano
Родитель 26e585893a
Коммит ddd9942b0c
3 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -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 = (
<div
className="coverage-percentage"
style={{ backgroundColor: `${getPercentCovColor(coveredLines / totalLines)}` }}
style={{ backgroundColor: `${getPercentCovColor(coverage.percentage)}` }}
>
{((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
</div>
);
} else {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;
};