forked from RaghavendhraK/cucumber-html-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary.js
46 lines (39 loc) · 1.1 KB
/
summary.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
function sum(arr) {
return arr.reduce(function(a, b) {
return a + b;
}, 0);
}
function sumFeatures(features, elementCallback) {
// Features summary
return sum(features.map(function(feature) {
// Elements summary for each feature
return sum(feature.elements.map(elementCallback));
}));
}
function sumTotal(features) {
return sumFeatures(features, function(element) {
return element.steps.length;
});
}
function stepSum(features, stepCondition) {
return sumFeatures(features, function(element) {
return element.steps.filter(stepCondition).length;
});
}
function stepPassed(step) {
return step.result.status.toLocaleLowerCase() === 'passed';
}
function stepFailed(step) {
return step.result.status.toLocaleLowerCase() === 'failed';
}
exports.calculateSummary = function(features) {
var totalPassed = stepSum(features, stepPassed);
var totalFailed = stepSum(features, stepFailed);
return {
total: sumTotal(features),
totalExecuted: totalPassed + totalFailed,
totalPassed: totalPassed,
totalFailed: totalFailed,
status: totalFailed === 0 ? 'OK' : 'NOK'
};
};