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

Commit

Permalink
Merge pull request #563 from gemini-testing/fix/flat-reporter
Browse files Browse the repository at this point in the history
Added the ability to see in flat reporter how many references images have been updated
  • Loading branch information
DudaGod committed Aug 29, 2016
2 parents eed63f8 + 1c700ec commit a73ca63
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 131 deletions.
38 changes: 23 additions & 15 deletions lib/reporters/flat-factory/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ module.exports = class Flat {

attachRunner(runner) {
runner.on(RunnerEvents.TEST_RESULT, this._onTestResult.bind(this));
runner.on(RunnerEvents.RETRY, this._onRetry.bind(this));
runner.on(RunnerEvents.UPDATE_RESULT, this._onUpdateResult.bind(this));
runner.on(RunnerEvents.RETRY, this._onRetry.bind(this));
runner.on(RunnerEvents.ERROR, this._onError.bind(this));
runner.on(RunnerEvents.WARNING, this._onWarning.bind(this));
runner.on(RunnerEvents.END, this._onEnd.bind(this));
Expand All @@ -39,7 +39,12 @@ module.exports = class Flat {
}

_onTestResult(result) {
const handler = result.equal ? this._onCapture : this._onError;
const handler = result.equal ? this._onPassed : this._onError;
handler.call(this, result);
}

_onUpdateResult(result) {
const handler = result.updated ? this._onUpdated : this._onNotUpdated;
handler.call(this, result);
}

Expand All @@ -50,17 +55,17 @@ module.exports = class Flat {
this._counter.onRetry(result);
}

_onUpdateResult(result) {
const handler = result.updated ? this._onCapture : this._onNoCapture;
handler.call(this, result);
_onPassed(result) {
logger.log(ICON_SUCCESS + this._formatStateInfo(result));
this._counter.onPassed(result);
}

_onCapture(result) {
_onUpdated(result) {
logger.log(ICON_SUCCESS + this._formatStateInfo(result));
this._counter.onPassed(result);
this._counter.onUpdated(result);
}

_onNoCapture(result) {
_onNotUpdated(result) {
logger.log(ICON_NOT_UPDATED + this._formatStateInfo(result));
this._counter.onPassed(result);
}
Expand Down Expand Up @@ -93,13 +98,16 @@ module.exports = class Flat {
_onEnd() {
const result = this._counter.getResult();

logger.log('Total: %s Passed: %s Failed: %s Skipped: %s Retries: %s',
chalk.underline(result.total),
chalk.green(result.passed),
chalk.red(result.failed),
chalk.cyan(result.skipped),
chalk.cyan(result.retries)
);
const message = [
'Total: ' + chalk.underline(result.total),
result.updated && 'Updated: ' + chalk.green(result.updated),
'Passed: ' + (result.updated && chalk.grey(result.passed) || chalk.green(result.passed)),
'Failed: ' + chalk.red(result.failed),
'Skipped: ' + chalk.cyan(result.skipped),
'Retries: ' + chalk.cyan(result.retries)
];

logger.log(_.compact(message).join(' '));
}

_logError(result) {
Expand Down
6 changes: 6 additions & 0 deletions lib/reporters/utils/test-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _ = require('lodash'),
inherit = require('inherit');

var STATS = {
UPDATED: 'updated',
PASSED: 'passed',
FAILED: 'failed',
SKIPPED: 'skipped'
Expand All @@ -14,6 +15,10 @@ module.exports = inherit({
this._stats = {};
},

onUpdated: function(updated) {
this._addStat(STATS.UPDATED, updated);
},

onPassed: function(passed) {
this._addStat(STATS.PASSED, passed);
},
Expand All @@ -36,6 +41,7 @@ module.exports = inherit({
getResult: function() {
var result = {
total: 0,
updated: 0,
passed: 0,
failed: 0,
skipped: 0,
Expand Down
23 changes: 12 additions & 11 deletions lib/stats.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
'use strict';
var _ = require('lodash'),

RunnerEvents = require('./constants/runner-events');
const _ = require('lodash');

const RunnerEvents = require('./constants/runner-events');

/**
* @constructor
* @param {Runner} [runner]
*/
module.exports = function(runner) {
var data = {};
const data = {};

function add(key) {
const add = (key) => {
data[key] = data[key] || 0;
data[key]++;
}
};

if (runner) {
runner
.on(RunnerEvents.BEGIN_STATE, _.partial(add, 'total'))
.on(RunnerEvents.SKIP_STATE, function() {
.on(RunnerEvents.SKIP_STATE, () => {
add('total');
add('skipped');
})
.on(RunnerEvents.WARNING, _.partial(add, 'warned'))
.on(RunnerEvents.ERROR, _.partial(add, 'errored'))

.on(RunnerEvents.CAPTURE, _.partial(add, 'gathered'))
.on(RunnerEvents.TEST_RESULT, function(res) {
.on(RunnerEvents.UPDATE_RESULT, (res) => {
add(res && res.updated ? 'updated' : 'passed');
})
.on(RunnerEvents.TEST_RESULT, (res) => {
add(res && res.equal ? 'passed' : 'failed');
});
}

this.add = add;

this.get = function(name) {
return name === undefined ? data : data[name];
};
this.get = (name) => name === undefined ? data : data[name];
};
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
'use strict';

const chalk = require('chalk');
const _ = require('lodash');

const EventEmitter = require('events').EventEmitter;
const FlatReporter = require('lib/reporters/flat-factory/flat');
const RunnerEvents = require('lib/constants/runner-events');
const logger = require('lib/utils').logger;
const chalk = require('chalk');
const RunnerEvents = require('lib/constants/runner-events');

describe('Reporter#Flat', () => {
const sandbox = sinon.sandbox.create();

let test;
let emitter;

const getCounters = (args) => ({
total: chalk.stripColor(args[1]),
passed: chalk.stripColor(args[2]),
failed: chalk.stripColor(args[3]),
skipped: chalk.stripColor(args[4]),
retries: chalk.stripColor(args[5])
});
const getLoggedCounters = () => {
const str = logger.log.lastCall.args[0];
const chunks = chalk.stripColor(str).match(/([a-z]+):\s?([0-9]+)/ig);

return _(chunks)
.map((val) => val.toLowerCase().split(/:\s/))
.zipObject()
.value();
};

const emit = (event, data) => {
emitter.emit(RunnerEvents.BEGIN);

if (event) {
emitter.emit(event, data);
}

emitter.emit(RunnerEvents.END);
};

Expand All @@ -48,34 +54,53 @@ describe('Reporter#Flat', () => {
emitter.removeAllListeners();
});

it('should initialize counters with 0', () => {
it('should initialize all counters with 0 except updated', () => {
emit();

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.total, 0);
assert.equal(counters.passed, 0);
assert.equal(counters.failed, 0);
assert.equal(counters.skipped, 0);
assert.equal(counters.retries, 0);
['total', 'passed', 'failed', 'skipped', 'retries'].forEach((type) => assert.equal(counters[type], 0));
});

it('should not initialize update counter', () => {
emit();

const counters = getLoggedCounters();

assert.isUndefined(counters.updated);
});

describe('should correctly calculate counters for', () => {
it('successed', () => {
emit(RunnerEvents.UPDATE_RESULT, test);
describe('updated', () => {
it('should increment "total" and "updated" counters', () => {
test.updated = true;

const counters = getCounters(logger.log.lastCall.args);
emit(RunnerEvents.UPDATE_RESULT, test);

assert.equal(counters.total, 1);
assert.equal(counters.passed, 1);
assert.equal(counters.failed, 0);
assert.equal(counters.skipped, 0);
const counters = getLoggedCounters();

assert.equal(counters.total, 1);
assert.equal(counters.updated, 1);
});

it('should initialize all remaining counters with 0', () => {
test.updated = true;

emit(RunnerEvents.UPDATE_RESULT, test);

const counters = getLoggedCounters();

assert.equal(counters.passed, 0);
assert.equal(counters.failed, 0);
assert.equal(counters.skipped, 0);
assert.equal(counters.retries, 0);
});
});

it('failed', () => {
emit(RunnerEvents.ERROR, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.total, 1);
assert.equal(counters.passed, 0);
Expand All @@ -87,7 +112,7 @@ describe('Reporter#Flat', () => {
it('should increment skipped count on WARNING event', () => {
emit(RunnerEvents.WARNING, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.total, 1);
assert.equal(counters.skipped, 1);
Expand All @@ -96,7 +121,7 @@ describe('Reporter#Flat', () => {
it('should increment skipped count on SKIP_STATE event', () => {
emit(RunnerEvents.SKIP_STATE, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.total, 1);
assert.equal(counters.skipped, 1);
Expand All @@ -106,7 +131,7 @@ describe('Reporter#Flat', () => {
it('retry', () => {
emit(RunnerEvents.RETRY, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.retries, 1);
});
Expand All @@ -118,23 +143,48 @@ describe('Reporter#Flat', () => {

emit(RunnerEvents.TEST_RESULT, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.passed, 1);
assert.equal(counters.failed, 0);
});

it('false', () => {
test.equal = false;

emit(RunnerEvents.TEST_RESULT, test);

const counters = getCounters(logger.log.lastCall.args);
const counters = getLoggedCounters();

assert.equal(counters.passed, 0);
assert.equal(counters.failed, 1);
});
});

describe('should correctly choose a handler if `updated` is', () => {
it('true', () => {
test.updated = true;

emit(RunnerEvents.UPDATE_RESULT, test);

const counters = getLoggedCounters();

assert.equal(counters.updated, 1);
assert.equal(counters.passed, 0);
});

it('false', () => {
test.updated = false;

emit(RunnerEvents.UPDATE_RESULT, test);

const counters = getLoggedCounters();

assert.equal(counters.passed, 1);
assert.isUndefined(counters.updated);
});
});

describe('should print an error if it there is in', () => {
it('result', () => {
test.message = 'Error from result';
Expand Down

0 comments on commit a73ca63

Please sign in to comment.