Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/report-builder-factory/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Promise = require('bluebird');
const _ = require('lodash');
const fs = require('fs-extra');
const {IDLE, RUNNING, SUCCESS, FAIL, ERROR, SKIPPED, UPDATED} = require('../constants/test-statuses');
const {logger, getPathsFor} = require('../server-utils');
const {logger, getPathsFor, hasImage} = require('../server-utils');
const {setStatusForBranch, hasFails} = require('../static/modules/utils');

const NO_STATE = 'NO_STATE';
Expand Down Expand Up @@ -83,7 +83,6 @@ module.exports = class ReportBuilder {
_addErrorResult(formattedResult) {
return this._addTestResult(formattedResult, {
status: ERROR,
image: !!formattedResult.getImagesInfo(ERROR).length || !!formattedResult.currentPath || !!formattedResult.screenshot,
reason: formattedResult.error
});
}
Expand Down Expand Up @@ -125,6 +124,7 @@ module.exports = class ReportBuilder {

if (existing === -1) {
formattedResult.attempt = testResult.attempt;
formattedResult.image = hasImage(formattedResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нам же нужны эти вызовы только для статуса error? Может тогда по условию будем его вызывать?

extendTestWithImagePaths(testResult, formattedResult);
node.browsers.push({name: browserId, result: testResult, retries: []});
setStatusForBranch(this._tree, node.suitePath, testResult.status);
Expand All @@ -148,6 +148,7 @@ module.exports = class ReportBuilder {
}

formattedResult.attempt = testResult.attempt;
formattedResult.image = hasImage(formattedResult);

const {imagesInfo} = stateInBrowser.result;
stateInBrowser.result = extendTestWithImagePaths(testResult, formattedResult, imagesInfo);
Expand Down
5 changes: 5 additions & 0 deletions lib/server-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ function getPathsFor(status, formattedResult, stateName) {
return {};
}

function hasImage(formattedResult) {
return !!formattedResult.getImagesInfo(ERROR).length || !!formattedResult.currentPath || !!formattedResult.screenshot;
}

module.exports = {
getReferencePath,
getCurrentPath,
getDiffPath,
getPathsFor,
hasImage,

getReferenceAbsolutePath,
getCurrentAbsolutePath,
Expand Down
23 changes: 22 additions & 1 deletion test/lib/report-builder-factory/report-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
const fs = require('fs-extra');
const _ = require('lodash');
const {logger} = require('../../../lib/server-utils');
const ReportBuilder = require('../../../lib/report-builder-factory/report-builder');
const proxyquire = require('proxyquire');
const {SUCCESS, FAIL, ERROR, SKIPPED, IDLE, UPDATED} = require('../../../lib/constants/test-statuses');

describe('ReportBuilder', () => {
const sandbox = sinon.sandbox.create();
let hasImage, ReportBuilder;

const mkReportBuilder_ = ({toolConfig, pluginConfig} = {}) => {
toolConfig = _.defaults(toolConfig || {}, {getAbsoluteUrl: _.noop});
Expand Down Expand Up @@ -44,6 +45,13 @@ describe('ReportBuilder', () => {
sandbox.stub(fs, 'mkdirsSync');
sandbox.stub(fs, 'writeFileAsync').resolves();
sandbox.stub(fs, 'writeFileSync');

hasImage = sandbox.stub().returns(true);
ReportBuilder = proxyquire('../../../lib/report-builder-factory/report-builder', {
'../server-utils': {
hasImage
}
});
});

afterEach(() => sandbox.restore());
Expand Down Expand Up @@ -165,6 +173,19 @@ describe('ReportBuilder', () => {
});
});

it('should get correct test attempt while checking for image exists', () => {
const reportBuilder = mkReportBuilder_();
const testResult = stubTest_();

reportBuilder.addError(testResult);
const firstCallAttempt = hasImage.firstCall.args[0].attempt;
reportBuilder.addError(testResult);
const secondCallAttempt = hasImage.secondCall.args[0].attempt;

assert.equal(firstCallAttempt, 0);
assert.equal(secondCallAttempt, 1);
});

it('should add base host to result with value from plugin parameter "baseHost"', () => {
const reportBuilder = mkReportBuilder_({pluginConfig: {baseHost: 'some-host'}});

Expand Down