Skip to content

Commit 9edc40b

Browse files
author
Gabriel J. Csapo
committed
1.1.5
- guards retrieval of values - sets the default parser to lcov
1 parent 9b9ebad commit 9edc40b

9 files changed

+63
-36
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage
33
docs
44
dist
55
npm-debug.log
6+
distributed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.1.5 (10/25/2017)
2+
3+
- guards retrieval of values
4+
- sets the default parser to lcov
5+
16
# 1.1.4 (10/24/2017)
27

38
- removes babel-register, ships a pre-compiled bundle

bin/lcov-server.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ if(serve) {
7070

7171
let _lcov = {};
7272
switch(parser) {
73-
case 'lcov':
74-
_lcov = await lcov.parse(input);
75-
break;
7673
case 'cobertura':
7774
_lcov = await cobertura.parse(input);
7875
break;
@@ -82,6 +79,9 @@ if(serve) {
8279
case 'jacoco':
8380
_lcov = await jacoco.parse(input);
8481
break;
82+
default:
83+
_lcov = await lcov.parse(input);
84+
break;
8585
}
8686

8787
const _git = await git.parse();

dist/bundle.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

+1-1
Large diffs are not rendered by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lcov-server",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "🎯 A simple lcov server & cli parser",
55
"main": "index.js",
66
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",

src/coverage/coverage.js

+26-16
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,22 @@ class Coverage extends React.Component {
6161
const { lines, branches, functions } = history.source_files[0];
6262
allBranches.push(git.branch || git.git_branch);
6363

64-
if(selectedBranch && selectedBranch === (git.branch || git.git_branch)) {
65-
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
66-
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
67-
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
68-
} else if(!selectedBranch) {
69-
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
70-
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
71-
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
64+
if(lines && branches && functions) {
65+
if(selectedBranch && selectedBranch === (git.branch || git.git_branch)) {
66+
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
67+
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
68+
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
69+
} else if(!selectedBranch) {
70+
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
71+
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
72+
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
73+
} else {
74+
// noop
75+
}
7276
} else {
73-
// noop
77+
data[0].push(0)
78+
data[1].push(0)
79+
data[2].push(0)
7480
}
7581
}, []);
7682

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

8894
function reduceBuilds(build) {
8995
let totalCoverage = build.source_files.map((f) => {
90-
const totalFound = f.lines.found + f.branches.found + f.functions.found;
91-
const totalHit = f.lines.hit + f.branches.hit + f.functions.hit;
96+
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = f;
97+
98+
const totalFound = lines.found + branches.found + functions.found;
99+
const totalHit = lines.hit + branches.hit + functions.hit;
92100
const totalCoverage = parseInt((totalHit / totalFound) * 100);
93101
return totalCoverage;
94102
}, []).reduce((p, c, _ ,a) => p + c / a.length, 0);
@@ -107,8 +115,10 @@ class Coverage extends React.Component {
107115
});
108116

109117
function reduceSourceFiles(file) {
110-
const totalFound = file.lines.found + file.branches.found + file.functions.found;
111-
const totalHit = file.lines.hit + file.branches.hit + file.functions.hit;
118+
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = file;
119+
120+
const totalFound = lines.found + branches.found + functions.found;
121+
const totalHit = lines.hit + branches.hit + functions.hit;
112122
const totalCoverage = parseInt((totalHit / totalFound) * 100);
113123
const fileName = encodeURIComponent(file.title).replace(/\./g, '$2E');
114124

@@ -117,9 +127,9 @@ class Coverage extends React.Component {
117127
"File": <a href={`/coverage/${source.replace(/\./g, '%2E')}/${owner}/${name}/${fileName}`}>
118128
{ file.title }
119129
</a>,
120-
"Lines": `${file.lines.hit} / ${file.lines.found}`,
121-
"Branches": `${file.branches.hit} / ${file.branches.found}`,
122-
"Functions": `${file.functions.hit} / ${file.functions.found}`
130+
"Lines": `${lines.hit} / ${lines.found}`,
131+
"Branches": `${branches.hit} / ${branches.found}`,
132+
"Functions": `${functions.hit} / ${functions.found}`
123133
}
124134
}
125135

src/coverage/file.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ class File extends React.Component {
5555
project.history.forEach((h) => {
5656
h.source_files.forEach((f) => {
5757
if(f.title === file) {
58-
const { lines, branches, functions } = f;
59-
const linePercentage = parseInt(((lines.hit / lines.found) || 1) * 100);
60-
const branchPercentage = parseInt(((branches.hit / branches.found) || 1) * 100);
61-
const functionPercentage = parseInt(((functions.hit / functions.found) || 1) * 100);
62-
data[0].push(linePercentage);
63-
data[1].push(branchPercentage);
64-
data[2].push(functionPercentage);
58+
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = f;
59+
60+
if(lines && branches && functions) {
61+
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
62+
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
63+
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
64+
} else {
65+
data[0].push(0)
66+
data[1].push(0)
67+
data[2].push(0)
68+
}
6569
}
6670
});
6771
});
@@ -73,7 +77,8 @@ class File extends React.Component {
7377
data[2].push(data[2][0])
7478
}
7579

76-
const { lines, branches, functions } = fileSource;
80+
const { lines={ found: 0, hit: 0 }, branches={ found: 0, hit: 0 }, functions={ found: 0, hit: 0 } } = fileSource;
81+
7782
lines.details.forEach((l) => {
7883
lineMap[l.line - 1] = l.hit;
7984
});

src/coverage/list-item.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import parse from 'git-url-parse';
55
import CoverageChart from './chart';
66
import Error from '../components/error';
77

8-
class Coverages extends React.Component {
8+
class ListItem extends React.Component {
99
constructor(props) {
1010
super(props);
1111
this.state = {
@@ -50,9 +50,15 @@ class Coverages extends React.Component {
5050
const data = [[], [], []];
5151
history.forEach(function(history) {
5252
const { lines, branches, functions } = history.source_files[0];
53-
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
54-
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
55-
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
53+
if(lines && branches && functions) {
54+
data[0].push(parseInt(((lines.hit / lines.found) || 1) * 100))
55+
data[1].push(parseInt(((branches.hit / branches.found) || 1) * 100))
56+
data[2].push(parseInt(((functions.hit / functions.found) || 1) * 100))
57+
} else {
58+
data[0].push(0)
59+
data[1].push(0)
60+
data[2].push(0)
61+
}
5662
}, []);
5763
// If there is only one data point
5864
// add another that is the same value to make a line
@@ -107,4 +113,4 @@ class Coverages extends React.Component {
107113
}
108114
}
109115

110-
export default Coverages;
116+
export default ListItem;

0 commit comments

Comments
 (0)