Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: use ref image from looks-same
Browse files Browse the repository at this point in the history
  • Loading branch information
rostik404 committed Jan 24, 2019
1 parent ec5efcf commit 3a1a3f3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 56 deletions.
10 changes: 3 additions & 7 deletions lib/state-processor/capture-processor/capture-processor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const _ = require('lodash');
const fs = require('fs-extra');
const utils = require('./utils');
const {temp, Image} = require('gemini-core');

Expand Down Expand Up @@ -35,11 +34,6 @@ module.exports = class CaptureProcessor {

return utils.existsRef(refImg.path)
.then((isRefExists) => {
if (isRefExists) {
const refImgBuff = fs.readFileSync(refImg.path);
refImg.size = Image.create(refImgBuff).getSize();
}

return isRefExists
? this._onRefHandler(refImg) || this._compareImages(capture, opts)
: this._onNoRefHandler(refImg, capture);
Expand All @@ -59,7 +53,9 @@ module.exports = class CaptureProcessor {

return capture.image.save(currImg.path)
.then(() => Image.compare(currImg.path, refImg.path, imageCompareOpts))
.then(({equal, diffBounds}) => {
.then(({equal, diffBounds, metaInfo = {}}) => {
Object.assign(refImg, metaInfo.refImg);

return equal
? this._onEqualHandler(refImg, currImg)
: this._onDiffHandler(refImg, currImg, diffBounds);
Expand Down
65 changes: 33 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"debug": "^2.2.0",
"fs-extra": "^0.30.0",
"gemini-configparser": "^1.0.0",
"gemini-core": "^3.1.2",
"gemini-core": "3.2.0",
"gemini-coverage": "^2.0.0",
"graceful-fs": "^4.1.11",
"handlebars": "^4.0.5",
Expand Down
27 changes: 11 additions & 16 deletions test/unit/state-processor/capture-processor/capture-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,8 @@ describe('state-processor/capture-processor/capture-processor', () => {
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');

const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('ref-buffer-data').returns(refImage);

const currImage = mkImage({size: {width: 100, height: 200}});
Image.compare.resolves({equal: true});
Image.compare.resolves({equal: true, metaInfo: {refImg: {size: {width: 100, height: 200}}}});
return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
.then((result) => {
assert.deepEqual(result, {
Expand All @@ -167,13 +164,14 @@ describe('state-processor/capture-processor/capture-processor', () => {
});

it('different', () => {
Image.compare.resolves({equal: false, diffBounds: {left: 0, top: 0, right: 10, bottom: 10}});
Image.compare.resolves({
equal: false,
diffBounds: {left: 0, top: 0, right: 10, bottom: 10},
metaInfo: {refImg: {size: {width: 100, height: 200}}}
});
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');

const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('ref-buffer-data').returns(refImage);

const currImage = mkImage({size: {width: 300, height: 400}});

return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
Expand Down Expand Up @@ -203,11 +201,11 @@ describe('state-processor/capture-processor/capture-processor', () => {
const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('existent-buffer-data').returns(refImage);

return exec_({refImg: {path: '/existent/path', size: null}})
return exec_({refImg: {path: '/existent/path'}})
.then((res) => {
assert.notCalled(utils.saveRef);
assert.deepEqual(res, {
refImg: {path: '/existent/path', size: {width: 100, height: 200}},
refImg: {path: '/existent/path'},
updated: false
});
});
Expand Down Expand Up @@ -289,9 +287,7 @@ describe('state-processor/capture-processor/capture-processor', () => {
it('should not update a reference image if images are the same', () => {
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');

const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('ref-buffer-data').returns(refImage);
Image.compare.resolves({equal: true});
Image.compare.resolves({equal: true, metaInfo: {refImg: {size: {width: 100, height: 200}}}});
return exec_({refImg: {path: '/ref/path', size: null}})
.then((res) => {
assert.notCalled(utils.copyImg);
Expand Down Expand Up @@ -333,12 +329,11 @@ describe('state-processor/capture-processor/capture-processor', () => {
utils.copyImg.resolves(false);

fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');
const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('ref-buffer-data').returns(refImage);

Image.compare.resolves({metaInfo: {refImg: {size: {width: 100, height: 200}}}});
const currImage = mkImage({size: {width: 300, height: 400}});

return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
return exec_({refImg: {path: '/ref/path'}}, {image: currImage})
.then((res) => {
assert.deepEqual(res, {
refImg: {path: '/ref/path', size: {width: 100, height: 200}},
Expand Down

0 comments on commit 3a1a3f3

Please sign in to comment.