Skip to content

Commit ee2a4c9

Browse files
committed
added tests
1 parent 457148f commit ee2a4c9

18 files changed

+2846
-72
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
*.log
33
.data
4+
__fixtures__/**/.data

Diff for: .travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
cache: yarn
5+
script: yarn test

Diff for: LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2017-present Ajay Narain Mathur <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

Diff for: README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# build-stats
2+
3+
> Get the stats of your pipeline.
4+
5+
![preview](preview.png)
6+
7+
## Install
8+
9+
```sh
10+
yarn global add build-stats
11+
```
12+
13+
## Example
14+
15+
```js
16+
build-stats travis:boltpkg/bolt download // download the build data
17+
build-stats travis:boltpkg/bolt calculate // calculate the build stats from downloaded data
18+
```
19+
20+
## Usage
21+
22+
```sh
23+
build-stats <ciTool>:<user>/<repo> [command] --period <p> --last <l>
24+
```
25+
26+
### `ciTool`
27+
28+
ciTool - The ciTool on which pipelines are hosted, supported Bitbucket Pipelines and Travis Ci.
29+
30+
### `user`
31+
32+
user - User running the pipelines
33+
34+
### `repo`
35+
36+
repo - Name of the repository to calculate stats for
37+
38+
### `command`
39+
40+
command - [download - to downlaod the build data | calculate - to calculate the mean and see the stats of build data].
41+
42+
### `--period <p>`
43+
44+
p - How many days in a time period to calculate the build stats for **default to 1**
45+
46+
### `--last <l>`
47+
48+
l - How many periods to calculate back to **defaults to 30**
49+

Diff for: __tests__/download.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
const test = require('ava');
3+
const download = require('../lib/commands/download');
4+
const sinon = require('sinon');
5+
const { getFixturePath } = require('jest-fixtures');
6+
const HOSTS = require('../lib/ci');
7+
8+
test('it calls bitbucket download with appropiate path', async (t) => {
9+
let stub = sinon.stub(HOSTS, 'bitbucket');
10+
let cwd = await getFixturePath(__dirname, 'testRepo');
11+
await download({cwd, host: 'bitbucket', user: 'test',repo: 'test-repo'});
12+
t.is(stub.callCount, 1);
13+
});

Diff for: __tests__/util.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
const test = require('ava');
3+
const sinon = require('sinon');
4+
const { getFixturePath } = require('jest-fixtures');
5+
const utils = require('../lib/commands/util');
6+
7+
test('it should return constucted build path', async (t) => {
8+
let cwd = await getFixturePath(__dirname, 'testRepo');
9+
const constructedPath = await utils.getBuildDir(cwd, 'bitbucket', 'test', 'test-repo');
10+
t.is(constructedPath, '/Users/amathur/workspace/open-source/build-stats/__fixtures__/testRepo/.data/bitbucket/test/test-repo/builds');
11+
});

Diff for: cli.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env node
22
'use strict';
33
const meow = require('meow');
4-
const calculate = require('./commands/calculate');
5-
const download = require('./commands/download');
4+
const { calculate, download } = require('./');
65

76
async function main(argv) {
87
const cli = meow({

Diff for: commands/download.js

-18
This file was deleted.

Diff for: index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
exports.download = require('./lib/commands/download');
3+
exports.calculate = require('./lib/commands/calculate');
File renamed without changes.

Diff for: lib/ci/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
module.exports = {
4+
bitbucket: require('./bitbucket/bitbucketDownload'),
5+
travis: require('./travis/travisDownload'),
6+
};
File renamed without changes.
File renamed without changes.

Diff for: lib/commands/download.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
const { getBuildDir } = require("./util");
3+
const HOSTS = require('../ci');
4+
5+
async function download({ cwd, host, user, repo }) {
6+
let buildsDir = await getBuildDir(cwd, host, user, repo);
7+
let hostDownload = HOSTS[host];
8+
9+
if (hostDownload) {
10+
await hostDownload(buildsDir, user, repo);
11+
} else {
12+
throw new Error(`Unknown CI service: ${host}`);
13+
}
14+
}
15+
16+
module.exports = download;

Diff for: commands/util.js renamed to lib/commands/util.js

File renamed without changes.

Diff for: package.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@
33
"version": "0.0.0",
44
"description": "Calculate build stats",
55
"main": "index.js",
6-
"author": "James Kyle <[email protected]>",
6+
"bin": "cli.js",
7+
"author": "Ajay Narain Mathur <[email protected]>",
78
"license": "MIT",
9+
"keywords": [
10+
"build",
11+
"stats",
12+
"ci",
13+
"continous integration",
14+
"perf"
15+
],
16+
"file": [
17+
"cli.js",
18+
"index.js",
19+
"lib"
20+
],
21+
"engines": {
22+
"node": ">=8.5.0"
23+
},
24+
"scripts": {
25+
"test": "ava"
26+
},
827
"dependencies": {
928
"chalk": "^2.3.0",
1029
"cli-table": "^0.3.1",
@@ -13,5 +32,10 @@
1332
"lodash.groupby": "^4.6.0",
1433
"meow": "^4.0.0",
1534
"p-limit": "^1.2.0"
35+
},
36+
"devDependencies": {
37+
"ava": "^0.24.0",
38+
"jest-fixtures": "^0.6.0",
39+
"sinon": "^4.1.4"
1640
}
1741
}

Diff for: preview.png

169 KB
Loading

0 commit comments

Comments
 (0)