-
Notifications
You must be signed in to change notification settings - Fork 10
/
getConsolidatedData.js
73 lines (62 loc) · 2.75 KB
/
getConsolidatedData.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
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var fs = require('fs-extra');
var chalk = require('chalk');
var glob = require('glob');
/**
* Get Consolidated JSON Report Array
* @param {string} options.parallelExecutionReportDirectory - Path to Parallel Execution Report Directory where all the Reports will be saved
* @return {Array}
*/
var getConsolidatedArray = function getConsolidatedArray(options) {
try {
var jsonArray = [];
var jsonReportPaths = glob.sync(options.parallelExecutionReportDirectory + '/*.json', { sync: true });
if (jsonReportPaths != null) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = jsonReportPaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var value = _step.value;
var content = fs.readFileSync(value, 'utf8');
var data = JSON.parse(content);
jsonArray = [].concat(_toConsumableArray(jsonArray), _toConsumableArray(data));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var filteredArray = [];
jsonArray.forEach(function (item) {
if (item.hasOwnProperty('elements')) {
var existing = filteredArray.filter(function (element) {
return element.id == item.id;
});
if (existing.length) {
var existingIndex = filteredArray.indexOf(existing[0]);
filteredArray[existingIndex].elements = filteredArray[existingIndex].elements.concat(item.elements);
} else {
filteredArray.push(item);
}
}
});
return filteredArray;
} else {
console.log(chalk.bold.hex('#7D18FF')('No JSON Files found in ' + options.parallelExecutionReportDirectory));
}
} catch (e) {
console.log('Error: ', e);
}
};
module.exports = getConsolidatedArray;