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 149
/
Copy pathstats.js
72 lines (59 loc) · 1.89 KB
/
stats.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
'use strict';
const _ = require('lodash');
const RunnerEvents = require('./constants/events');
const STATS = {
total: 'total',
updated: 'updated',
passed: 'passed',
failed: 'failed',
skipped: 'skipped',
retries: 'retries'
};
module.exports = class Stats {
static create() {
return new Stats();
}
constructor() {
this._stats = {};
}
attachRunner(runner) {
runner
.on(RunnerEvents.SKIP_STATE, (test) => this._addStat(STATS.skipped, test))
.on(RunnerEvents.ERROR, (test) => this._addStat(STATS.failed, test))
.on(RunnerEvents.UPDATE_RESULT, (test) => {
return test.updated ? this._addStat(STATS.updated, test) : this._addStat(STATS.passed, test);
})
.on(RunnerEvents.TEST_RESULT, (test) => {
return test.equal ? this._addStat(STATS.passed, test) : this._addStat(STATS.failed, test);
})
.on(RunnerEvents.RETRY, (test) => this._getSuiteStats(test).retries++);
}
_addStat(stat, test) {
this._getSuiteStats(test).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;
}
};