-
Notifications
You must be signed in to change notification settings - Fork 10
/
parse.js
115 lines (105 loc) · 5.08 KB
/
parse.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const { ActionOutput, InternalToken } = require('./constants');
const { trimBasePath } = require('./utils');
const { formatPercentWithIndicator, formatPercentDiff } = require('./format');
const OUTPUT_BLANK = {
[ActionOutput.total_lines_coverage_percent]: '?',
[ActionOutput.total_statements_coverage_percent]: '?',
[ActionOutput.total_functions_coverage_percent]: '?',
[ActionOutput.total_branches_coverage_percent]: '?',
[ActionOutput.total_lines_coverage_percent_raw]: '?',
[ActionOutput.total_statements_coverage_percent_raw]: '?',
[ActionOutput.total_functions_coverage_percent_raw]: '?',
[ActionOutput.total_branches_coverage_percent_raw]: '?',
[ActionOutput.base_total_lines_coverage_percent]: '?',
[ActionOutput.base_total_statements_coverage_percent]: '?',
[ActionOutput.base_total_functions_coverage_percent]: '?',
[ActionOutput.base_total_branches_coverage_percent]: '?',
[ActionOutput.base_total_lines_coverage_percent_raw]: '?',
[ActionOutput.base_total_statements_coverage_percent_raw]: '?',
[ActionOutput.base_total_functions_coverage_percent_raw]: '?',
[ActionOutput.base_total_branches_coverage_percent_raw]: '?',
[ActionOutput.total_lines_coverage_percent_diff]: '?',
[ActionOutput.total_statements_coverage_percent_diff]: '?',
[ActionOutput.total_functions_coverage_percent_diff]: '?',
[ActionOutput.total_branches_coverage_percent_diff]: '?',
[ActionOutput.total_lines_coverage_percent_diff_raw]: '?',
[ActionOutput.total_statements_coverage_percent_diff_raw]: '?',
[ActionOutput.total_functions_coverage_percent_diff_raw]: '?',
[ActionOutput.total_branches_coverage_percent_diff_raw]: '?',
};
function parseCoverageSummaryJSON(json, { changedFiles, basePath, baseCoverageSummaryJSON } = {}) {
const total = json.total;
delete json.total;
const coverageData = Object.entries(json).map(([absolutePath, data]) => {
return [trimBasePath(absolutePath, basePath), data];
});
let changedFilesCoverageData = [];
if (Array.isArray(changedFiles)) {
changedFilesCoverageData = coverageData.filter(([file]) => {
return changedFiles.includes(file);
});
}
const output = Object.assign({}, OUTPUT_BLANK, {
[ActionOutput.total_lines_coverage_percent]: formatPercentWithIndicator(total.lines.pct),
[ActionOutput.total_statements_coverage_percent]: formatPercentWithIndicator(
total.statements.pct,
),
[ActionOutput.total_functions_coverage_percent]: formatPercentWithIndicator(
total.functions.pct,
),
[ActionOutput.total_branches_coverage_percent]: formatPercentWithIndicator(total.branches.pct),
[ActionOutput.total_lines_coverage_percent_raw]: total.lines.pct,
[ActionOutput.total_statements_coverage_percent_raw]: total.statements.pct,
[ActionOutput.total_functions_coverage_percent_raw]: total.functions.pct,
[ActionOutput.total_branches_coverage_percent_raw]: total.branches.pct,
});
const other = {
[InternalToken.files_coverage_data]: coverageData,
[InternalToken.changed_files_coverage_data]: changedFilesCoverageData,
};
if (baseCoverageSummaryJSON) {
const baseTotal = baseCoverageSummaryJSON.total;
delete baseTotal.total;
Object.assign(output, {
[ActionOutput.base_total_lines_coverage_percent]: formatPercentWithIndicator(
baseTotal.lines.pct,
),
[ActionOutput.base_total_statements_coverage_percent]: formatPercentWithIndicator(
baseTotal.statements.pct,
),
[ActionOutput.base_total_functions_coverage_percent]: formatPercentWithIndicator(
baseTotal.functions.pct,
),
[ActionOutput.base_total_branches_coverage_percent]: formatPercentWithIndicator(
baseTotal.branches.pct,
),
[ActionOutput.base_total_lines_coverage_percent_raw]: baseTotal.lines.pct,
[ActionOutput.base_total_statements_coverage_percent_raw]: baseTotal.statements.pct,
[ActionOutput.base_total_functions_coverage_percent_raw]: baseTotal.functions.pct,
[ActionOutput.base_total_branches_coverage_percent_raw]: baseTotal.branches.pct,
[ActionOutput.total_lines_coverage_percent_diff]: formatPercentDiff(
total.lines.pct - baseTotal.lines.pct,
),
[ActionOutput.total_statements_coverage_percent_diff]: formatPercentDiff(
total.statements.pct - baseTotal.statements.pct,
),
[ActionOutput.total_functions_coverage_percent_diff]: formatPercentDiff(
total.functions.pct - baseTotal.functions.pct,
),
[ActionOutput.total_branches_coverage_percent_diff]: formatPercentDiff(
total.branches.pct - baseTotal.branches.pct,
),
[ActionOutput.total_lines_coverage_percent_diff_raw]: total.lines.pct - baseTotal.lines.pct,
[ActionOutput.total_statements_coverage_percent_diff_raw]:
total.statements.pct - baseTotal.statements.pct,
[ActionOutput.total_functions_coverage_percent_diff_raw]:
total.functions.pct - baseTotal.functions.pct,
[ActionOutput.total_branches_coverage_percent_diff_raw]:
total.branches.pct - baseTotal.branches.pct,
});
}
return { output, other };
}
module.exports = {
parseCoverageSummaryJSON,
};