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

Commit 3a1a3f3

Browse files
committed
feat: use ref image from looks-same
1 parent ec5efcf commit 3a1a3f3

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

lib/state-processor/capture-processor/capture-processor.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

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

@@ -35,11 +34,6 @@ module.exports = class CaptureProcessor {
3534

3635
return utils.existsRef(refImg.path)
3736
.then((isRefExists) => {
38-
if (isRefExists) {
39-
const refImgBuff = fs.readFileSync(refImg.path);
40-
refImg.size = Image.create(refImgBuff).getSize();
41-
}
42-
4337
return isRefExists
4438
? this._onRefHandler(refImg) || this._compareImages(capture, opts)
4539
: this._onNoRefHandler(refImg, capture);
@@ -59,7 +53,9 @@ module.exports = class CaptureProcessor {
5953

6054
return capture.image.save(currImg.path)
6155
.then(() => Image.compare(currImg.path, refImg.path, imageCompareOpts))
62-
.then(({equal, diffBounds}) => {
56+
.then(({equal, diffBounds, metaInfo = {}}) => {
57+
Object.assign(refImg, metaInfo.refImg);
58+
6359
return equal
6460
? this._onEqualHandler(refImg, currImg)
6561
: this._onDiffHandler(refImg, currImg, diffBounds);

package-lock.json

Lines changed: 33 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"debug": "^2.2.0",
1818
"fs-extra": "^0.30.0",
1919
"gemini-configparser": "^1.0.0",
20-
"gemini-core": "^3.1.2",
20+
"gemini-core": "3.2.0",
2121
"gemini-coverage": "^2.0.0",
2222
"graceful-fs": "^4.1.11",
2323
"handlebars": "^4.0.5",

test/unit/state-processor/capture-processor/capture-processor.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ describe('state-processor/capture-processor/capture-processor', () => {
151151
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');
152152
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');
153153

154-
const refImage = mkImage({size: {width: 100, height: 200}});
155-
Image.create.withArgs('ref-buffer-data').returns(refImage);
156-
157154
const currImage = mkImage({size: {width: 100, height: 200}});
158-
Image.compare.resolves({equal: true});
155+
Image.compare.resolves({equal: true, metaInfo: {refImg: {size: {width: 100, height: 200}}}});
159156
return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
160157
.then((result) => {
161158
assert.deepEqual(result, {
@@ -167,13 +164,14 @@ describe('state-processor/capture-processor/capture-processor', () => {
167164
});
168165

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

174-
const refImage = mkImage({size: {width: 100, height: 200}});
175-
Image.create.withArgs('ref-buffer-data').returns(refImage);
176-
177175
const currImage = mkImage({size: {width: 300, height: 400}});
178176

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

206-
return exec_({refImg: {path: '/existent/path', size: null}})
204+
return exec_({refImg: {path: '/existent/path'}})
207205
.then((res) => {
208206
assert.notCalled(utils.saveRef);
209207
assert.deepEqual(res, {
210-
refImg: {path: '/existent/path', size: {width: 100, height: 200}},
208+
refImg: {path: '/existent/path'},
211209
updated: false
212210
});
213211
});
@@ -289,9 +287,7 @@ describe('state-processor/capture-processor/capture-processor', () => {
289287
it('should not update a reference image if images are the same', () => {
290288
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');
291289

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

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

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

341-
return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
336+
return exec_({refImg: {path: '/ref/path'}}, {image: currImage})
342337
.then((res) => {
343338
assert.deepEqual(res, {
344339
refImg: {path: '/ref/path', size: {width: 100, height: 200}},

0 commit comments

Comments
 (0)