Skip to content

Commit 449ee78

Browse files
author
Rashid Ksirov
committed
feat: save & show error details
1 parent f2b981d commit 449ee78

10 files changed

Lines changed: 220 additions & 16 deletions

File tree

‎hermione.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ async function prepare(hermione, reportBuilder, pluginConfig) {
3232
const formattedResult = reportBuilder.format(testResult);
3333
const actions = [formattedResult.saveTestImages(reportPath, workers)];
3434

35+
if (formattedResult.errorDetails) {
36+
actions.push(formattedResult.saveErrorDetails(reportPath));
37+
}
38+
3539
if (formattedResult.screenshot) {
3640
actions.push(formattedResult.saveBase64Screenshot(reportPath));
3741
}

‎lib/gui/server.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ exports.start = ({paths, tool, guiApi, configs}) => {
2121
server.use(express.static(path.join(__dirname, '../static'), {index: 'gui.html'}));
2222
server.use(express.static(process.cwd()));
2323
server.use('/images', express.static(path.join(process.cwd(), pluginConfig.path, 'images')));
24+
server.use('/error-details', express.static(path.join(process.cwd(), pluginConfig.path, 'error-details')));
2425

2526
server.get('/', (req, res) => res.sendFile(path.join(__dirname, '../static', 'gui.html')));
2627

‎lib/gui/tool-runner-factory/hermione/report-subscriber.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
1616
actions.push(formattedResult.saveBase64Screenshot(reportPath));
1717
}
1818

19+
if (formattedResult.errorDetails) {
20+
actions.push(formattedResult.saveErrorDetails(reportPath));
21+
}
22+
1923
return Promise.all(actions);
2024
}
2125

‎lib/report-builder-factory/report-builder.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,21 @@ module.exports = class ReportBuilder {
116116

117117
_createTestResult(result, props) {
118118
const {browserId, suite, sessionId, description, imagesInfo, screenshot, multipleTabs} = result;
119+
const {errorDetails} = result;
119120
const {baseHost} = this._pluginConfig;
120121
const suiteUrl = suite.getUrl({browserId, baseHost});
121122
const metaInfo = _.merge(_.cloneDeep(result.meta), {url: suite.fullUrl, file: suite.file, sessionId});
122123

123-
return Object.assign({
124+
const testResult = Object.assign({
124125
suiteUrl, name: browserId, metaInfo, description, imagesInfo,
125126
screenshot: Boolean(screenshot), multipleTabs
126127
}, props);
128+
129+
if (errorDetails) {
130+
testResult.errorDetails = _.pick(errorDetails, ['title', 'filePath']);
131+
}
132+
133+
return testResult;
127134
}
128135

129136
_getResultNode(formattedResult) {

‎lib/server-utils.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const chalk = require('chalk');
66
const _ = require('lodash');
77
const fs = require('fs-extra');
88

9+
const {getShortMD5} = require('./gui/tool-runner-factory/hermione/utils');
910
const {ERROR, UPDATED, IDLE} = require('./constants/test-statuses');
1011

1112
const getReferencePath = (testResult, stateName) => createPath('ref', testResult, stateName);
@@ -89,7 +90,13 @@ function shouldUpdateAttempt(status) {
8990
return ![UPDATED, IDLE].includes(status);
9091
}
9192

93+
function getDetailsFileName(suitePath, browserId, attempt) {
94+
return `${getShortMD5(suitePath.join(' '))}-${browserId}_${+attempt + 1}_${Date.now()}.json`;
95+
}
96+
9297
module.exports = {
98+
getDetailsFileName,
99+
93100
getReferencePath,
94101
getCurrentPath,
95102
getDiffPath,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
import React, {Component} from 'react';
4+
import PropTypes from 'prop-types';
5+
import ToggleOpen from '../../toggle-open';
6+
7+
export default class ErrorDetails extends Component {
8+
static propTypes = {
9+
errorDetails: PropTypes.object.isRequired
10+
};
11+
12+
render() {
13+
const {title, filePath} = this.props.errorDetails;
14+
const content = <div className="toggle-open__item"><a href={filePath}>{title}</a></div>;
15+
16+
return <ToggleOpen title='Error details' content={content} extendClassNames="toggle-open_type_text"/>;
17+
}
18+
}

‎lib/static/components/section/body/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwitcherRetry from '../switcher-retry';
1010
import ControlButton from '../../controls/control-button';
1111
import State from '../../state';
1212
import MetaInfo from './meta-info';
13+
import ErrorDetails from './error-details';
1314
import Description from './description';
1415
import * as actions from '../../../modules/actions';
1516
import {isSuccessStatus, isErroredStatus} from '../../../../common-utils';
@@ -167,7 +168,7 @@ class Body extends Component {
167168
render() {
168169
const {retries} = this.props;
169170
const activeResult = this._getActiveResult();
170-
const {metaInfo, suiteUrl, description} = activeResult;
171+
const {metaInfo, suiteUrl, description, errorDetails} = activeResult;
171172

172173
return (
173174
<div className="section__body">
@@ -180,6 +181,7 @@ class Body extends Component {
180181
{this._addRetryButton()}
181182
</div>
182183
<MetaInfo metaInfo={metaInfo} suiteUrl={suiteUrl} getExtraMetaInfo={this.getExtraMetaInfo}/>
184+
{errorDetails && <ErrorDetails errorDetails={errorDetails}/>}
183185
{description && <Description content={description}/>}
184186
{this._getTabs()}
185187
</div>

‎lib/test-adapter/hermione-test-adapter.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module.exports = class HermioneTestResultAdapter extends TestAdapter {
3232
this._suite = HermioneSuiteAdapter.create(this._testResult);
3333
this._imagesSaver = this._tool.htmlReporter.imagesSaver;
3434
this._testId = `${this._testResult.fullTitle()}.${this._testResult.browserId}`;
35+
this._errorDetails = undefined;
36+
3537
if (utils.shouldUpdateAttempt(status)) {
3638
testsAttempts.set(this._testId, _.isUndefined(testsAttempts.get(this._testId)) ? 0 : testsAttempts.get(this._testId) + 1);
3739
}
@@ -141,6 +143,24 @@ module.exports = class HermioneTestResultAdapter extends TestAdapter {
141143
return this._testResult.meta;
142144
}
143145

146+
get errorDetails() {
147+
if (this._errorDetails !== undefined) {
148+
return this._errorDetails;
149+
}
150+
151+
const details = _.get(this._testResult, 'err.details', null);
152+
153+
this._errorDetails = details ? {
154+
title: details.title || 'error details',
155+
data: details.data,
156+
filePath: `error-details/${utils.getDetailsFileName(
157+
getSuitePath(this._testResult), this._testResult.browserId, this.attempt
158+
)}`
159+
} : null;
160+
161+
return this._errorDetails;
162+
}
163+
144164
getRefImg(stateName) {
145165
return _.get(_.find(this.assertViewResults, {stateName}), 'refImg', {});
146166
}
@@ -164,6 +184,17 @@ module.exports = class HermioneTestResultAdapter extends TestAdapter {
164184
return true;
165185
}
166186

187+
async saveErrorDetails(reportPath) {
188+
if (!this.errorDetails) {
189+
return;
190+
}
191+
192+
const destDetailsFilePath = `${path.resolve(reportPath)}/${this.errorDetails.filePath}`;
193+
194+
await utils.makeDirFor(destDetailsFilePath);
195+
await fs.writeFile(destDetailsFilePath, JSON.stringify(this.errorDetails.data, null, 2));
196+
}
197+
167198
saveTestImages(reportPath, workers) {
168199
return Promise.map(this.assertViewResults, async (assertResult) => {
169200
const {stateName} = assertResult;

‎test/unit/lib/server-utils.js‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
const path = require('path');
44
const fs = require('fs-extra');
55
const utils = require('lib/server-utils');
6+
const {getShortMD5} = require('lib/gui/tool-runner-factory/hermione/utils');
67

78
describe('server-utils', () => {
9+
const sandbox = sinon.sandbox.create();
10+
11+
afterEach(() => sandbox.restore());
12+
813
[
914
{name: 'Reference', prefix: 'ref'},
1015
{name: 'Current', prefix: 'current'},
@@ -47,14 +52,10 @@ describe('server-utils', () => {
4752
});
4853

4954
describe(`get${testData.name}AbsolutePath`, () => {
50-
const sandbox = sinon.sandbox.create();
51-
5255
beforeEach(() => {
5356
sandbox.stub(process, 'cwd').returns('/root');
5457
});
5558

56-
afterEach(() => sandbox.restore());
57-
5859
it('should generate correct absolute path for test image', () => {
5960
const test = {
6061
imageDir: 'some/dir',
@@ -80,10 +81,6 @@ describe('server-utils', () => {
8081
});
8182

8283
describe('prepareCommonJSData', () => {
83-
const sandbox = sinon.sandbox.create();
84-
85-
afterEach(() => sandbox.restore());
86-
8784
it('should wrap passed data with commonjs wrapper', () => {
8885
const result = utils.prepareCommonJSData({some: 'data'});
8986

@@ -103,15 +100,11 @@ describe('server-utils', () => {
103100
});
104101

105102
describe('copyImageAsync', () => {
106-
const sandbox = sinon.sandbox.create();
107-
108103
beforeEach(() => {
109104
sandbox.stub(fs, 'copy').resolves();
110105
sandbox.stub(fs, 'mkdirs').resolves();
111106
});
112107

113-
afterEach(() => sandbox.restore());
114-
115108
it('should create directory and copy image', () => {
116109
const fromPath = '/from/image.png',
117110
toPath = '/to/image.png';
@@ -123,4 +116,14 @@ describe('server-utils', () => {
123116
});
124117
});
125118
});
119+
120+
describe('getDetailsFileName', () => {
121+
it('should compose correct file name from suite path, browser id and attempt', () => {
122+
sandbox.stub(Date, 'now').returns('123456789');
123+
const suitePath = ['root-title', 'some-title'];
124+
const expected = `${getShortMD5('root-title some-title')}-bro_2_123456789.json`;
125+
126+
assert.equal(utils.getDetailsFileName(suitePath, 'bro', 1), expected);
127+
});
128+
});
126129
});

0 commit comments

Comments
 (0)