Skip to content

Commit

Permalink
Merge pull request #131 from gemini-testing/sp.fixRetries
Browse files Browse the repository at this point in the history
fix(gui): broken images for retried tests
  • Loading branch information
sipayRT authored Jul 12, 2018
2 parents f42672d + 99e5869 commit 8ef988b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
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);
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

0 comments on commit 8ef988b

Please sign in to comment.