lcov-badge2 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.eslintrc.yml +343 -0
- package/.github/dependabot.yml +10 -0
- package/.github/workflows/codeql-analysis.yml +37 -0
- package/.github/workflows/test.yml +31 -0
- package/SECURITY.md +14 -0
- package/gulpfile.mjs +20 -0
- package/package.json +16 -21
- package/src/badge.spec.ts +36 -0
- package/src/badge.ts +22 -0
- package/src/cli.spec.ts +111 -0
- package/src/cli.ts +80 -0
- package/src/coverage.spec.ts +88 -0
- package/src/coverage.ts +24 -0
- package/src/main.spec.ts +78 -0
- package/src/main.ts +21 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +26 -0
- package/types/badge-up2/index.d.ts +19 -0
- package/badge.d.ts +0 -1
- package/badge.js +0 -89
- package/cli.d.ts +0 -6
- package/cli.js +0 -59
- package/coverage.d.ts +0 -1
- package/coverage.js +0 -27
- package/main.d.ts +0 -1
- package/main.js +0 -90
package/src/cli.spec.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import { Arguments, processArguments } from './cli';
|
|
4
|
+
|
|
5
|
+
describe('CLI', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
jest.spyOn(console, 'log').mockImplementation();
|
|
8
|
+
jest.spyOn(console, 'error').mockImplementation();
|
|
9
|
+
jest.spyOn(process, 'exit').mockImplementation();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
(console.log as jest.Mock).mockReset();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('When the help argument is passed', () => {
|
|
17
|
+
describe.each(['-h', '--help'])('When %s is passed', (arg) => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
process.argv = ['node', path.join('some', 'path', 'whatever', 'foo.ts'), arg];
|
|
20
|
+
processArguments();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('it prints the help message', () => {
|
|
24
|
+
expect(console.log).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect((console.log as jest.MockedFunction<typeof console.log>).mock.calls[0][0])
|
|
26
|
+
.toContain('Usage: foo.ts [-h] [-o OUTPUT] [-l LABEL] input');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('it exits without an error', () => {
|
|
30
|
+
expect(process.exit).toHaveBeenCalledWith(0);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('When no positional arguments are passed', () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
process.argv = ['node', 'foo.ts', '-l', 'foo'];
|
|
38
|
+
processArguments();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('it prints an error message', () => {
|
|
42
|
+
expect(console.error).toHaveBeenCalledWith('Input must be provided');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('it exits with an error', () => {
|
|
46
|
+
expect(process.exit).toHaveBeenCalledWith(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('When multiple positional arguments are passed', () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
process.argv = ['node', 'foo.ts', '-l', 'foo', 'bar', 'baz'];
|
|
53
|
+
processArguments();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('it prints an error message', () => {
|
|
57
|
+
expect(console.error).toHaveBeenCalledWith('Only one input can be provided');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('it exits with an error', () => {
|
|
61
|
+
expect(process.exit).toHaveBeenCalledWith(1);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('When only an input is provided', () => {
|
|
66
|
+
let args: Arguments;
|
|
67
|
+
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
process.argv = ['node', 'foo.ts', 'foo'];
|
|
70
|
+
args = processArguments();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('it sets the input', () => {
|
|
74
|
+
expect(args.input).toBe('foo');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('it uses the default label value', () => {
|
|
78
|
+
expect(args.label).toBe('coverage');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('it uses the default output value', () => {
|
|
82
|
+
expect(args.output).toBe('badge.svg');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('When providing a value for label', () => {
|
|
87
|
+
let args: Arguments;
|
|
88
|
+
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
process.argv = ['node', 'foo.ts', '-l', 'my-coverage', 'foo'];
|
|
91
|
+
args = processArguments();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('it sets the value for label', () => {
|
|
95
|
+
expect(args.label).toBe('my-coverage');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('When providing a value for output', () => {
|
|
100
|
+
let args: Arguments;
|
|
101
|
+
|
|
102
|
+
beforeEach(() => {
|
|
103
|
+
process.argv = ['node', 'foo.ts', '-o', 'my-badge.svg', 'foo'];
|
|
104
|
+
args = processArguments();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('it sets the value for label', () => {
|
|
108
|
+
expect(args.output).toBe('my-badge.svg');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import minimist, { ParsedArgs } from 'minimist';
|
|
2
|
+
import buildOptions from 'minimist-options';
|
|
3
|
+
import { basename } from 'path';
|
|
4
|
+
|
|
5
|
+
export interface Arguments {
|
|
6
|
+
input: string;
|
|
7
|
+
label: string;
|
|
8
|
+
output: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultOutputPath = 'badge.svg';
|
|
12
|
+
const defaultLabel = 'coverage';
|
|
13
|
+
|
|
14
|
+
function exitWithError(message: string): never {
|
|
15
|
+
console.error(message);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function printHelp(): never {
|
|
20
|
+
const message = `Usage: ${basename(process.argv[1])} [-h] [-o OUTPUT] [-l LABEL] input
|
|
21
|
+
|
|
22
|
+
Positional Arguments:
|
|
23
|
+
input Path to LCOV file to parse
|
|
24
|
+
|
|
25
|
+
Optional Arguments:
|
|
26
|
+
-h, --help Show this help message and exit
|
|
27
|
+
-o OUTPUT, --output OUTPUT
|
|
28
|
+
Output file path (default: ${defaultOutputPath})
|
|
29
|
+
-l LABEL, --label LABEL
|
|
30
|
+
Badge label (default: ${defaultLabel})
|
|
31
|
+
`;
|
|
32
|
+
console.log(message);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function validateArguments(args: ParsedArgs): void {
|
|
37
|
+
if (!args._.length) {
|
|
38
|
+
exitWithError('Input must be provided');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (args._.length !== 1) {
|
|
42
|
+
exitWithError('Only one input can be provided');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function processArguments(): Arguments {
|
|
47
|
+
const options = buildOptions({
|
|
48
|
+
help: {
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
alias: 'h',
|
|
51
|
+
default: false,
|
|
52
|
+
},
|
|
53
|
+
label: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
alias: 'l',
|
|
56
|
+
default: defaultLabel,
|
|
57
|
+
},
|
|
58
|
+
output: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
alias: 'o',
|
|
61
|
+
default: defaultOutputPath,
|
|
62
|
+
},
|
|
63
|
+
// Special option for positional arguments (`_` in minimist)
|
|
64
|
+
arguments: 'string',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const args = minimist(process.argv.slice(2), options);
|
|
68
|
+
|
|
69
|
+
if (args.help) {
|
|
70
|
+
printHelp();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
validateArguments(args);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
input: args._[0],
|
|
77
|
+
label: args.label,
|
|
78
|
+
output: args.output,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import parse from 'parse-lcov';
|
|
2
|
+
|
|
3
|
+
import { getCoverageLevel } from './coverage';
|
|
4
|
+
|
|
5
|
+
jest.mock('parse-lcov');
|
|
6
|
+
|
|
7
|
+
describe('Coverage', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
(parse as jest.MockedFunction<typeof parse>).mockReturnValue([]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('it reads the file', () => {
|
|
13
|
+
getCoverageLevel('foo.lcov');
|
|
14
|
+
expect(parse).toHaveBeenCalledWith('foo.lcov');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('When there are no lines of code', () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
(parse as jest.MockedFunction<typeof parse>).mockReturnValue([
|
|
20
|
+
{
|
|
21
|
+
title: '',
|
|
22
|
+
file: '',
|
|
23
|
+
functions: { found: 0, hit: 0, details: [] },
|
|
24
|
+
branches: { found: 0, hit: 0, details: [] },
|
|
25
|
+
lines: { found: 0, hit: 0, details: [] },
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('it returns 100', () => {
|
|
31
|
+
expect(getCoverageLevel('foo')).toBe(100);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('When there are lines of code and none are hit', () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
(parse as jest.MockedFunction<typeof parse>).mockReturnValue([
|
|
38
|
+
{
|
|
39
|
+
title: '',
|
|
40
|
+
file: '',
|
|
41
|
+
functions: { found: 1, hit: 0, details: [] },
|
|
42
|
+
branches: { found: 2, hit: 0, details: [] },
|
|
43
|
+
lines: { found: 3, hit: 0, details: [] },
|
|
44
|
+
},
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('it returns 0', () => {
|
|
49
|
+
expect(getCoverageLevel('foo')).toBe(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('When there are lines of code and all are hit', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
(parse as jest.MockedFunction<typeof parse>).mockReturnValue([
|
|
56
|
+
{
|
|
57
|
+
title: '',
|
|
58
|
+
file: '',
|
|
59
|
+
functions: { found: 1, hit: 1, details: [] },
|
|
60
|
+
branches: { found: 2, hit: 2, details: [] },
|
|
61
|
+
lines: { found: 3, hit: 3, details: [] },
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('it returns 0', () => {
|
|
67
|
+
expect(getCoverageLevel('foo')).toBe(100);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('When there are lines of code and some are hit', () => {
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
(parse as jest.MockedFunction<typeof parse>).mockReturnValue([
|
|
74
|
+
{
|
|
75
|
+
title: '',
|
|
76
|
+
file: '',
|
|
77
|
+
functions: { found: 100, hit: 66, details: [] },
|
|
78
|
+
branches: { found: 200, hit: 157, details: [] },
|
|
79
|
+
lines: { found: 1234, hit: 963, details: [] },
|
|
80
|
+
},
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('it calculates the coverage', () => {
|
|
85
|
+
expect(getCoverageLevel('foo')).toBe(74.18);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
package/src/coverage.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import parse from 'parse-lcov';
|
|
2
|
+
|
|
3
|
+
export function getCoverageLevel(lcov: string): number {
|
|
4
|
+
const coverage = parse(lcov);
|
|
5
|
+
|
|
6
|
+
const summary = {
|
|
7
|
+
lines: { found: 0, hit: 0 },
|
|
8
|
+
branches: { found: 0, hit: 0 },
|
|
9
|
+
functions: { found: 0, hit: 0 },
|
|
10
|
+
};
|
|
11
|
+
const keys = Object.keys(summary) as (keyof typeof summary)[];
|
|
12
|
+
|
|
13
|
+
coverage.forEach((arg) => {
|
|
14
|
+
keys.forEach((key) => {
|
|
15
|
+
summary[key].found += arg[key].found;
|
|
16
|
+
summary[key].hit += arg[key].hit;
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return Math.round(keys.reduce((avg, key) => {
|
|
21
|
+
const found = summary[key].found;
|
|
22
|
+
return avg + (found > 0 ? summary[key].hit / found * 100 : 100);
|
|
23
|
+
}, 0) / keys.length * 100) / 100;
|
|
24
|
+
}
|
package/src/main.spec.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { spawnSync, SpawnSyncReturns } from 'child_process';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
import { createBadge } from './badge';
|
|
7
|
+
import { getCoverageLevel } from './coverage';
|
|
8
|
+
import { generateBadge } from './main';
|
|
9
|
+
|
|
10
|
+
jest.mock('./badge');
|
|
11
|
+
jest.mock('./coverage');
|
|
12
|
+
|
|
13
|
+
describe('Main', () => {
|
|
14
|
+
let badgeContents: string;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
jest.spyOn(fs, 'readFile').mockResolvedValue('some lcov content');
|
|
18
|
+
(getCoverageLevel as jest.MockedFunction<typeof getCoverageLevel>).mockReturnValue(99.5);
|
|
19
|
+
(createBadge as jest.MockedFunction<typeof createBadge>).mockResolvedValue('totally an svg');
|
|
20
|
+
|
|
21
|
+
badgeContents = await generateBadge('foo.lcov', 'something');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('the main function generates the badge from the input', () => {
|
|
25
|
+
expect(fs.readFile).toHaveBeenCalledWith('foo.lcov');
|
|
26
|
+
expect(getCoverageLevel).toHaveBeenCalledWith('some lcov content');
|
|
27
|
+
expect(createBadge).toHaveBeenCalledWith('something', 99.5);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('it returns the SVG as a string', () => {
|
|
31
|
+
expect(badgeContents).toBe('totally an svg');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('Running as a script', () => {
|
|
35
|
+
const report = `
|
|
36
|
+
TN:
|
|
37
|
+
SF:src/badge.ts
|
|
38
|
+
FN:3,getColor
|
|
39
|
+
FN:19,createBadge
|
|
40
|
+
FNF:2
|
|
41
|
+
FNH:2
|
|
42
|
+
FNDA:13,getColor
|
|
43
|
+
FNDA:13,createBadge
|
|
44
|
+
DA:1,2
|
|
45
|
+
LF:15
|
|
46
|
+
LH:15
|
|
47
|
+
BRDA:4,0,0,2
|
|
48
|
+
BRF:10
|
|
49
|
+
BRH:10
|
|
50
|
+
end_of_record`;
|
|
51
|
+
let inputFilePath: string;
|
|
52
|
+
let filePath: string;
|
|
53
|
+
let result: SpawnSyncReturns<string | Buffer>;
|
|
54
|
+
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
const dir = os.tmpdir();
|
|
57
|
+
filePath = path.join(dir, `badge-${new Date().valueOf()}.svg`);
|
|
58
|
+
inputFilePath = path.join(dir, `lcov-${new Date().valueOf()}.info`);
|
|
59
|
+
|
|
60
|
+
await fs.writeFile(inputFilePath, report);
|
|
61
|
+
|
|
62
|
+
result = spawnSync('ts-node', [path.join(__dirname, 'main.ts'), '-o', filePath, inputFilePath]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
afterEach(async () => {
|
|
66
|
+
await fs.rm(filePath);
|
|
67
|
+
await fs.rm(inputFilePath);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('it exited successfully', () => {
|
|
71
|
+
expect(result.status).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('it writes the badge file', async () => {
|
|
75
|
+
await expect(fs.stat(filePath)).resolves.not.toThrow();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import { createBadge } from './badge';
|
|
4
|
+
import { processArguments } from './cli';
|
|
5
|
+
import { getCoverageLevel } from './coverage';
|
|
6
|
+
|
|
7
|
+
export async function generateBadge(filename: string, label = 'coverage'): Promise<string> {
|
|
8
|
+
const input = (await fs.readFile(filename)).toString();
|
|
9
|
+
const coverage = getCoverageLevel(input);
|
|
10
|
+
return createBadge(label, coverage);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (require.main === module) {
|
|
14
|
+
const args = processArguments();
|
|
15
|
+
generateBadge(args.input, args.label)
|
|
16
|
+
.then(async (badge) => fs.writeFile(args.output, badge))
|
|
17
|
+
.catch((e) => {
|
|
18
|
+
console.error(e);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
});
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"removeComments": true,
|
|
6
|
+
"emitDecoratorMetadata": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"target": "ES5",
|
|
10
|
+
"lib": [
|
|
11
|
+
"es2020"
|
|
12
|
+
],
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"outDir": "./dist",
|
|
15
|
+
"baseUrl": "./src",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"typeRoots": [
|
|
19
|
+
"node_modules/@types",
|
|
20
|
+
"types"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"src/**/*.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module 'badge-up2' {
|
|
2
|
+
export enum colors {
|
|
3
|
+
brightgreen = '#4C1',
|
|
4
|
+
green = '#97CA00',
|
|
5
|
+
yellow = '#DFB317',
|
|
6
|
+
yellowgreen = '#A4A61D',
|
|
7
|
+
orange = '#FE7D37',
|
|
8
|
+
red = '#E05D44',
|
|
9
|
+
blue = '#007EC6',
|
|
10
|
+
grey = '#555',
|
|
11
|
+
gray = '#555',
|
|
12
|
+
lightgrey = '#9F9F9F',
|
|
13
|
+
lightgray = '#9F9F9F',
|
|
14
|
+
purple = '#400090'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function badge(field1: string, field2: string, color: colors): Promise<string>;
|
|
18
|
+
export default badge;
|
|
19
|
+
}
|
package/badge.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createBadge(label: string, coverage: number): Promise<string>;
|
package/badge.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
-
function step(op) {
|
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
37
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
-
switch (op[0]) {
|
|
40
|
-
case 0: case 1: t = op; break;
|
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
-
default:
|
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
-
if (t[2]) _.ops.pop();
|
|
50
|
-
_.trys.pop(); continue;
|
|
51
|
-
}
|
|
52
|
-
op = body.call(thisArg, _);
|
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
-
exports.createBadge = void 0;
|
|
59
|
-
var badge_up_1 = __importStar(require("badge-up"));
|
|
60
|
-
function getColor(coverage) {
|
|
61
|
-
if (coverage > 97) {
|
|
62
|
-
return badge_up_1.colors.brightgreen;
|
|
63
|
-
}
|
|
64
|
-
else if (coverage > 93) {
|
|
65
|
-
return badge_up_1.colors.green;
|
|
66
|
-
}
|
|
67
|
-
else if (coverage > 90) {
|
|
68
|
-
return badge_up_1.colors.yellowgreen;
|
|
69
|
-
}
|
|
70
|
-
else if (coverage > 85) {
|
|
71
|
-
return badge_up_1.colors.yellow;
|
|
72
|
-
}
|
|
73
|
-
else if (coverage > 75) {
|
|
74
|
-
return badge_up_1.colors.orange;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return badge_up_1.colors.red;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function createBadge(label, coverage) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var color;
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
color = getColor(coverage);
|
|
85
|
-
return [2, badge_up_1.default(label, coverage + "%", color)];
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
exports.createBadge = createBadge;
|
package/cli.d.ts
DELETED
package/cli.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.processArguments = void 0;
|
|
7
|
-
var minimist_1 = __importDefault(require("minimist"));
|
|
8
|
-
var minimist_options_1 = __importDefault(require("minimist-options"));
|
|
9
|
-
var path_1 = require("path");
|
|
10
|
-
var defaultOutputPath = 'badge.svg';
|
|
11
|
-
var defaultLabel = 'coverage';
|
|
12
|
-
function exitWithError(message) {
|
|
13
|
-
console.error(message);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
function printHelp() {
|
|
17
|
-
var message = "Usage: " + path_1.basename(process.argv[1]) + " [-h] [-o OUTPUT] [-l LABEL] input\n\nPositional Arguments:\n input Path to LCOV file to parse\n\nOptional Arguments:\n -h, --help Show this help message and exit\n -o OUTPUT, --output OUTPUT\n Output file path (default: " + defaultOutputPath + ")\n -l LABEL, --label LABEL\n Badge label (default: " + defaultLabel + ")\n ";
|
|
18
|
-
console.log(message);
|
|
19
|
-
process.exit(0);
|
|
20
|
-
}
|
|
21
|
-
function validateArguments(args) {
|
|
22
|
-
if (!args._.length) {
|
|
23
|
-
exitWithError('Input must be provided');
|
|
24
|
-
}
|
|
25
|
-
if (args._.length !== 1) {
|
|
26
|
-
exitWithError('Only one input can be provided');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function processArguments() {
|
|
30
|
-
var options = minimist_options_1.default({
|
|
31
|
-
help: {
|
|
32
|
-
type: 'boolean',
|
|
33
|
-
alias: 'h',
|
|
34
|
-
default: false,
|
|
35
|
-
},
|
|
36
|
-
label: {
|
|
37
|
-
type: 'string',
|
|
38
|
-
alias: 'l',
|
|
39
|
-
default: defaultLabel,
|
|
40
|
-
},
|
|
41
|
-
output: {
|
|
42
|
-
type: 'string',
|
|
43
|
-
alias: 'o',
|
|
44
|
-
default: defaultOutputPath,
|
|
45
|
-
},
|
|
46
|
-
arguments: 'string',
|
|
47
|
-
});
|
|
48
|
-
var args = minimist_1.default(process.argv.slice(2), options);
|
|
49
|
-
if (args.help) {
|
|
50
|
-
printHelp();
|
|
51
|
-
}
|
|
52
|
-
validateArguments(args);
|
|
53
|
-
return {
|
|
54
|
-
input: args._[0],
|
|
55
|
-
label: args.label,
|
|
56
|
-
output: args.output,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
exports.processArguments = processArguments;
|
package/coverage.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCoverageLevel(lcov: string): number;
|
package/coverage.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCoverageLevel = void 0;
|
|
7
|
-
var parse_lcov_1 = __importDefault(require("parse-lcov"));
|
|
8
|
-
function getCoverageLevel(lcov) {
|
|
9
|
-
var coverage = parse_lcov_1.default(lcov);
|
|
10
|
-
var summary = {
|
|
11
|
-
lines: { found: 0, hit: 0 },
|
|
12
|
-
branches: { found: 0, hit: 0 },
|
|
13
|
-
functions: { found: 0, hit: 0 },
|
|
14
|
-
};
|
|
15
|
-
var keys = Object.keys(summary);
|
|
16
|
-
coverage.forEach(function (arg) {
|
|
17
|
-
keys.forEach(function (key) {
|
|
18
|
-
summary[key].found += arg[key].found;
|
|
19
|
-
summary[key].hit += arg[key].hit;
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
return Math.round(keys.reduce(function (avg, key) {
|
|
23
|
-
var found = summary[key].found;
|
|
24
|
-
return avg + (found > 0 ? summary[key].hit / found * 100 : 100);
|
|
25
|
-
}, 0) / keys.length * 100) / 100;
|
|
26
|
-
}
|
|
27
|
-
exports.getCoverageLevel = getCoverageLevel;
|
package/main.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateBadge(filename: string, label?: string): Promise<string>;
|