Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 99e7e0c

Browse files
committed
feat(stats): move part of the logic to the gemini-core
1 parent 707abee commit 99e7e0c

File tree

2 files changed

+22
-54
lines changed

2 files changed

+22
-54
lines changed

lib/stats.js

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,40 @@
11
'use strict';
22

3-
const _ = require('lodash');
3+
const {BaseStats} = require('gemini-core');
44
const RunnerEvents = require('./constants/events');
55

6-
const STATS = {
7-
total: 'total',
8-
updated: 'updated',
9-
passed: 'passed',
10-
failed: 'failed',
11-
skipped: 'skipped',
12-
retries: 'retries'
6+
const statNames = {
7+
TOTAL: 'total',
8+
UPDATED: 'updated',
9+
PASSED: 'passed',
10+
FAILED: 'failed',
11+
SKIPPED: 'skipped',
12+
RETRIES: 'retries'
1313
};
1414

15-
module.exports = class Stats {
16-
static create() {
17-
return new Stats();
15+
module.exports = class Stats extends BaseStats {
16+
constructor() {
17+
super(statNames);
1818
}
1919

20-
constructor() {
21-
this._stats = {};
20+
addUpdated(test) {
21+
return this._addStat(this._statNames.UPDATED, test);
2222
}
2323

2424
attachRunner(runner) {
2525
runner
26-
.on(RunnerEvents.SKIP_STATE, (test) => this._addStat(STATS.skipped, test))
27-
.on(RunnerEvents.ERROR, (test) => this._addStat(STATS.failed, test))
28-
.on(RunnerEvents.UPDATE_RESULT, (test) => {
29-
return test.updated ? this._addStat(STATS.updated, test) : this._addStat(STATS.passed, test);
30-
})
31-
.on(RunnerEvents.TEST_RESULT, (test) => {
32-
return test.equal ? this._addStat(STATS.passed, test) : this._addStat(STATS.failed, test);
33-
})
34-
.on(RunnerEvents.RETRY, (test) => this._getSuiteStats(test).retries++);
26+
.on(RunnerEvents.SKIP_STATE, (test) => this.addSkipped(test))
27+
.on(RunnerEvents.ERROR, (test) => this.addFailed(test))
28+
.on(RunnerEvents.UPDATE_RESULT, (test) => test.updated ? this.addUpdated(test) : this.addPassed(test))
29+
.on(RunnerEvents.TEST_RESULT, (test) => test.equal ? this.addPassed(test) : this.addFailed(test))
30+
.on(RunnerEvents.RETRY, () => this.addRetries());
3531
}
3632

37-
_addStat(stat, test) {
38-
this._getSuiteStats(test).states[test.state.name] = stat;
39-
}
40-
41-
_getSuiteStats(test) {
42-
const key = this._buildSuiteKey(test);
43-
44-
if (!this._stats[key]) {
45-
this._stats[key] = {
46-
retries: 0,
47-
states: {}
48-
};
49-
}
50-
51-
return this._stats[key];
33+
_buildStateKey(test) {
34+
return test.state.name;
5235
}
5336

5437
_buildSuiteKey(test) {
5538
return `${test.suite.fullName} ${test.browserId}`;
5639
}
57-
58-
getResult() {
59-
const statNames = _.keys(STATS);
60-
const result = _.zipObject(statNames, _.fill(Array(statNames.length), 0));
61-
62-
_.forEach(this._stats, (suiteStats) => {
63-
result.retries += suiteStats.retries;
64-
_.forEach(suiteStats.states, (stateStatus) => {
65-
result.total++;
66-
result[stateStatus]++;
67-
});
68-
});
69-
70-
return result;
71-
}
7240
};

test/unit/stats.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
const EventEmitter = require('events').EventEmitter;
3+
const {EventEmitter} = require('events');
44
const RunnerEvents = require('../../lib/constants/events');
55
const Stats = require('../../lib/stats');
6-
const makeStateResult = require('../util').makeStateResult;
6+
const {makeStateResult} = require('../util');
77

88
describe('Stats', () => {
99
let stats;

0 commit comments

Comments
 (0)