Skip to content

Commit

Permalink
1.1.5
Browse files Browse the repository at this point in the history
- guards retrieval of values
- sets the default parser to lcov
  • Loading branch information
gabrielcsapo committed Oct 26, 2017
1 parent 9b9ebad commit 9edc40b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage
docs
dist
npm-debug.log
distributed
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.1.5 (10/25/2017)

- guards retrieval of values
- sets the default parser to lcov

# 1.1.4 (10/24/2017)

- removes babel-register, ships a pre-compiled bundle
Expand Down
6 changes: 3 additions & 3 deletions bin/lcov-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ if(serve) {

let _lcov = {};
switch(parser) {
case 'lcov':
_lcov = await lcov.parse(input);
break;
case 'cobertura':
_lcov = await cobertura.parse(input);
break;
Expand All @@ -82,6 +79,9 @@ if(serve) {
case 'jacoco':
_lcov = await jacoco.parse(input);
break;
default:
_lcov = await lcov.parse(input);
break;
}

const _git = await git.parse();
Expand Down
4 changes: 2 additions & 2 deletions dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcov-server",
"version": "1.1.4",
"version": "1.1.5",
"description": "🎯 A simple lcov server & cli parser",
"main": "index.js",
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
Expand Down
42 changes: 26 additions & 16 deletions src/coverage/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,22 @@ class Coverage extends React.Component {
const { lines, branches, functions } = history.source_files[0];
allBranches.push(git.branch || git.git_branch);

if(selectedBranch && selectedBranch === (git.branch || git.git_branch)) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
} else if(!selectedBranch) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
if(lines && branches && functions) {
if(selectedBranch && selectedBranch === (git.branch || git.git_branch)) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
} else if(!selectedBranch) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
} else {
// noop
}
} else {
// noop
data[0].push(0)
data[1].push(0)
data[2].push(0)
}
}, []);

Expand All @@ -87,8 +93,10 @@ class Coverage extends React.Component {

function reduceBuilds(build) {
let totalCoverage = build.source_files.map((f) => {
const totalFound = f.lines.found + f.branches.found + f.functions.found;
const totalHit = f.lines.hit + f.branches.hit + f.functions.hit;
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = f;

const totalFound = lines.found + branches.found + functions.found;
const totalHit = lines.hit + branches.hit + functions.hit;
const totalCoverage = parseInt((totalHit / totalFound) * 100);
return totalCoverage;
}, []).reduce((p, c, _ ,a) => p + c / a.length, 0);
Expand All @@ -107,8 +115,10 @@ class Coverage extends React.Component {
});

function reduceSourceFiles(file) {
const totalFound = file.lines.found + file.branches.found + file.functions.found;
const totalHit = file.lines.hit + file.branches.hit + file.functions.hit;
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = file;

const totalFound = lines.found + branches.found + functions.found;
const totalHit = lines.hit + branches.hit + functions.hit;
const totalCoverage = parseInt((totalHit / totalFound) * 100);
const fileName = encodeURIComponent(file.title).replace(/\./g, '$2E');

Expand All @@ -117,9 +127,9 @@ class Coverage extends React.Component {
"File": <a href={`/coverage/${source.replace(/\./g, '%2E')}/${owner}/${name}/${fileName}`}>
{ file.title }
</a>,
"Lines": `${file.lines.hit} / ${file.lines.found}`,
"Branches": `${file.branches.hit} / ${file.branches.found}`,
"Functions": `${file.functions.hit} / ${file.functions.found}`
"Lines": `${lines.hit} / ${lines.found}`,
"Branches": `${branches.hit} / ${branches.found}`,
"Functions": `${functions.hit} / ${functions.found}`
}
}

Expand Down
21 changes: 13 additions & 8 deletions src/coverage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ class File extends React.Component {
project.history.forEach((h) => {
h.source_files.forEach((f) => {
if(f.title === file) {
const { lines, branches, functions } = f;
const linePercentage = parseInt(((lines.hit / lines.found) || 1) * 100);
const branchPercentage = parseInt(((branches.hit / branches.found) || 1) * 100);
const functionPercentage = parseInt(((functions.hit / functions.found) || 1) * 100);
data[0].push(linePercentage);
data[1].push(branchPercentage);
data[2].push(functionPercentage);
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = f;

if(lines && branches && functions) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
} else {
data[0].push(0)
data[1].push(0)
data[2].push(0)
}
}
});
});
Expand All @@ -73,7 +77,8 @@ class File extends React.Component {
data[2].push(data[2][0])
}

const { lines, branches, functions } = fileSource;
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = fileSource;

lines.details.forEach((l) => {
lineMap[l.line - 1] = l.hit;
});
Expand Down
16 changes: 11 additions & 5 deletions src/coverage/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import parse from 'git-url-parse';
import CoverageChart from './chart';
import Error from '../components/error';

class Coverages extends React.Component {
class ListItem extends React.Component {
constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -50,9 +50,15 @@ class Coverages extends React.Component {
const data = [[], [], []];
history.forEach(function(history) {
const { lines, branches, functions } = history.source_files[0];
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
if(lines && branches && functions) {
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
} else {
data[0].push(0)
data[1].push(0)
data[2].push(0)
}
}, []);
// If there is only one data point
// add another that is the same value to make a line
Expand Down Expand Up @@ -107,4 +113,4 @@ class Coverages extends React.Component {
}
}

export default Coverages;
export default ListItem;

0 comments on commit 9edc40b

Please sign in to comment.