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
88 lines (68 loc) 路 1.8 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
'use strict';
const _ = require('lodash');
const STATS = {
total: 'total',
updated: 'updated',
passed: 'passed',
failed: 'failed',
errored: 'errored',
skipped: 'skipped',
warned: 'warned',
retries: 'retries'
};
module.exports = class TestCounter {
constructor() {
this._stats = {};
}
onUpdated(updated) {
this._addStat(STATS.updated, updated);
}
onPassed(passed) {
this._addStat(STATS.passed, passed);
}
onFailed(failed) {
this._addStat(STATS.failed, failed);
}
onErrored(errored) {
this._addStat(STATS.errored, errored);
}
onSkipped(skipped) {
this._addStat(STATS.skipped, skipped);
}
onWarned(warned) {
this._addStat(STATS.warned, warned);
}
onRetry(retried) {
const suiteStats = this._getSuiteStats(retried);
suiteStats.retries++;
}
_addStat(stat, test) {
const suiteStats = this._getSuiteStats(test);
suiteStats.states[test.state.name] = stat;
}
_getSuiteStats(test) {
const key = this._buildSuiteKey(test);
if (!this._stats[key]) {
this._stats[key] = {
retries: 0,
states: {}
};
}
return this._stats[key];
}
_buildSuiteKey(test) {
return test.suite.fullName + test.browserId;
}
getResult() {
const statNames = _.keys(STATS);
const result = _.zipObject(statNames, _.fill(Array(statNames.length), 0));
_.forEach(this._stats, (suiteStats) => {
result.retries += suiteStats.retries;
_.forEach(suiteStats.states, (stateStatus) => {
result.total++;
result[stateStatus]++;
});
});
return result;
}
};