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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stats): move part of the logic to the gemini-core
- Loading branch information
Showing
2 changed files
with
22 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters