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

Commit 6aa92e1

Browse files
committed
fix: Remove session id console output for skipped tests
1 parent 2aa4bb0 commit 6aa92e1

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
'use strict';
22

3+
const _ = require('lodash');
4+
const chalk = require('chalk');
35
const Flat = require('./flat');
46

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

11-
return this._compile(tmpl, {
12-
state: result.suite.path.join(' '),
13-
name: result.state && result.state.name,
14-
bId: result.browserId,
15-
sId: result.sessionId || 'unknown session id'
16-
});
11+
const state = result.state
12+
? `${chalk.underline(result.state.name)}`
13+
: '';
14+
15+
const session = result.suite.skipped
16+
? ''
17+
: `: ${chalk.blue(result.sessionId || 'unknown session id')}`;
18+
19+
const browser = `[${chalk.yellow(result.browserId)}${session}]`;
20+
21+
return _([suite, state, browser]).compact().join(' ');
1722
}
1823
};

lib/reporters/flat-factory/flat.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ module.exports = class Flat {
3030
runner.on(Events.SKIP_STATE, this._onSkipState.bind(this));
3131
}
3232

33-
_compile(tmpl, data) {
34-
return _.template(tmpl, {
35-
imports: {
36-
chalk: chalk
37-
}
38-
})(data);
39-
}
40-
4133
_onTestResult(result) {
4234
const handler = result.equal ? this._onPassed : this._onError;
4335
handler.call(this, result);
@@ -49,44 +41,47 @@ module.exports = class Flat {
4941
}
5042

5143
_onRetry(result) {
52-
logger.log(ICON_RETRY + this._formatRetryInfo(result));
44+
logger.log(`${ICON_RETRY} ${this._formatRetryInfo(result)}`);
5345
this._logError(result);
5446

5547
this._counter.onRetry(result);
5648
}
5749

5850
_onPassed(result) {
59-
logger.log(ICON_SUCCESS + this._formatStateInfo(result));
51+
logger.log(`${ICON_SUCCESS} ${this._formatStateInfo(result)}`);
6052
this._counter.onPassed(result);
6153
}
6254

6355
_onUpdated(result) {
64-
logger.log(ICON_SUCCESS + this._formatStateInfo(result));
56+
logger.log(`${ICON_SUCCESS} ${this._formatStateInfo(result)}`);
6557
this._counter.onUpdated(result);
6658
}
6759

6860
_onNotUpdated(result) {
69-
logger.log(ICON_NOT_UPDATED + this._formatStateInfo(result));
61+
logger.log(`${ICON_NOT_UPDATED} ${this._formatStateInfo(result)}`);
7062
this._counter.onPassed(result);
7163
}
7264

7365
_onError(result) {
74-
logger.log(ICON_FAIL + this._formatStateInfo(result));
66+
logger.log(`${ICON_FAIL} ${this._formatStateInfo(result)}`);
7567
this._logError(result);
7668

7769
this._counter.onFailed(result);
7870
}
7971

8072
_onWarning(result) {
81-
logger.log(ICON_WARN + this._formatStateInfo(result));
73+
logger.log(`${ICON_WARN} ${this._formatStateInfo(result)}`);
8274
logger.warn(result.message);
8375

8476
this._counter.onSkipped(result);
8577
}
8678

8779
_onSkipState(result) {
88-
logger.log(ICON_WARN + this._formatStateInfo(result)
89-
+ (result.suite.skipComment ? chalk.yellow(' reason: ' + result.suite.skipComment) : ''));
80+
const skipReason = result.suite.skipComment
81+
? chalk.yellow('reason: ' + result.suite.skipComment)
82+
: '';
83+
84+
logger.log(`${ICON_WARN} ${this._formatStateInfo(result)} ${skipReason}`);
9085

9186
this._counter.onSkipped(result);
9287
}
@@ -121,23 +116,17 @@ module.exports = class Flat {
121116
}
122117

123118
_formatRetryInfo(result) {
124-
const tmpl = '${stateInfo} will be retried. Retries left: ${chalk.yellow(retriesLeft)}';
119+
const stateInfo = this._formatStateInfo(result);
120+
const retriesLeft = result.retriesLeft;
125121

126-
return this._compile(tmpl, {
127-
stateInfo: this._formatStateInfo(result),
128-
retriesLeft: result.retriesLeft
129-
});
122+
return `${stateInfo} will be retried. Retries left: ${chalk.yellow(retriesLeft)}`;
130123
}
131124

132125
_formatStateInfo(result) {
133-
const tmpl = result.state
134-
? ' ${state} ${chalk.underline(name)} [${chalk.yellow(id)}]'
135-
: ' ${state} [${chalk.yellow(id)}]';
136-
137-
return this._compile(tmpl, {
138-
state: result.suite.path.join(' '),
139-
name: result.state && result.state.name,
140-
id: result.browserId
141-
});
126+
const suite = result.suite.path.join(' ');
127+
const state = result.state && chalk.underline(result.state.name);
128+
const browserId = `[${chalk.yellow(result.browserId)}]`;
129+
130+
return _([suite, state, browserId]).compact().join(' ');
142131
}
143132
};

test/unit/reporters/flat-factory/flat-verbose.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ describe('Reporter#FlatVerbose', () => {
1111
const sandbox = sinon.sandbox.create();
1212
let emitter;
1313

14+
function getTestLog(test) {
15+
emitter.emit(Events.BEGIN);
16+
emitter.emit(Events.UPDATE_RESULT, test);
17+
emitter.emit(Events.END);
18+
19+
return chalk
20+
.stripColor(logger.log.firstCall.args[0])
21+
.substr(2); // remove first symbol (icon)
22+
}
23+
1424
beforeEach(() => {
1525
const reporter = new FlatVerboseReporter();
1626

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

35-
emitter.emit(Events.BEGIN);
36-
emitter.emit(Events.UPDATE_RESULT, test);
37-
emitter.emit(Events.END);
45+
assert.equal(getTestLog(test), 'block size big hover [chrome: 0fc23des]');
46+
});
3847

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

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

0 commit comments

Comments
 (0)