Skip to content

Commit

Permalink
Merge pull request #471 from gemini-testing/HERMIONE-968.fix_reuse_re…
Browse files Browse the repository at this point in the history
…ferences

fix: do not reuse reference images from another browser
  • Loading branch information
DudaGod authored Apr 12, 2023
2 parents 06f78d2 + cb0467e commit bf67869
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ module.exports = class TestAdapter {
}

_getExpectedKey(stateName) {
const {id, browserId} = this._testResult;
// TODO: remove toString after publish major version
return this._testResult.id.toString() + '#' + stateName;
return [id.toString(), browserId, stateName].join('/');
}

_getExpectedPath(stateName, status) {
Expand Down
33 changes: 24 additions & 9 deletions test/unit/lib/test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,27 @@ describe('hermione test adapter', () => {
});

describe('expected path', () => {
let lastImageInfo;

beforeEach(() => {
lastImageInfo = [{
const mkLastImageInfo_ = (opts = {}) => {
const {stateName, expectedImgPath} = _.defaults(opts, {
stateName: 'plain',
expectedImgPath: 'default/expected/img/path.png'
});

return [{
stateName,
expectedImg: {
path: 'expectedImgPath'
path: expectedImgPath
}
}];
});
};

it('should be pulled from the database if exists', async () => {
sqliteAdapter.query.withArgs({
select: 'imagesInfo',
where: 'suitePath = ? AND name = ?',
orderBy: 'timestamp',
orderDescending: true
}).returns({imagesInfo: JSON.stringify(lastImageInfo)});
}).returns({imagesInfo: JSON.stringify(mkLastImageInfo_())});

const testResult = mkTestResult_({
fullTitle: () => 'some-title',
Expand Down Expand Up @@ -651,7 +654,7 @@ describe('hermione test adapter', () => {
});

it('should be generated on update', async () => {
sqliteAdapter.query.returns({imagesInfo: JSON.stringify(lastImageInfo)});
sqliteAdapter.query.returns({imagesInfo: JSON.stringify(mkLastImageInfo_())});
const testResult = mkTestResult_({
fullTitle: () => 'some-title',
assertViewResults: [mkErrStub()],
Expand All @@ -664,8 +667,20 @@ describe('hermione test adapter', () => {
assert.calledOnce(utils.getReferencePath);
});

it('should be queried from the database for each browser', async () => {
const chromeTestResult = mkTestResult_({browserId: 'chrome'});
const firefoxTestResult = mkTestResult_({browserId: 'firefox'});

mkHermioneTestResultAdapter(chromeTestResult, {status: FAIL}).getImagesFor(FAIL, 'plain');
mkHermioneTestResultAdapter(firefoxTestResult, {status: FAIL}).getImagesFor(FAIL, 'plain');

assert.calledTwice(sqliteAdapter.query);
assert.calledWith(sqliteAdapter.query.firstCall, sinon.match.any, sinon.match.any, 'chrome');
assert.calledWith(sqliteAdapter.query.secondCall, sinon.match.any, sinon.match.any, 'firefox');
});

it('should be queried from the database once per state', async () => {
sqliteAdapter.query.returns({imagesInfo: JSON.stringify(lastImageInfo)});
sqliteAdapter.query.returns({imagesInfo: JSON.stringify(mkLastImageInfo_())});
const testResult = mkTestResult_({
fullTitle: () => 'some-title',
assertViewResults: [mkErrStub()],
Expand Down

0 comments on commit bf67869

Please sign in to comment.