Skip to content

Commit 043b4b7

Browse files
author
Rashid Ksirov
committed
fix: add saveErrorDetails option, unit-test, fix readme
1 parent 5c374b5 commit 043b4b7

7 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Plugin has following configuration:
2020
* **path** (optional) `String` - path to directory for saving html report file; by
2121
default html report will be saved into `gemini-report/index.html` inside current work
2222
directory.
23+
* **saveErrorDetails** (optional) `Boolean` – save/don't save error details to json-files (to error-details folder); `false` by default
2324
* **defaultView** (optional) `String` - default view mode. Available values are:
2425
* `all` - show all tests. Default value.
2526
* `failed` - show only failed tests.

‎lib/config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ const getParser = () => {
7676
defaultValue: 'html-report',
7777
validate: assertString('path')
7878
}),
79+
saveErrorDetails: option({
80+
defaultValue: false,
81+
parseEnv: JSON.parse,
82+
parseCli: JSON.parse,
83+
validate: assertBoolean('saveErrorDetails')
84+
}),
7985
defaultView: option({
8086
defaultValue: configDefaults.defaultView,
8187
validate: assertString('defaultView')

‎lib/constants/defaults.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
CIRCLE_RADIUS: 150,
55
config: {
6+
saveErrorDetails: false,
67
defaultView: 'all',
78
baseHost: '',
89
scaleImages: false,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = class ReportBuilder {
119119
browserId, suite, sessionId, description, imagesInfo, screenshot, multipleTabs, errorDetails
120120
} = result;
121121

122-
const {baseHost} = this._pluginConfig;
122+
const {baseHost, saveErrorDetails} = this._pluginConfig;
123123
const suiteUrl = suite.getUrl({browserId, baseHost});
124124
const metaInfo = _.merge(_.cloneDeep(result.meta), {url: suite.fullUrl, file: suite.file, sessionId});
125125

@@ -128,7 +128,7 @@ module.exports = class ReportBuilder {
128128
screenshot: Boolean(screenshot), multipleTabs
129129
}, props);
130130

131-
if (errorDetails) {
131+
if (saveErrorDetails && errorDetails) {
132132
testResult.errorDetails = _.pick(errorDetails, ['title', 'filePath']);
133133
}
134134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ module.exports = class HermioneTestResultAdapter extends TestAdapter {
145145
}
146146

147147
get errorDetails() {
148-
if (this._errorDetails !== undefined) {
148+
if (!_.isUndefined(this._errorDetails)) {
149149
return this._errorDetails;
150150
}
151151

‎test/unit/lib/config.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ describe('config', () => {
6868
});
6969
});
7070

71+
describe('"saveErrorDetails" option', () => {
72+
it('should be false by default', () => {
73+
assert.isFalse(parseConfig({}).saveErrorDetails);
74+
});
75+
76+
it('should set from configuration file', () => {
77+
const config = parseConfig({saveErrorDetails: true});
78+
79+
assert.isTrue(config.saveErrorDetails);
80+
});
81+
82+
it('should set from environment variable', () => {
83+
process.env['html_reporter_save_error_details'] = 'true';
84+
85+
assert.isTrue(parseConfig({}).saveErrorDetails);
86+
});
87+
88+
it('should set from cli', () => {
89+
process.argv = process.argv.concat('--html-reporter-save-error-details', 'true');
90+
91+
assert.isTrue(parseConfig({}).saveErrorDetails);
92+
});
93+
});
94+
7195
describe('"defaultView" option', () => {
7296
it('should show all suites by default', () => {
7397
assert.equal(parseConfig({}).defaultView, 'all');

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,34 @@ describe('ReportBuilder', () => {
208208
});
209209
});
210210

211+
it('should add error details to result if saveErrorDetails is set', () => {
212+
const reportBuilder = mkReportBuilder_({pluginConfig: {saveErrorDetails: true}});
213+
214+
reportBuilder.addFail(stubTest_({
215+
errorDetails: {title: 'some-title', filePath: 'some-path'}
216+
}));
217+
218+
assert.match(getReportBuilderResult_(reportBuilder), {
219+
errorDetails: {
220+
title: 'some-title', filePath: 'some-path'
221+
}
222+
});
223+
});
224+
225+
it('should not add error details to result if saveErrorDetails is not set', () => {
226+
const reportBuilder = mkReportBuilder_({pluginConfig: {saveErrorDetails: false}});
227+
228+
reportBuilder.addFail(stubTest_({
229+
errorDetails: {title: 'some-title', filePath: 'some-path'}
230+
}));
231+
232+
assert.notDeepInclude(getReportBuilderResult_(reportBuilder), {
233+
errorDetails: {
234+
title: 'some-title', filePath: 'some-path'
235+
}
236+
});
237+
});
238+
211239
it('should add error test to result', () => {
212240
const reportBuilder = mkReportBuilder_();
213241

0 commit comments

Comments
 (0)