Skip to content

Commit a08fe83

Browse files
committed
1.1.8
- fixes coverage api to sort before limit is run - adds more examples to storybook - fixes error not propagating on main coverage page - fixes a bug when parsing coverage which stops NaN values from being added to array - abstracts CLI functionality into library to add more extensive tests
1 parent 8ef37a1 commit a08fe83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+695
-421
lines changed

.storybook/config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'psychic.css/dist/psychic.min.css';
2+
13
import { configure } from '@storybook/react';
24

35
function loadStories() {

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.1.8 (10/27/2017)
2+
3+
- fixes coverage api to sort before limit is run
4+
- adds more examples to storybook
5+
- fixes error not propagating on main coverage page
6+
- fixes a bug when parsing coverage which stops NaN values from being added to array
7+
- abstracts CLI functionality into library to add more extensive tests
8+
19
# 1.1.7 (10/25/2017)
210

311
- includes moment as a production dependency

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# lcov-server [docs](https://www.gabrielcsapo.com/lcov-server)
1+
# lcov-server [[docs](https://www.gabrielcsapo.com/lcov-server)][[hosted](https://lcov-server.gabrielcsapo.com)]
22

33
> 🎯 A simple lcov server & cli parser
44

bin/lcov-server.js

+10-94
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,9 @@
33
require('babel-polyfill');
44

55
const program = require('commander');
6-
const http = require('http');
7-
const https = require('https');
8-
const fs = require('fs');
9-
const Path = require('path');
10-
const Url = require('url');
116
const updateNotifier = require('update-notifier');
127

13-
const lcov = require('../lib/lcov');
14-
const cobertura = require('../lib/cobertura');
15-
const golang = require('../lib/golang');
16-
const jacoco = require('../lib/jacoco');
17-
18-
const git = require('../lib/git');
19-
const ci = require('../lib/ci');
8+
const cli = require('../lib/cli');
209

2110
const pkg = require('../package.json');
2211

@@ -43,95 +32,22 @@ if(serve) {
4332

4433
require('../index');
4534
} else {
46-
const parsedUrl = Url.parse(upload);
47-
4835
let input = '';
4936
process.stdin.resume();
5037
process.stdin.setEncoding('utf8');
5138
process.stdin.on('data', (chunk) => {
5239
input += chunk;
5340
});
5441
process.stdin.on('end', (async () => {
55-
const env = ci();
56-
const output = {
57-
service_job_id: env.service_job_id,
58-
service_pull_request: env.service_pull_request,
59-
service_name: env.service_name,
60-
source_files: [],
61-
git: {
62-
commit: env.commit,
63-
branch: env.branch,
64-
message: env.message,
65-
committer_name: env.committer_name,
66-
committer_email: env.committer_email
67-
},
68-
run_at: new Date()
69-
};
70-
71-
let _lcov = {};
72-
switch(parser) {
73-
case 'cobertura':
74-
_lcov = await cobertura.parse(input);
75-
break;
76-
case 'golang':
77-
_lcov = await golang.parse(input);
78-
break;
79-
case 'jacoco':
80-
_lcov = await jacoco.parse(input);
81-
break;
82-
default:
83-
_lcov = await lcov.parse(input);
84-
break;
85-
}
86-
87-
const _git = await git.parse();
88-
89-
// Go through and set the file contents
90-
for (let i = 0; i < _lcov.length; i++) {
91-
let path = basePath ? Path.resolve(process.cwd(), basePath, _lcov[i].file) : _lcov[i].file;
92-
93-
_lcov[i].source = fs.readFileSync(path).toString('utf8');
94-
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
95-
}
96-
97-
output['source_files'] = _lcov;
98-
output['git'] = Object.assign(output['git'], _git);
99-
100-
const options = {
101-
hostname: parsedUrl.hostname,
102-
port: parsedUrl.port || 80,
103-
path: '/api/upload',
104-
method: 'POST',
105-
headers: {
106-
'Content-Type': 'application/json',
107-
}
108-
};
109-
let operation = http;
110-
let data = '';
111-
112-
if(parsedUrl.protocol == 'https:') {
113-
options.port = 443;
114-
operation = https;
42+
try {
43+
let response = cli({ parser, input, url: upload, basePath });
44+
if(response.error) {
45+
console.error(`coverage not sent with reason:\n ${response.error}`); // eslint-disable-line
46+
} else {
47+
console.log('\n coverage sent successfully 💚 \n'); // eslint-disable-line
48+
}
49+
} catch(ex) {
50+
console.error(`coverage could not be parsed with reason:\n ${ex.toString()}`); // eslint-disable-line
11551
}
116-
117-
let req = operation.request(options, (res) => {
118-
res.on('data', (chunk) => {
119-
data += chunk;
120-
});
121-
res.on('end', () => {
122-
try {
123-
const response = JSON.parse(data);
124-
if(response.error) {
125-
console.error(response.error); // eslint-disable-line
126-
} else {
127-
console.log(`\n coverage sent successfully 💚 \n`); // eslint-disable-line
128-
}
129-
} catch(ex) {
130-
console.log(`\n uhoh something went wrong, ${ex.toString()}`); // eslint-disable-line
131-
}
132-
});
133-
});
134-
req.write(JSON.stringify(output));
135-
req.end();
13652
}));
13753
}

dist/bundle.js

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

dist/vendor.bundle.js

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

docs/code/coverage.js.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ <h1 class="page-title">coverage.js</h1>
199199
module.exports.get = function get(repo, limit) {
200200
return new Promise((resolve, reject) => {
201201
let options = [
202+
{ $sort: { "run_at": -1 } },
202203
{ $match: { "git.remotes.url": repo } },
203204
{ $limit: parseInt(limit) },
204205
{
@@ -211,7 +212,7 @@ <h1 class="page-title">coverage.js</h1>
211212
}];
212213

213214
if(!limit) {
214-
delete options[1];
215+
delete options[2];
215216
options = options.filter((n) => n !== undefined);
216217
}
217218

docs/code/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Coverage.
4646

4747

4848
<section class="readme">
49-
<article><h1>lcov-server <a href="https://www.gabrielcsapo.com/lcov-server">docs</a></h1><blockquote>
49+
<article><h1>lcov-server [<a href="https://www.gabrielcsapo.com/lcov-server">docs</a>][<a href="https://lcov-server.gabrielcsapo.com">hosted</a>]</h1><blockquote>
5050
<p>🎯 A simple lcov server &amp; cli parser</p>
5151
</blockquote>
5252
<p><a href="https://www.npmjs.com/package/lcov-server"><img src="https://img.shields.io/npm/v/lcov-server.svg" alt="Npm Version"></a>

docs/example.png

428 KB
Loading

docs/index.html

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

docs/storybook/iframe.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<body>
1818
<div id="root"></div>
1919
<div id="error-display"></div>
20-
<script src="static/preview.01ae41e870d6bfc88cfd.bundle.js"></script>
20+
<script src="static/preview.a8c92ec89fd752a174d8.bundle.js"></script>
2121
</body>
2222
</html>
2323

docs/storybook/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<head>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<meta name="storybook-version" content="3.2.12">
7+
<meta name="storybook-version" content="3.2.13">
88
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
99
<title>Storybook</title>
1010
<style>
@@ -40,7 +40,7 @@
4040
</head>
4141
<body style="margin: 0;">
4242
<div id="root"></div>
43-
<script src="static/manager.636402f6d36656349933.bundle.js"></script>
43+
<script src="static/manager.09f65c282c57cf833204.bundle.js"></script>
4444
</body>
4545
</html>
4646

docs/storybook/static/manager.09f65c282c57cf833204.bundle.js

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

docs/storybook/static/manager.636402f6d36656349933.bundle.js

-1
This file was deleted.

docs/storybook/static/preview.01ae41e870d6bfc88cfd.bundle.js

-1
This file was deleted.

docs/storybook/static/preview.a8c92ec89fd752a174d8.bundle.js

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

lib/cli.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
const fs = require('fs');
2+
const Path = require('path');
3+
const Url = require('url');
4+
const http = require('http');
5+
const https = require('https');
6+
7+
const lcov = require('../lib/lcov');
8+
const cobertura = require('../lib/cobertura');
9+
const golang = require('../lib/golang');
10+
const jacoco = require('../lib/jacoco');
11+
12+
const git = require('../lib/git');
13+
const ci = require('../lib/ci');
14+
15+
module.exports = function cli({ parser, input, url, basePath }) {
16+
const parsedUrl = Url.parse(url);
17+
18+
return new Promise(async function(resolve, reject) {
19+
const env = ci();
20+
const output = {
21+
service_job_id: env.service_job_id,
22+
service_pull_request: env.service_pull_request,
23+
service_name: env.service_name,
24+
source_files: [],
25+
git: {
26+
commit: env.commit,
27+
branch: env.branch,
28+
message: env.message,
29+
committer_name: env.committer_name,
30+
committer_email: env.committer_email
31+
},
32+
run_at: new Date()
33+
};
34+
35+
let _lcov = {};
36+
switch(parser) {
37+
case 'cobertura':
38+
_lcov = await cobertura.parse(input);
39+
break;
40+
case 'golang':
41+
_lcov = await golang.parse(input);
42+
break;
43+
case 'jacoco':
44+
_lcov = await jacoco.parse(input);
45+
break;
46+
default:
47+
_lcov = await lcov.parse(input);
48+
break;
49+
}
50+
51+
// Go through and set the file contents
52+
for (let i = 0; i < _lcov.length; i++) {
53+
let path = basePath ? Path.resolve(process.cwd(), basePath, _lcov[i].file) : _lcov[i].file;
54+
55+
if(fs.existsSync(path)) {
56+
_lcov[i].source = fs.readFileSync(path).toString('utf8');
57+
_lcov[i].title = _lcov[i].file.substring(_lcov[i].file.lastIndexOf('/') + 1, _lcov[i].file.length);
58+
} else {
59+
return reject(`can not find file at ${path}`);
60+
}
61+
}
62+
63+
output['source_files'] = _lcov;
64+
output['git'] = Object.assign(output['git'], await git.parse());
65+
66+
const options = {
67+
hostname: parsedUrl.hostname,
68+
port: parsedUrl.port || 80,
69+
path: '/api/upload',
70+
method: 'POST',
71+
headers: {
72+
'Content-Type': 'application/json',
73+
}
74+
};
75+
let operation = http;
76+
let data = '';
77+
78+
if(parsedUrl.protocol == 'https:') {
79+
options.port = 443;
80+
operation = https;
81+
}
82+
83+
let req = operation.request(options, (res) => {
84+
res.on('data', (chunk) => {
85+
data += chunk;
86+
});
87+
res.on('end', () => {
88+
try {
89+
const response = JSON.parse(data);
90+
if(response.error) {
91+
return reject(response.error); // eslint-disable-line
92+
} else {
93+
return resolve(response);
94+
}
95+
} catch(ex) {
96+
return reject(ex);
97+
}
98+
});
99+
});
100+
req.write(JSON.stringify(output));
101+
req.end();
102+
});
103+
};

lib/coverage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ module.exports.repos = function repos(repo) {
160160
module.exports.get = function get(repo, limit) {
161161
return new Promise((resolve, reject) => {
162162
let options = [
163+
{ $sort: { "run_at": -1 } },
163164
{ $match: { "git.remotes.url": repo } },
164165
{ $limit: parseInt(limit) },
165166
{
@@ -172,7 +173,7 @@ module.exports.get = function get(repo, limit) {
172173
}];
173174

174175
if(!limit) {
175-
delete options[1];
176+
delete options[2];
176177
options = options.filter((n) => n !== undefined);
177178
}
178179

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lcov-server",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "🎯 A simple lcov server & cli parser",
55
"main": "index.js",
66
"homepage": "https://github.com/gabrielcsapo/lcov-server#readme",
@@ -24,7 +24,7 @@
2424
"start": "./bin/lcov-server.js --serve",
2525
"dev": "NODE_ENV=development webpack-dev-server --hot --port 5000",
2626
"pack": "pkg bin/lcov-server.js -c package.json -o packed/lcov-server",
27-
"generate-docs": "tryitout --template=landing --output=./docs && jsdoc -c jsdoc.json",
27+
"generate-docs": "tryitout --output=docs --template=product && jsdoc -c jsdoc.json",
2828
"storybook": "start-storybook -p 6006",
2929
"build-storybook": "build-storybook --output-dir ./docs/storybook"
3030
},
@@ -75,7 +75,7 @@
7575
"body-parser": "^1.18.2",
7676
"css-loader": "^0.28.7",
7777
"docdash": "^0.4.0",
78-
"eslint": "^4.9.0",
78+
"eslint": "^4.10.0",
7979
"eslint-plugin-react": "^7.4.0",
8080
"getstorybook": "^1.7.0",
8181
"highlight.js": "^9.12.0",
@@ -91,7 +91,7 @@
9191
"style-loader": "^0.19.0",
9292
"tap": "^10.7.2",
9393
"tape": "^4.8.0",
94-
"tryitout": "^0.3.6",
94+
"tryitout": "^0.3.7",
9595
"webpack": "^3.8.1",
9696
"webpack-dev-server": "^2.9.3",
9797
"whatwg-fetch": "^2.0.3"

src/app.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'whatwg-fetch';
21
import 'psychic.css/dist/psychic.min.css';
32
import './style.css';
43

src/components/table.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Table extends React.Component {
4747
return <td key={`${k}/${i}`}> <div className={ k === 'Commit' ? 'coverage-commit-message' : ''}>{ h[k] }</div> </td>;
4848
})}
4949
</tr>);
50-
}) }
50+
}, []) }
5151
</tbody>
5252
</table>
5353
{ data.length > 1 ?
@@ -65,13 +65,11 @@ class Table extends React.Component {
6565

6666
Table.propTypes = {
6767
data: PropTypes.array,
68-
sort: PropTypes.string,
6968
chunk: PropTypes.number
7069
};
7170

7271
Table.defaultProps = {
7372
data: [],
74-
sort: '',
7573
chunk: 5
7674
};
7775

src/coverage/coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Coverage extends React.Component {
141141
<h4> Source Files ({ history[0].source_files.length })</h4>
142142
<Table data={history[0].source_files.map(this.reduceSourceFiles.bind(this))} chunk={5}/>
143143
<h4> Recent Builds ({ history.length })</h4>
144-
<Table data={history.map(this.reduceBuilds)} sort={"Recieved"} chunk={9}/>
144+
<Table data={history.map(this.reduceBuilds)} chunk={9}/>
145145
</div>
146146
</div>);
147147
} else {

0 commit comments

Comments
 (0)