Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sum up all tests stats #24

Merged
merged 6 commits into from
Jan 5, 2017
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
32 changes: 31 additions & 1 deletion lib/nyanCat.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,37 @@ NyanCat.prototype.onBrowserLog = function(browser, log) {
*/

NyanCat.prototype.onSpecComplete = function(browser, result) {
this.stats = browser.lastResult;
// don't pollute original object
this.stats = Object.create(browser.lastResult);

// sum up tests stats
var testStats = {
success: 0,
failed: 0,
skipped: 0,
total: 0
};

var matched = this._browsers.some(function(br, idx, all) {
if (all[idx].id === browser.id) {
return all.splice(idx, 1, browser);
}
});

if (!matched) {
this._browsers.push(browser);
}

this._browsers.forEach(function(br) {
Object.keys(testStats).forEach(function(prop) {
testStats[prop] += br.lastResult[prop];
});
});

var self = this;
Object.keys(testStats).forEach(function (prop) {
self.stats[prop] = testStats[prop];
});

if (!this.options.suppressErrorReport) {
this.dataStore.save(browser, result);
Expand Down
7 changes: 4 additions & 3 deletions test/nyanCat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,13 @@ describe('nyanCat.js test suite', function() {

beforeEach(function(done) {
browser = {
'lastResult' : 'last result'
'lastResult' : {}
};

result = {};

sut = new module.NyanCat(null, null, configFake);
sut._browsers = [];
sut.dataStore = dataStoreInstanceFake;
sut.draw = sinon.spy();
done();
Expand All @@ -384,9 +385,9 @@ describe('nyanCat.js test suite', function() {
done();
});

it('should set sut.stats to the value of browser.lastResult', function() {
it('should set sut.stats to inherit from browser.lastResult', function() {
sut.onSpecComplete(browser, result);
expect(sut.stats).to.eq(browser.lastResult);
expect(Object.getPrototypeOf(sut.stats)).to.eq(browser.lastResult);
});

it('should only call save on dataStore when suppressErrorReport is false', function() {
Expand Down