Skip to content

Commit

Permalink
feat: emit "UPDATE_REFERENCE" event in hermione on accept screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Apr 9, 2019
1 parent ab8fe14 commit 6f95fda
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/gui/tool-runner-factory/base-tool-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ module.exports = class ToolRunner {

return reporterHelper.updateReferenceImage(formattedResult, this._reportPath, stateName)
.then(() => {
this._tool.emit(
this._tool.events.UPDATE_RESULT,
_.extend(updateResult, {refImg: imageInfo.expectedImg})
);
const result = _.extend(updateResult, {refImg: imageInfo.expectedImg});

this._emitUpdateReference(result, stateName);
});
}).then(() => {
reportBuilder.addUpdated(updateResult);
Expand Down
7 changes: 7 additions & 0 deletions lib/gui/tool-runner-factory/gemini/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ module.exports = class GeminiRunner extends BaseToolRunner {

return _.merge(testResult, {refImg, currImg, sessionId, attempt, imagesInfo, suite: {fullUrl}, updated: true});
}

_emitUpdateReference(result) {
this._tool.emit(
this._tool.events.UPDATE_RESULT,
result
);
}
};

function getAllStates(suites) {
Expand Down
7 changes: 7 additions & 0 deletions lib/gui/tool-runner-factory/hermione/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ module.exports = class HermioneRunner extends BaseToolRunner {

return _.merge({}, testResult, {assertViewResults, imagesInfo, sessionId, attempt, meta: {url}, updated: true});
}

_emitUpdateReference({refImg}, state) {
this._tool.emit(
this._tool.events.UPDATE_REFERENCE,
{refImg, state}
);
}
};
94 changes: 92 additions & 2 deletions test/lib/gui/tool-runner-factory/hermione/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require('lodash');
const proxyquire = require('proxyquire');
const ReportBuilder = require('lib/report-builder-factory/report-builder');
const {stubTool} = require('test/utils');
const {stubTool, stubConfig, mkTestResult, mkImagesInfo} = require('test/utils');

describe('lib/gui/tool-runner-factory/hermione/index', () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -40,10 +40,15 @@ describe('lib/gui/tool-runner-factory/hermione/index', () => {
beforeEach(() => {
reportBuilder = sinon.createStubInstance(ReportBuilder);
sandbox.stub(ReportBuilder, 'create').returns(reportBuilder);
reportBuilder.format.returns({prepareTestResult: sandbox.stub()});
reportBuilder.getResult.returns({});

ToolGuiReporter = proxyquire(`lib/gui/tool-runner-factory/hermione`, {
'./report-subscriber': sandbox.stub()
'./report-subscriber': sandbox.stub(),
'../base-tool-runner': proxyquire('lib/gui/tool-runner-factory/base-tool-runner', {
'./utils': {findTestResult: sandbox.stub()},
'../../reporter-helpers': {updateReferenceImage: sandbox.stub().resolves()}
})
});
});

Expand Down Expand Up @@ -96,4 +101,89 @@ describe('lib/gui/tool-runner-factory/hermione/index', () => {
.then(() => assert.calledOnce(reportBuilder.addIdle));
});
});

describe('updateReferenceImage', () => {
const mkHermione_ = (config) => {
const hermione = stubTool(config, {UPDATE_REFERENCE: 'updateReference'});
sandbox.stub(hermione, 'emit');

return hermione;
};

describe('should emit "UPDATE_REFERENCE" event', () => {
it('should emit "UPDATE_REFERENCE" event with state and reference data', async () => {
const getScreenshotPath = sandbox.stub().returns('/ref/path1');
const config = stubConfig({
browsers: {yabro: {getScreenshotPath}}
});

const hermione = mkHermione_(config);
const gui = initGuiReporter(hermione);

const tests = [mkTestResult({
browserId: 'yabro',
suite: {path: ['suite1']},
state: {},
imagesInfo: [mkImagesInfo({
stateName: 'plain1',
actualImg: {
size: {height: 100, width: 200}
}
})]
})];

await gui.updateReferenceImage(tests);

assert.calledOnceWith(hermione.emit, 'updateReference', {
refImg: {path: '/ref/path1', size: {height: 100, width: 200}},
state: 'plain1'
});
});

it('for each image info', async () => {
const getScreenshotPath = sandbox.stub()
.onFirstCall().returns('/ref/path1')
.onSecondCall().returns('/ref/path2');

const config = stubConfig({
browsers: {yabro: {getScreenshotPath}}
});

const hermione = mkHermione_(config);
const gui = initGuiReporter(hermione);

const tests = [mkTestResult({
browserId: 'yabro',
suite: {path: ['suite1']},
state: {},
imagesInfo: [
mkImagesInfo({
stateName: 'plain1',
actualImg: {
size: {height: 100, width: 200}
}
}),
mkImagesInfo({
stateName: 'plain2',
actualImg: {
size: {height: 200, width: 300}
}
})
]
})];

await gui.updateReferenceImage(tests);

assert.calledTwice(hermione.emit);
assert.calledWith(hermione.emit.firstCall, 'updateReference', {
refImg: {path: '/ref/path1', size: {height: 100, width: 200}},
state: 'plain1'
});
assert.calledWith(hermione.emit.secondCall, 'updateReference', {
refImg: {path: '/ref/path2', size: {height: 200, width: 300}},
state: 'plain2'
});
});
});
});
});
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function stubConfig(config = {}) {
forBrowser: sinon.stub().named('forBrowser').callsFake((bro) => _.defaults(browsers[bro], config))
};

return Object.assign(_.omit(config, 'browsers'), browserConfigs);
return Object.assign(config, browserConfigs);
}

function stubTool(config = stubConfig(), events = {}, errors = {}) {
Expand Down

0 comments on commit 6f95fda

Please sign in to comment.