8000 feat(stats): move part of the logic to the gemini-core by DudaGod · Pull Request #872 · gemini-testing/gemini · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 20 additions & 52 deletions lib/stats.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,40 @@
'use strict';

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

const STATS = {
total: 'total',
updated: 'updated',
passed: 'passed',
failed: 'failed',
skipped: 'skipped',
retries: 'retries'
const statNames = {
TOTAL: 'total',
UPDATED: 'updated',
PASSED: 'passed',
FAILED: 'failed',
SKIPPED: 'skipped',
RETRIES: 'retries'
};

module.exports = class Stats {
static create() {
return new Stats();
module.exports = class Stats extends BaseStats {
constructor() {
super(statNames);
}

constructor() {
this._stats = {};
addUpdated(test) {
return this._addStat(this._statNames.UPDATED, test);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Напомню на всякий случай, либо тут updated, либо в STAT_NAMES все капсом

}

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++);
.on(RunnerEvents.SKIP_STATE, (test) => this.addSkipped(test))
.on(RunnerEvents.ERROR, (test) => this.addFailed(test))
.on(RunnerEvents.UPDATE_RESULT, (test) => test.updated ? this.addUpdated(test) : this.addPassed(test))
.on(RunnerEvents.TEST_RESULT, (test) => test.equal ? this.addPassed(test) : this.addFailed(test))
.on(RunnerEvents.RETRY, () => this.addRetries());
}

_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];
_buildStateKey(test) {
return test.state.name;
}

_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;
}
};
92 changes: 53 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"gemini-configparser": "^1.0.0",
"gemini-core": "^2.4.0",
"gemini-core": "^2.5.0",
"gemini-coverage": "^2.0.0",
"graceful-fs": "^4.1.11",
"handlebars": "^4.0.5",
Expand Down
4 changes: 2 additions & 2 deletions test/unit/stats.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const EventEmitter = require('events').EventEmitter;
const {EventEmitter} = require('events');
const RunnerEvents = require('../../lib/constants/events');
const Stats = require('../../lib/stats');
const makeStateResult = require('../util').makeStateResult;
const {makeStateResult} = require('../util');

describe('Stats', () => {
let stats;
Expand Down
0