Skip to content

Commit b498f47

Browse files
fix: add steps support
1 parent ac9791a commit b498f47

File tree

17 files changed

+219
-78
lines changed

17 files changed

+219
-78
lines changed

lib/constants/database.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const SUITES_TABLE_COLUMNS = [
77
{name: 'name', type: DB_TYPES.text},
88
{name: 'suiteUrl', type: DB_TYPES.text},
99
{name: 'metaInfo', type: DB_TYPES.text},
10+
{name: 'history', type: DB_TYPES.text},
1011
{name: 'description', type: DB_TYPES.text},
1112
{name: 'error', type: DB_TYPES.text},
1213
{name: 'skipReason', type: DB_TYPES.text},

lib/history-utils.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
11
'use strict';
22

3-
const {last, isUndefined} = require('lodash');
3+
const {isEmpty} = require('lodash');
44

55
const formatDuration = (d) => `<- ${d}ms`;
66

77
const wrapArg = (arg) => `"${arg}"`;
88

99
const getCommand = ({
1010
n: name,
11-
a: args = [],
12-
d: duration}
13-
) => `${name}(${args.map(wrapArg).join(', ')}) ${formatDuration(duration)}`;
11+
a: args = []
12+
}) => `${name}(${args.map(wrapArg).join(', ')})`;
13+
14+
const traverseNodes = (nodes, traverseCb, depth = 0) => {
15+
nodes.forEach(node => {
16+
const shouldTraverseChildren = traverseCb(node, depth);
17+
18+
if (shouldTraverseChildren) {
19+
traverseNodes(node.c, traverseCb, depth + 1);
20+
}
21+
});
22+
};
1423

1524
const getCommandsHistory = (history) => {
16-
if (isUndefined(history)) {
25+
if (isEmpty(history)) {
1726
return;
1827
}
1928

2029
try {
21-
const formatedCommands = history
22-
.map(getCommand)
23-
.map((s) => `\t${s}\n`);
24-
const lastCommandChildren = last(history).c;
25-
const formatedChildren = lastCommandChildren
26-
.map((cmd) => `${getCommand(cmd)}`)
27-
.map((s) => `\t\t${s}\n`);
28-
29-
return [...formatedCommands, ...formatedChildren];
30+
const formatedHistory = [];
31+
32+
const traverseCb = (node, depth) => {
33+
const offset = '\t'.repeat(depth);
34+
const isStep = node.n === 'runStep';
35+
const duration = node.d;
36+
const isFailed = !!node.f;
37+
const title = isStep ? node.a[0] : getCommand(node);
38+
const formatedDuration = formatDuration(duration);
39+
40+
formatedHistory.push(`${offset}${title} ${formatedDuration}\n`);
41+
42+
return isFailed;
43+
};
44+
45+
traverseNodes(history, traverseCb);
46+
47+
return formatedHistory;
3048
} catch (e) {
3149
return `failed to get command history: ${e.message}`;
3250
}

lib/report-builder/static.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = class StaticReportBuilder {
3838

3939
return result instanceof TestAdapter
4040
? result
41-
: TestAdapter.create(result, this._hermione, this._pluginConfig, status);
41+
: TestAdapter.create(result, this._hermione, status);
4242
}
4343

4444
async saveStaticFiles() {
@@ -111,16 +111,17 @@ module.exports = class StaticReportBuilder {
111111

112112
_createTestResult(result, props) {
113113
const {
114-
browserId, suite, sessionId, description, imagesInfo, screenshot, multipleTabs, errorDetails
114+
browserId, suite, sessionId, description, history,
115+
imagesInfo, screenshot, multipleTabs, errorDetails
115116
} = result;
116117

117118
const {baseHost, saveErrorDetails} = this._pluginConfig;
118119
const suiteUrl = suite.getUrl({browserId, baseHost});
119120
const metaInfo = _.merge(_.cloneDeep(result.meta), {url: suite.fullUrl, file: suite.file, sessionId});
120121

121122
const testResult = Object.assign({
122-
suiteUrl, name: browserId, metaInfo, description, imagesInfo,
123-
screenshot: Boolean(screenshot), multipleTabs
123+
suiteUrl, name: browserId, metaInfo, description, history,
124+
imagesInfo, screenshot: Boolean(screenshot), multipleTabs
124125
}, props);
125126

126127
if (saveErrorDetails && errorDetails) {

lib/sqlite-adapter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module.exports = class SqliteAdapter {
6666
name,
6767
suiteUrl,
6868
metaInfo,
69+
history,
6970
description,
7071
error,
7172
skipReason,
@@ -82,6 +83,7 @@ module.exports = class SqliteAdapter {
8283
name,
8384
suiteUrl,
8485
metaInfo,
86+
history,
8587
description,
8688
error,
8789
skipReason,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import {connect} from 'react-redux';
3+
import PropTypes from 'prop-types';
4+
import {isEmpty} from 'lodash';
5+
import Details from '../../../details';
6+
7+
import './index.styl';
8+
9+
const History = ({history}) => (
10+
isEmpty(history)
11+
? null
12+
: <Details
13+
title='History'
14+
content={history}
15+
extendClassNames='details_type_text history'
16+
/>
17+
);
18+
19+
History.propTypes = {
20+
resultId: PropTypes.string.isRequired,
21+
// from store
22+
history: PropTypes.arrayOf(PropTypes.string).isRequired
23+
};
24+
25+
export default connect(({tree}, {resultId}) => {
26+
const {history = []} = tree.results.byId[resultId];
27+
28+
return {history};
29+
})(History);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.history {
2+
white-space: pre-wrap;
3+
word-wrap: break-word;
4+
}

lib/static/components/section/body/result.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {Component, Fragment} from 'react';
22
import {connect} from 'react-redux';
33
import PropTypes from 'prop-types';
44
import MetaInfo from './meta-info';
5+
import History from './history';
56
import Description from './description';
67
import Tabs from './tabs';
78
import ExtensionPoint from '../../extension-point';
@@ -26,6 +27,7 @@ class Result extends Component {
2627
<Fragment>
2728
<ExtensionPoint name={RESULT_META} result={result} testName={testName}>
2829
<MetaInfo resultId={resultId} />
30+
<History resultId={resultId} />
2931
</ExtensionPoint>
3032
{result.description && <Description content={result.description} />}
3133
<Tabs result={result} />

lib/test-adapter.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ const globalCacheDiffImages = new Map();
2727
const testsAttempts = new Map();
2828

2929
module.exports = class TestAdapter {
30-
static create(testResult = {}, hermione, pluginConfig, status) {
31-
return new this(testResult, hermione, pluginConfig, status);
30+
static create(testResult = {}, hermione, status) {
31+
return new this(testResult, hermione, status);
3232
}
3333

34-
constructor(testResult, hermione, pluginConfig, status) {
34+
constructor(testResult, hermione, status) {
3535
this._testResult = testResult;
3636
this._hermione = hermione;
37-
this._pluginConfig = pluginConfig;
3837
this._errors = this._hermione.errors;
3938
this._suite = SuiteAdapter.create(this._testResult);
4039
this._imagesSaver = this._hermione.htmlReporter.imagesSaver;
@@ -220,16 +219,12 @@ module.exports = class TestAdapter {
220219
return this.imagesInfo;
221220
}
222221

223-
get error() {
224-
const err = _.pick(this._testResult.err, ['message', 'stack', 'stateName']);
225-
const {history} = this._testResult;
226-
const {commandsWithShortHistory} = this._pluginConfig;
227-
228-
if (!_.isEmpty(history)) {
229-
err.history = getCommandsHistory(history, commandsWithShortHistory);
230-
}
222+
get history() {
223+
return getCommandsHistory(this._testResult.history);
224+
}
231225

232-
return err;
226+
get error() {
227+
return _.pick(this._testResult.err, ['message', 'stack', 'stateName']);
233228
}
234229

235230
get imageDir() {

lib/tests-tree-builder/static.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function mkTestResult(row, data = {}) {
154154
description: row[DB_COLUMN_INDEXES.description],
155155
imagesInfo: JSON.parse(row[DB_COLUMN_INDEXES.imagesInfo]),
156156
metaInfo: JSON.parse(row[DB_COLUMN_INDEXES.metaInfo]),
157+
history: JSON.parse(row[DB_COLUMN_INDEXES.history]),
157158
multipleTabs: Boolean(row[DB_COLUMN_INDEXES.multipleTabs]),
158159
name: row[DB_COLUMN_INDEXES.name],
159160
screenshot: Boolean(row[DB_COLUMN_INDEXES.screenshot]),

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)