diff --git a/lib/state-processor/capture-processor/capture-processor.js b/lib/state-processor/capture-processor/capture-processor.js index a683294b0..fee0c150b 100644 --- a/lib/state-processor/capture-processor/capture-processor.js +++ b/lib/state-processor/capture-processor/capture-processor.js @@ -1,7 +1,6 @@ 'use strict'; const _ = require('lodash'); -const fs = require('fs-extra'); const utils = require('./utils'); const {temp, Image} = require('gemini-core'); @@ -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); @@ -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); diff --git a/package-lock.json b/package-lock.json index 6c2909362..92b9d15c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,9 +84,9 @@ "integrity": "sha512-OtUw6JUTgxA2QoqqmrmQ7F2NYqiBPi/L2jqHyFtllhOUvXYQXf0Z1CYUinIfyT4bTCGmrA7gX9FvHA81uzCoVw==" }, "ajv": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.2.tgz", - "integrity": "sha512-FBHEW6Jf5TB9MGBgUUA9XHkTbjXYfAUjY43ACMfmdMRHniyoMHjHjzD50OK8LGDWQwp4rWEsIq5kEqq7rvIM1g==", + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.7.0.tgz", + "integrity": "sha512-RZXPviBTtfmtka9n9sy1N5M5b82CbxWIR6HIis4s3WQTXDJamc/0gpCWNGz6EWdWp4DOfjzJfhz/AS9zVPjjWg==", "requires": { "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", @@ -1809,9 +1809,9 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, "core-js": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.2.tgz", - "integrity": "sha512-NdBPF/RVwPW6jr0NCILuyN9RiqLo2b1mddWHkUL+VnvcB7dzlnBJ1bXYntjpTGOgkZiiLWj2JxmOr7eGE3qK6g==", + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.3.tgz", + "integrity": "sha512-l00tmFFZOBHtYhN4Cz7k32VM7vTn3rE2ANjQDxdEN6zmXZ/xq1jQuutnmHvMG1ZJ7xd72+TA5YpUK8wz3rWsfQ==", "dev": true }, "core-util-is": { @@ -2416,9 +2416,9 @@ } }, "es5-ext": { - "version": "0.10.46", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.46.tgz", - "integrity": "sha512-24XxRvJXNFwEMpJb3nOkiRJKRoupmjYmOPVlI65Qy2SrtxwOTB+g6ODjBKOtwEHbYrhWRty9xxOWLNdClT2djw==", + "version": "0.10.47", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.47.tgz", + "integrity": "sha512-/1TItLfj+TTfWoeRcDn/0FbGV6SNo4R+On2GGVucPU/j3BWnXE2Co8h8CTo4Tu34gFJtnmwS9xiScKs4EjZhdw==", "dev": true, "requires": { "es6-iterator": "~2.0.3", @@ -3125,9 +3125,9 @@ } }, "gemini-core": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/gemini-core/-/gemini-core-3.1.2.tgz", - "integrity": "sha512-yxTSQxz2Thbmg5BVsPSjBQAReq+p1fnW+3PgGq5rjV9p8DaGjhHIzA+V8cDpayawICFsrsQSvt/BNuxWRMJC/w==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/gemini-core/-/gemini-core-3.2.0.tgz", + "integrity": "sha512-kOgO4ekoVzUR7DXkfH0m0JW1o+tgXBmM4zBPX2Azj0Y/1kzsfEvmGqrBkElkcz/Z+O7J31gd1uAlNHK/ijb6QA==", "requires": { "aliasify": "^1.9.0", "bluebird": "^3.4.6", @@ -3136,7 +3136,7 @@ "gemini-configparser": "^1.0.0", "glob-extra": "^4.0.0", "lodash": "^4.15.0", - "looks-same": "^5.0.2", + "looks-same": "^5.1.0", "micromatch": "^2.3.11", "png-img": "^2.1.1", "sizzle": "^2.3.3", @@ -4617,9 +4617,9 @@ "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=" }, "looks-same": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/looks-same/-/looks-same-5.0.2.tgz", - "integrity": "sha512-wRt5m6awYk28HELfFN28H5K71g3D3b92jDZFVIDYGeP74OkIxFMov+uYNdeC9Wi7O6yjP35Q8+GWSvDQ03u06w==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/looks-same/-/looks-same-5.1.0.tgz", + "integrity": "sha512-a/BdaF+Q7mqpJZ5Xz1VM9Nb+LnDu8l1A+2ZKEoaqmb9B+nlap1dKeUG8YeVUkQh4pnqsAs6mcSDUp35wkvxozw==", "requires": { "color-diff": "^1.1.0", "concat-stream": "^1.6.2", @@ -4677,9 +4677,9 @@ } }, "math-random": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.1.tgz", - "integrity": "sha1-izqsWIuKZuSXXjzepn97sylgH6w=" + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz", + "integrity": "sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==" }, "md5.js": { "version": "1.3.5", @@ -9902,15 +9902,16 @@ } }, "parse-asn1": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz", - "integrity": "sha512-KPx7flKXg775zZpnp9SxJlz00gTd4BmJ2yJufSc44gMCRrRQ7NSzAcSJQfifuOLgW6bEi+ftrALtsgALeB2Adw==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.3.tgz", + "integrity": "sha512-VrPoetlz7B/FqjBLD2f5wBVZvsZVLnRUrxVLfRYhGXCODa/NWE4p3Wp+6+aV3ZPL3KM7/OZmxDIwwijD7yuucg==", "requires": { "asn1.js": "^4.0.0", "browserify-aes": "^1.0.0", "create-hash": "^1.1.0", "evp_bytestokey": "^1.0.0", - "pbkdf2": "^3.0.3" + "pbkdf2": "^3.0.3", + "safe-buffer": "^5.1.1" } }, "parse-color": { @@ -10453,9 +10454,9 @@ } }, "resolve": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz", - "integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", + "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", "requires": { "path-parse": "^1.0.6" } @@ -10888,9 +10889,9 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "sshpk": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.0.tgz", - "integrity": "sha512-Zhev35/y7hRMcID/upReIvRse+I9SVhyVre/KTJSJQWMz3C3+G+HpO7m1wK/yckEtujKZ7dS4hkVxAnmHaIGVQ==", + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -11082,9 +11083,9 @@ } }, "stream-browserify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", - "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz", + "integrity": "sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg==", "requires": { "inherits": "~2.0.1", "readable-stream": "^2.0.2" diff --git a/package.json b/package.json index 3f0c7d2d2..79e6bacf6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/state-processor/capture-processor/capture-processor.js b/test/unit/state-processor/capture-processor/capture-processor.js index e92e95486..a5946d8c4 100644 --- a/test/unit/state-processor/capture-processor/capture-processor.js +++ b/test/unit/state-processor/capture-processor/capture-processor.js @@ -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, { @@ -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}) @@ -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 }); }); @@ -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); @@ -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}},