forked from luk-schweizer/jest-code-coverage-badge-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge.js
26 lines (21 loc) · 879 Bytes
/
badge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module.exports.schema = (coveragePercentage, label, colorConfiguration, showJestLogo) => {
let color = getColor(colorConfiguration, coveragePercentage);
if (!color) color = 'blue';
const schema = {
schemaVersion: 1,
label: label,
message: `${coveragePercentage}%`,
color: color,
};
if (showJestLogo) schema.namedLogo = 'jest';
return schema;
};
const getColor = (colorConfiguration, coverage) => {
const configsFound = colorConfiguration
.filter((config) => (!config['>=']) || (config['>='] && coverage>=config['>=']))
.filter((config) => (!config['<='] || config['<='] && coverage<=config['<=']))
.filter((config) => (!config['>'] || config['>'] && coverage>config['>']))
.filter((config) => (!config['<'] || config['<'] && coverage<config['<']))
.map((config) => config.color);
return configsFound.shift();
};