Skip to content

Commit

Permalink
fix: add saveErrorDetails option, unit-test, fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Ksirov committed Sep 27, 2019
1 parent 5c374b5 commit 043b4b7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Plugin has following configuration:
* **path** (optional) `String` - path to directory for saving html report file; by
default html report will be saved into `gemini-report/index.html` inside current work
directory.
* **saveErrorDetails** (optional) `Boolean` – save/don't save error details to json-files (to error-details folder); `false` by default
* **defaultView** (optional) `String` - default view mode. Available values are:
* `all` - show all tests. Default value.
* `failed` - show only failed tests.
Expand Down
6 changes: 6 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ const getParser = () => {
defaultValue: 'html-report',
validate: assertString('path')
}),
saveErrorDetails: option({
defaultValue: false,
parseEnv: JSON.parse,
parseCli: JSON.parse,
validate: assertBoolean('saveErrorDetails')
}),
defaultView: option({
defaultValue: configDefaults.defaultView,
validate: assertString('defaultView')
Expand Down
1 change: 1 addition & 0 deletions lib/constants/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module.exports = {
CIRCLE_RADIUS: 150,
config: {
saveErrorDetails: false,
defaultView: 'all',
baseHost: '',
scaleImages: false,
Expand Down
4 changes: 2 additions & 2 deletions lib/report-builder-factory/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = class ReportBuilder {
browserId, suite, sessionId, description, imagesInfo, screenshot, multipleTabs, errorDetails
} = result;

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

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

if (errorDetails) {
if (saveErrorDetails && errorDetails) {
testResult.errorDetails = _.pick(errorDetails, ['title', 'filePath']);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/test-adapter/hermione-test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module.exports = class HermioneTestResultAdapter extends TestAdapter {
}

get errorDetails() {
if (this._errorDetails !== undefined) {
if (!_.isUndefined(this._errorDetails)) {
return this._errorDetails;
}

Expand Down
24 changes: 24 additions & 0 deletions test/unit/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ describe('config', () => {
});
});

describe('"saveErrorDetails" option', () => {
it('should be false by default', () => {
assert.isFalse(parseConfig({}).saveErrorDetails);
});

it('should set from configuration file', () => {
const config = parseConfig({saveErrorDetails: true});

assert.isTrue(config.saveErrorDetails);
});

it('should set from environment variable', () => {
process.env['html_reporter_save_error_details'] = 'true';

assert.isTrue(parseConfig({}).saveErrorDetails);
});

it('should set from cli', () => {
process.argv = process.argv.concat('--html-reporter-save-error-details', 'true');

assert.isTrue(parseConfig({}).saveErrorDetails);
});
});

describe('"defaultView" option', () => {
it('should show all suites by default', () => {
assert.equal(parseConfig({}).defaultView, 'all');
Expand Down
28 changes: 28 additions & 0 deletions test/unit/lib/report-builder-factory/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,34 @@ describe('ReportBuilder', () => {
});
});

it('should add error details to result if saveErrorDetails is set', () => {
const reportBuilder = mkReportBuilder_({pluginConfig: {saveErrorDetails: true}});

reportBuilder.addFail(stubTest_({
errorDetails: {title: 'some-title', filePath: 'some-path'}
}));

assert.match(getReportBuilderResult_(reportBuilder), {
errorDetails: {
title: 'some-title', filePath: 'some-path'
}
});
});

it('should not add error details to result if saveErrorDetails is not set', () => {
const reportBuilder = mkReportBuilder_({pluginConfig: {saveErrorDetails: false}});

reportBuilder.addFail(stubTest_({
errorDetails: {title: 'some-title', filePath: 'some-path'}
}));

assert.notDeepInclude(getReportBuilderResult_(reportBuilder), {
errorDetails: {
title: 'some-title', filePath: 'some-path'
}
});
});

it('should add error test to result', () => {
const reportBuilder = mkReportBuilder_();

Expand Down

0 comments on commit 043b4b7

Please sign in to comment.