This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
/
test-counter.js
89 lines (70 loc) 路 1.93 KB
/
test-counter.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
'use strict';
var _ = require('lodash'),
inherit = require('inherit');
var STATS = {
UPDATED: 'updated',
PASSED: 'passed',
FAILED: 'failed',
SKIPPED: 'skipped'
};
module.exports = inherit({
__constructor: function() {
this._stats = {};
},
onUpdated: function(updated) {
this._addStat(STATS.UPDATED, updated);
},
onPassed: function(passed) {
this._addStat(STATS.PASSED, passed);
},
onFailed: function(failed) {
this._addStat(STATS.FAILED, failed);
},
onSkipped: function(skipped) {
this._addStat(STATS.SKIPPED, skipped);
},
onRetry: function(retried) {
var suiteStats = this._getSuiteStats(retried);
suiteStats.retries++;
suiteStats.states = {};
},
getResult: function() {
var result = {
total: 0,
updated: 0,
passed: 0,
failed: 0,
skipped: 0,
retries: 0
};
_.forEach(this._stats, function(suiteStats) {
result.retries += suiteStats.retries;
_.forEach(suiteStats.states, function(stateStatus) {
result.total++;
result[stateStatus]++;
});
});
return result;
},
_addStat: function(stat, completed) {
var completedEntity = completed.state || completed.suite;
if (!completedEntity) {
return;
}
var suiteStats = this._getSuiteStats(completed);
suiteStats.states[completedEntity.name] = stat;
},
_getSuiteStats: function(completed) {
var key = this._buildSuiteKey(completed);
if (!this._stats[key]) {
this._stats[key] = {
retries: 0,
states: {}
};
}
return this._stats[key];
},
_buildSuiteKey: function(completed) {
return completed.suite.fullName + completed.browserId;
}
});