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

Commit

Permalink
fix: Remove session id console output for skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tormozz48 committed Dec 9, 2016
1 parent 2aa4bb0 commit 6aa92e1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 46 deletions.
23 changes: 14 additions & 9 deletions lib/reporters/flat-factory/flat-verbose.js
@@ -1,18 +1,23 @@
'use strict';

const _ = require('lodash');
const chalk = require('chalk');
const Flat = require('./flat');

module.exports = class FlatVerbose extends Flat {
_formatStateInfo(result) {
const tmpl = result.state
? ' ${state} ${chalk.underline(name)} [${chalk.yellow(bId)}: ${chalk.blue(sId)}]'
: ' ${state} [${chalk.yellow(bId)}: ${chalk.blue(sId)}]';
const suite = result.suite.path.join(' ');

return this._compile(tmpl, {
state: result.suite.path.join(' '),
name: result.state && result.state.name,
bId: result.browserId,
sId: result.sessionId || 'unknown session id'
});
const state = result.state
? `${chalk.underline(result.state.name)}`
: '';

const session = result.suite.skipped
? ''
: `: ${chalk.blue(result.sessionId || 'unknown session id')}`;

const browser = `[${chalk.yellow(result.browserId)}${session}]`;

return _([suite, state, browser]).compact().join(' ');
}
};
49 changes: 19 additions & 30 deletions lib/reporters/flat-factory/flat.js
Expand Up @@ -30,14 +30,6 @@ module.exports = class Flat {
runner.on(Events.SKIP_STATE, this._onSkipState.bind(this));
}

_compile(tmpl, data) {
return _.template(tmpl, {
imports: {
chalk: chalk
}
})(data);
}

_onTestResult(result) {
const handler = result.equal ? this._onPassed : this._onError;
handler.call(this, result);
Expand All @@ -49,44 +41,47 @@ module.exports = class Flat {
}

_onRetry(result) {
logger.log(ICON_RETRY + this._formatRetryInfo(result));
logger.log(`${ICON_RETRY} ${this._formatRetryInfo(result)}`);
this._logError(result);

this._counter.onRetry(result);
}

_onPassed(result) {
logger.log(ICON_SUCCESS + this._formatStateInfo(result));
logger.log(`${ICON_SUCCESS} ${this._formatStateInfo(result)}`);
this._counter.onPassed(result);
}

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

_onNotUpdated(result) {
logger.log(ICON_NOT_UPDATED + this._formatStateInfo(result));
logger.log(`${ICON_NOT_UPDATED} ${this._formatStateInfo(result)}`);
this._counter.onPassed(result);
}

_onError(result) {
logger.log(ICON_FAIL + this._formatStateInfo(result));
logger.log(`${ICON_FAIL} ${this._formatStateInfo(result)}`);
this._logError(result);

this._counter.onFailed(result);
}

_onWarning(result) {
logger.log(ICON_WARN + this._formatStateInfo(result));
logger.log(`${ICON_WARN} ${this._formatStateInfo(result)}`);
logger.warn(result.message);

this._counter.onSkipped(result);
}

_onSkipState(result) {
logger.log(ICON_WARN + this._formatStateInfo(result)
+ (result.suite.skipComment ? chalk.yellow(' reason: ' + result.suite.skipComment) : ''));
const skipReason = result.suite.skipComment
? chalk.yellow('reason: ' + result.suite.skipComment)
: '';

logger.log(`${ICON_WARN} ${this._formatStateInfo(result)} ${skipReason}`);

this._counter.onSkipped(result);
}
Expand Down Expand Up @@ -121,23 +116,17 @@ module.exports = class Flat {
}

_formatRetryInfo(result) {
const tmpl = '${stateInfo} will be retried. Retries left: ${chalk.yellow(retriesLeft)}';
const stateInfo = this._formatStateInfo(result);
const retriesLeft = result.retriesLeft;

return this._compile(tmpl, {
stateInfo: this._formatStateInfo(result),
retriesLeft: result.retriesLeft
});
return `${stateInfo} will be retried. Retries left: ${chalk.yellow(retriesLeft)}`;
}

_formatStateInfo(result) {
const tmpl = result.state
? ' ${state} ${chalk.underline(name)} [${chalk.yellow(id)}]'
: ' ${state} [${chalk.yellow(id)}]';

return this._compile(tmpl, {
state: result.suite.path.join(' '),
name: result.state && result.state.name,
id: result.browserId
});
const suite = result.suite.path.join(' ');
const state = result.state && chalk.underline(result.state.name);
const browserId = `[${chalk.yellow(result.browserId)}]`;

return _([suite, state, browserId]).compact().join(' ');
}
};
26 changes: 19 additions & 7 deletions test/unit/reporters/flat-factory/flat-verbose.js
Expand Up @@ -11,6 +11,16 @@ describe('Reporter#FlatVerbose', () => {
const sandbox = sinon.sandbox.create();
let emitter;

function getTestLog(test) {
emitter.emit(Events.BEGIN);
emitter.emit(Events.UPDATE_RESULT, test);
emitter.emit(Events.END);

return chalk
.stripColor(logger.log.firstCall.args[0])
.substr(2); // remove first symbol (icon)
}

beforeEach(() => {
const reporter = new FlatVerboseReporter();

Expand All @@ -32,14 +42,16 @@ describe('Reporter#FlatVerbose', () => {
sessionId: '0fc23des'
};

emitter.emit(Events.BEGIN);
emitter.emit(Events.UPDATE_RESULT, test);
emitter.emit(Events.END);
assert.equal(getTestLog(test), 'block size big hover [chrome: 0fc23des]');
});

const deserealizedResult = chalk
.stripColor(logger.log.firstCall.args[0])
.substr(2); // remove first symbol (icon)
it('should not render session identifier for skipped tests', () => {
const test = {
suite: {path: ['some-path'], skipped: {}},
state: {name: 'some-name'},
browserId: 'chrome'
};

assert.equal(deserealizedResult, 'block size big hover [chrome: 0fc23des]');
assert.equal(getTestLog(test), 'some-path some-name [chrome]');
});
});

0 comments on commit 6aa92e1

Please sign in to comment.