-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxml.js
35 lines (24 loc) · 988 Bytes
/
xml.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
const { fail } = require('./core');
const extractNodes = (tree, name) => {
if (!tree.elements || tree.elements.length === 0) {
return [];
}
let out = [];
tree.elements.filter(e => e.name !== name).forEach(e => out = out.concat(extractNodes(e, name)));
out = out.concat(tree.elements.filter(e => e.name === name));
return out;
};
const findNode = (tree, name) => {
if (!tree.elements) {
fail('Wrong coverage file format');
}
const element = tree.elements.find(e => e.name === name);
if (!element) {
fail('Wrong coverage file format');
}
return element;
}
const retrieveGlobalMetricsElement = json => findNode(findNode(findNode(json, 'coverage'), 'project'), 'metrics');
const retrieveDetailedFilesElements = json => extractNodes(json, 'file');
const retrieveMetricsElement = json => findNode(json, 'metrics');
export { retrieveDetailedFilesElements, retrieveGlobalMetricsElement, retrieveMetricsElement };