From fc87b21b6813ade6beb5632bea370d9b09409e1e Mon Sep 17 00:00:00 2001 From: DudaGod Date: Wed, 10 Jan 2018 19:40:46 +0300 Subject: [PATCH] feat(calibrator): move to gemini-core --- lib/browser-pool.js | 3 +- lib/browser/camera.js | 10 +- .../client-scripts/gemini.calibrate.js | 63 ---- lib/calibrator.js | 140 --------- package-lock.json | 274 +++++++++++------- package.json | 7 +- test/browser/calibrator.test.js | 5 +- .../data/image/calibrate-broken.png | Bin 313 -> 0 bytes test/functional/data/image/calibrate.png | Bin 279 -> 0 bytes test/unit/browser-pool.js | 3 +- test/unit/browser/new-browser.js | 2 +- test/unit/calibrator.test.js | 70 ----- 12 files changed, 181 insertions(+), 396 deletions(-) delete mode 100644 lib/browser/client-scripts/gemini.calibrate.js delete mode 100644 lib/calibrator.js delete mode 100644 test/functional/data/image/calibrate-broken.png delete mode 100644 test/functional/data/image/calibrate.png delete mode 100644 test/unit/calibrator.test.js diff --git a/lib/browser-pool.js b/lib/browser-pool.js index 4de3d8201..5481d8d5d 100644 --- a/lib/browser-pool.js +++ b/lib/browser-pool.js @@ -1,7 +1,6 @@ 'use strict'; -const BrowserPool = require('gemini-core').BrowserPool; -const Calibrator = require('./calibrator'); +const {BrowserPool, Calibrator} = require('gemini-core'); const Browser = require('./browser'); const Events = require('./constants/events'); diff --git a/lib/browser/camera.js b/lib/browser/camera.js index 435c32f01..6563f71fa 100644 --- a/lib/browser/camera.js +++ b/lib/browser/camera.js @@ -63,12 +63,10 @@ module.exports = class Camera { return image; } - return image.crop({ - left: this._calibration.left, - top: this._calibration.top, - width: image.getSize().width - this._calibration.left, - height: image.getSize().height - this._calibration.top - }); + const {left, top} = this._calibration; + const {width, height} = image.getSize(); + + return image.crop({left, top, width: width - left, height: height - top}); } _cropToViewport(image, page) { diff --git a/lib/browser/client-scripts/gemini.calibrate.js b/lib/browser/client-scripts/gemini.calibrate.js deleted file mode 100644 index bf0e4f94c..000000000 --- a/lib/browser/client-scripts/gemini.calibrate.js +++ /dev/null @@ -1,63 +0,0 @@ -(function(window) { - 'use strict'; - - // HACK: ie8 does not need to reset the body border, - // while any other browser does. - // This hack is obsolete in standards mode, but - // calibration script is executed on about:blank - // which is in quirks mode. - // Needs to find a proper way to open calibration - // page in standards mode. - function needsResetBorder() { - return !/MSIE 8\.0/.test(navigator.userAgent); - } - - function resetZoom() { - var meta = document.createElement('meta'); - meta.name = 'viewport'; - meta.content = 'width=device-width,initial-scale=1.0,user-scalable=no'; - document.getElementsByTagName('head')[0].appendChild(meta); - } - - function createPattern() { - var bodyStyle = document.body.style; - bodyStyle.margin = 0; - bodyStyle.padding = 0; - - if (needsResetBorder()) { - bodyStyle.border = 0; - } - - bodyStyle.backgroundColor = '#96fa00'; - } - - function hasCSS3Selectors() { - try { - document.querySelector('body:nth-child(1)'); - } catch (e) { - return false; - } - return true; - } - - function needsCompatLib() { - return !hasCSS3Selectors() || - !window.getComputedStyle || - !window.matchMedia || - !String.prototype.trim; - } - - function getBrowserFeatures() { - var features = { - needsCompatLib: needsCompatLib(), - pixelRatio: window.devicePixelRatio, - innerWidth: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth - }; - - return features; - } - - resetZoom(); - createPattern(); - return getBrowserFeatures(); -}(window)); diff --git a/lib/calibrator.js b/lib/calibrator.js deleted file mode 100644 index 109e7731d..000000000 --- a/lib/calibrator.js +++ /dev/null @@ -1,140 +0,0 @@ -'use strict'; -var Promise = require('bluebird'), - fs = require('fs'), - path = require('path'), - _ = require('lodash'), - - GeminiError = require('./errors/gemini-error'), - looksSame = require('looks-same'), - clientScriptCalibrate = fs.readFileSync(path.join(__dirname, 'browser', 'client-scripts', 'gemini.calibrate.min.js'), 'utf8'), - DIRECTION = {FORWARD: 'forward', REVERSE: 'reverse'}; - -/** - * @constructor - */ -function Calibrator() { - this._cache = {}; -} - -/** - * @param {Browser} browser - * @returns {Promise.} - */ -Calibrator.prototype.calibrate = function(browser) { - var _this = this; - if (this._cache[browser.id]) { - return Promise.resolve(this._cache[browser.id]); - } - return browser.open('about:blank', {resetZoom: false}) - .then(function() { - return browser.evalScript(clientScriptCalibrate); - }) - .then(function(features) { - return [features, browser.captureViewportImage()]; - }) - .spread(function(features, image) { - var innerWidth = features.innerWidth, - hasPixelRatio = !!(features.pixelRatio && features.pixelRatio > 1.0), - imageFeatures = _this._analyzeImage(image, {calculateColorLength: hasPixelRatio}); - - if (!imageFeatures) { - return Promise.reject(new GeminiError( - 'Could not calibrate. This could be due to calibration page has failed to open properly' - )); - } - - _.extend(features, { - top: imageFeatures.viewportStart.y, - left: imageFeatures.viewportStart.x, - usePixelRatio: hasPixelRatio && imageFeatures.colorLength > innerWidth - }); - - _this._cache[browser.id] = features; - return features; - }); -}; - -Calibrator.prototype._analyzeImage = function(image, params) { - var imageHeight = image.getSize().height; - - for (var y = 0; y < imageHeight; y++) { - var result = analyzeRow(y, image, params); - - if (result) { - return result; - } - } - - return null; -}; - -function analyzeRow(row, image, params) { - params = params || {}; - - var markerStart = findMarkerInRow(row, image, DIRECTION.FORWARD); - - if (markerStart === -1) { - return null; - } - - if (!params.calculateColorLength) { - return {viewportStart: {x: markerStart, y: row}}; - } - - var markerEnd = findMarkerInRow(row, image, DIRECTION.REVERSE), - colorLength = markerEnd - markerStart + 1; - - return {viewportStart: {x: markerStart, y: row}, colorLength: colorLength}; -} - -function findMarkerInRow(row, image, searchDirection) { - var imageWidth = image.getSize().width, - searchColor = {R: 148, G: 250, B: 0}; - - if (searchDirection === DIRECTION.REVERSE) { - return searchReverse_(); - } else { - return searchForward_(); - } - - function searchForward_() { - for (var x = 0; x < imageWidth; x++) { - if (compare_(x)) { - return x; - } - } - return -1; - } - - function searchReverse_() { - for (var x = imageWidth - 1; x >= 0; x--) { - if (compare_(x)) { - return x; - } - } - return -1; - } - - function compare_(x) { - var color = pickRGB(image.getRGBA(x, row)); - return looksSame.colors(color, searchColor); - } -} - -function pickRGB(rgba) { - return { - R: rgba.r, - G: rgba.g, - B: rgba.b - }; -} - -/** - * @typedef {Object} CalibrationResult - * @property {Number} top - * @property {Number} left - * @property {Number} right - * @property {Number} bottom - */ - -module.exports = Calibrator; diff --git a/package-lock.json b/package-lock.json index 9546aae19..f811994c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -275,9 +275,9 @@ "integrity": "sha1-7nQAlBMALYTOxyGcasgRgS5yMWA=" }, "assertion-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz", - "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, "astw": { @@ -451,7 +451,7 @@ "requires": { "combine-source-map": "0.7.2", "defined": "1.0.0", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "through2": "2.0.3", "umd": "3.0.1" } @@ -497,7 +497,7 @@ "https-browserify": "0.0.1", "inherits": "2.0.3", "insert-module-globals": "7.0.1", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "labeled-stream-splicer": "2.0.0", "module-deps": "4.1.1", "os-browserify": "0.1.2", @@ -564,7 +564,7 @@ "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", "requires": { "bn.js": "4.11.8", - "randombytes": "2.0.5" + "randombytes": "2.0.6" } }, "browserify-sign": { @@ -699,7 +699,7 @@ "integrity": "sha1-TQJjewZ/6Vi9v906QOxW/vc3Mkc=", "dev": true, "requires": { - "assertion-error": "1.0.2", + "assertion-error": "1.1.0", "deep-eql": "0.1.3", "type-detect": "1.0.0" } @@ -846,9 +846,9 @@ } }, "commander": { - "version": "2.12.2", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz", - "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==" + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", + "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==" }, "compare-func": { "version": "1.3.2", @@ -938,10 +938,10 @@ "integrity": "sha1-kVGmKx2O2y2CcR2r9bfPcQQfgrE=", "dev": true, "requires": { - "conventional-changelog-angular": "1.5.3", + "conventional-changelog-angular": "1.6.0", "conventional-changelog-atom": "0.1.2", "conventional-changelog-codemirror": "0.2.1", - "conventional-changelog-core": "1.9.4", + "conventional-changelog-core": "1.9.5", "conventional-changelog-ember": "0.2.10", "conventional-changelog-eslint": "0.2.1", "conventional-changelog-express": "0.2.1", @@ -951,9 +951,9 @@ }, "dependencies": { "conventional-changelog-angular": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-1.5.3.tgz", - "integrity": "sha512-J+3g7H7O9QTxBFMmdlHSLzqTdxO8lhOKGXLAcewtKPGaVVV/JnaPOokuj85mP3tghP5gXi527HWoJlD3VBlX6g==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-1.6.0.tgz", + "integrity": "sha1-CiagcfLJ/PzyuGugz79uYwG3W/o=", "dev": true, "requires": { "compare-func": "1.3.2", @@ -992,9 +992,9 @@ } }, "conventional-changelog-core": { - "version": "1.9.4", - "resolved": "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-1.9.4.tgz", - "integrity": "sha512-C8R8Bb706P10hYaGzllvH92O8Ck7xCGPB7t2Y+S1O2yf13BDvDW5BPdjyBwY2VgVNuFyNqi6qA458N+W9txpHg==", + "version": "1.9.5", + "resolved": "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-1.9.5.tgz", + "integrity": "sha1-XbdWba18DLddr0f7spdve/mSjB0=", "dev": true, "requires": { "conventional-changelog-writer": "2.0.3", @@ -1019,7 +1019,7 @@ "dev": true, "requires": { "is-text-path": "1.0.1", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "lodash": "4.17.4", "meow": "3.7.0", "split2": "2.2.0", @@ -1161,7 +1161,7 @@ "dev": true, "requires": { "is-text-path": "1.0.1", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "lodash": "4.17.4", "meow": "3.7.0", "split2": "2.2.0", @@ -1191,7 +1191,7 @@ "dev": true, "requires": { "is-text-path": "1.0.1", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "lodash": "4.17.4", "meow": "3.7.0", "split2": "2.2.0", @@ -1306,8 +1306,8 @@ "dev": true, "requires": { "chalk": "1.1.3", - "commander": "2.12.2", - "is-my-json-valid": "2.16.1", + "commander": "2.13.0", + "is-my-json-valid": "2.17.1", "pinkie-promise": "2.0.1" } }, @@ -1507,7 +1507,7 @@ "inherits": "2.0.3", "pbkdf2": "3.0.14", "public-encrypt": "4.0.0", - "randombytes": "2.0.5", + "randombytes": "2.0.6", "randomfill": "1.0.3" } }, @@ -1676,7 +1676,7 @@ "resolved": "https://registry.npmjs.org/deps-sort/-/deps-sort-2.0.0.tgz", "integrity": "sha1-CRckkC6EZYJg65EHSMzNGvbiH7U=", "requires": { - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "shasum": "1.0.2", "subarg": "1.0.0", "through2": "2.0.3" @@ -1692,18 +1692,18 @@ } }, "detective": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/detective/-/detective-4.7.0.tgz", - "integrity": "sha512-4mBqSEdMfBpRAo/DQZnTcAXenpiSIJmVKbCMSotS+SFWWcrP/CKM6iBRPdTiEO+wZhlfEsoZlGqpG6ycl5vTqw==", + "version": "4.7.1", + "resolved": "https://registry.npmjs.org/detective/-/detective-4.7.1.tgz", + "integrity": "sha512-H6PmeeUcZloWtdt4DAkFyzFL94arpHr3NOwwmVILFiy+9Qd4JTxxXrzfyGk/lmct2qVGBwTSwSXagqu2BxmWig==", "requires": { - "acorn": "5.2.1", + "acorn": "5.3.0", "defined": "1.0.0" }, "dependencies": { "acorn": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", - "integrity": "sha512-jG0u7c4Ly+3QkkW18V+NRDN+4bWHdln30NL1ZL2AvFZZmQe/BfopYCtghCKKVBUSetZ4QKcyA0pY6/4Gw8Pv8w==" + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.3.0.tgz", + "integrity": "sha512-Yej+zOJ1Dm/IMZzzj78OntP/r3zHEaKcyNoU2lAaxPtrseM6rF0xwqoz5Q5ysAiED9hTjI2hgtvLXitlCN1/Ug==" } } }, @@ -1720,13 +1720,13 @@ "requires": { "bn.js": "4.11.8", "miller-rabin": "4.0.1", - "randombytes": "2.0.5" + "randombytes": "2.0.6" } }, "doctrine": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.0.2.tgz", - "integrity": "sha512-y0tm5Pq6ywp3qSTZ1vPgVdAnbDEoeoc5wlOHXoY1c4Wug/a7JvqHIl7BTvwodaHmejWkK/9dSb3sCYfyo/om8A==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", "dev": true, "requires": { "esutils": "2.0.2" @@ -1746,6 +1746,27 @@ "is-obj": "1.0.1" } }, + "dotgitignore": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/dotgitignore/-/dotgitignore-1.0.3.tgz", + "integrity": "sha512-eu5XjSstm0WXQsARgo6kPjkINYZlOUW+z/KtAAIBjHa5mUpMPrxJytbPIndWz6GubBuuuH5ljtVcXKnVnH5q8w==", + "dev": true, + "requires": { + "find-up": "2.1.0", + "minimatch": "3.0.4" + }, + "dependencies": { + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", + "dev": true, + "requires": { + "locate-path": "2.0.0" + } + } + } + }, "duplexer2": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", @@ -1787,17 +1808,17 @@ } }, "end-of-stream": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz", - "integrity": "sha1-epDYM+/abPpurA9JSduw+tOmMgY=", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", + "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", "requires": { "once": "1.4.0" } }, "errno": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.5.tgz", - "integrity": "sha512-tv2H+e3KBnMmNRuoVG24uorOj3XfYo+/nJJd07PUISRr0kaMKQKL5kyD+6ANXk1ZIIsvbORsjvHnCfC4KIc7uQ==", + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.6.tgz", + "integrity": "sha512-IsORQDpaaSwcDP4ZZnHxgE85werpo34VYn1Ud3mq+eUsF593faR8oCZNXrROVkpFu2TsbrNhHin0aUrTsQ9vNw==", "requires": { "prr": "1.0.1" } @@ -1951,7 +1972,7 @@ "chalk": "1.1.3", "concat-stream": "1.5.2", "debug": "2.6.9", - "doctrine": "2.0.2", + "doctrine": "2.1.0", "escope": "3.6.0", "espree": "3.5.2", "esquery": "1.0.0", @@ -1963,8 +1984,8 @@ "ignore": "3.3.7", "imurmurhash": "0.1.4", "inquirer": "0.12.0", - "is-my-json-valid": "2.16.1", - "is-resolvable": "1.0.0", + "is-my-json-valid": "2.17.1", + "is-resolvable": "1.0.1", "js-yaml": "3.10.0", "json-stable-stringify": "1.0.1", "levn": "0.3.0", @@ -2013,14 +2034,14 @@ "integrity": "sha512-sadKeYwaR/aJ3stC2CdvgXu1T16TdYN+qwCpcWbMnGJ8s0zNWemzrvb2GbD4OhmJ/fwpJjudThAlLobGbWZbCQ==", "dev": true, "requires": { - "acorn": "5.2.1", + "acorn": "5.3.0", "acorn-jsx": "3.0.1" }, "dependencies": { "acorn": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.2.1.tgz", - "integrity": "sha512-jG0u7c4Ly+3QkkW18V+NRDN+4bWHdln30NL1ZL2AvFZZmQe/BfopYCtghCKKVBUSetZ4QKcyA0pY6/4Gw8Pv8w==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.3.0.tgz", + "integrity": "sha512-Yej+zOJ1Dm/IMZzzj78OntP/r3zHEaKcyNoU2lAaxPtrseM6rF0xwqoz5Q5ysAiED9hTjI2hgtvLXitlCN1/Ug==", "dev": true } } @@ -2325,16 +2346,16 @@ } }, "gemini-core": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/gemini-core/-/gemini-core-2.2.1.tgz", - "integrity": "sha512-pdZUAvA6B0KMNm65T+mOWPsVk7qlXlcL8eMVnEBlzVSeRfA2uN4HmqAtDclMzWpclJCImv6CoSHLMtvSPWkj1w==", + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/gemini-core/-/gemini-core-2.3.1.tgz", + "integrity": "sha512-yzmd4u73sx/37qc0yzWKTi6nYXlHwAM+6U8h+47LtpO5k4w9+IbDkOBLK4EdGmOCcgiQ0aCLioTGUflaS28bSg==", "requires": { "bluebird": "3.5.1", "debug": "2.6.9", "gemini-configparser": "1.0.0", "glob-extra": "2.0.0", "lodash": "4.17.4", - "looks-same": "3.2.1", + "looks-same": "3.3.0", "micromatch": "2.3.11", "png-img": "2.1.1", "temp": "0.8.3" @@ -2686,6 +2707,25 @@ "requires": { "amdefine": "1.0.1" } + }, + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "optional": true, + "requires": { + "source-map": "0.5.7", + "uglify-to-browserify": "1.0.2", + "yargs": "3.10.0" + }, + "dependencies": { + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "optional": true + } + } } } }, @@ -2696,8 +2736,8 @@ "requires": { "bluebird": "2.11.0", "chalk": "1.1.3", - "commander": "2.12.2", - "is-my-json-valid": "2.16.1" + "commander": "2.13.0", + "is-my-json-valid": "2.17.1" }, "dependencies": { "bluebird": { @@ -2804,7 +2844,7 @@ "integrity": "sha1-KM0dwWv/3KHU2TWSgU5fPDJ7OO4=", "dev": true, "requires": { - "is-ci": "1.0.10", + "is-ci": "1.1.0", "normalize-path": "1.0.0" }, "dependencies": { @@ -2914,7 +2954,7 @@ "combine-source-map": "0.7.2", "concat-stream": "1.5.2", "is-buffer": "1.1.6", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "lexical-scope": "1.2.0", "process": "0.11.10", "through2": "2.0.3", @@ -2954,9 +2994,9 @@ } }, "is-ci": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", - "integrity": "sha1-9zkzayYyNlBhqdSCcM1WrjNpMY4=", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.1.0.tgz", + "integrity": "sha512-c7TnwxLePuqIlxHgr7xtxzycJPegNHFuIrBkwbf8hc58//+Op1CqFkyS+xnIMkwn9UsJIwc174BIjkyBmSpjKg==", "dev": true, "requires": { "ci-info": "1.1.2" @@ -3012,9 +3052,9 @@ } }, "is-my-json-valid": { - "version": "2.16.1", - "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.16.1.tgz", - "integrity": "sha512-ochPsqWS1WXj8ZnMIV0vnNXooaMhp7cyL4FMSIPKTtnV0Ha/T19G2b9kkhcNsabV9bxYkze7/aLZJb/bYuFduQ==", + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/is-my-json-valid/-/is-my-json-valid-2.17.1.tgz", + "integrity": "sha512-Q2khNw+oBlWuaYvEEHtKSw/pCxD2L5Rc1C+UQme9X6JdRDh7m5D7HkozA0qa3DUkQ6VzCnEm8mVIQPyIRkI5sQ==", "requires": { "generate-function": "2.0.0", "generate-object-property": "1.2.0", @@ -3082,13 +3122,10 @@ "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=" }, "is-resolvable": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.0.0.tgz", - "integrity": "sha1-jfV8YeouPFAUCNEA+wE8+NbgzGI=", - "dev": true, - "requires": { - "tryit": "1.0.3" - } + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.0.1.tgz", + "integrity": "sha512-y5CXYbzvB3jTnWAZH1Nl7ykUWb6T3BcTs56HUruwBf8MhF56n1HWqhDWnVFo8GHrUPDgvUUNVhrc2U8W7iqz5g==", + "dev": true }, "is-stream": { "version": "1.1.0", @@ -3318,9 +3355,9 @@ "integrity": "sha1-T9kss04OnbPInIYi7PUfm5eMbLk=" }, "JSONStream": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.1.tgz", - "integrity": "sha1-cH92HgHa6eFvG8+TcDt4xwlmV5o=", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz", + "integrity": "sha1-wQI3G27Dp887hHygDCC7D85Mbeo=", "requires": { "jsonparse": "1.3.1", "through": "2.3.8" @@ -3515,9 +3552,9 @@ "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=" }, "looks-same": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/looks-same/-/looks-same-3.2.1.tgz", - "integrity": "sha1-tjJQyUZ3F5hwkHkTv5JACYnnRrI=", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/looks-same/-/looks-same-3.3.0.tgz", + "integrity": "sha512-EfiQf32HIiNCDoyG8SXgeg1AW/T8G1q0xo8JyKp0TbgjDbNPF+cUi1xmTSYi2+73JwV+lsEuGgsh1ZZSpV9aYA==", "requires": { "color-diff": "0.1.7", "concat-stream": "1.5.2", @@ -3792,10 +3829,10 @@ "cached-path-relative": "1.0.1", "concat-stream": "1.5.2", "defined": "1.0.0", - "detective": "4.7.0", + "detective": "4.7.1", "duplexer2": "0.1.4", "inherits": "2.0.3", - "JSONStream": "1.3.1", + "JSONStream": "1.3.2", "parents": "1.0.1", "readable-stream": "2.3.3", "resolve": "1.5.0", @@ -8605,10 +8642,13 @@ "dev": true }, "p-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.1.0.tgz", - "integrity": "sha1-sH/y2aXYi+yAYDWJWiurZqJ5iLw=", - "dev": true + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.2.0.tgz", + "integrity": "sha512-Y/OtIaXtUPr4/YpMv1pCL5L5ed0rumAaAeBSj12F+bSlMdys7i8oQF/GUJmfpTS/QoaRrS/k6pma29haJpsMng==", + "dev": true, + "requires": { + "p-try": "1.0.0" + } }, "p-locate": { "version": "2.0.0", @@ -8616,9 +8656,15 @@ "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", "dev": true, "requires": { - "p-limit": "1.1.0" + "p-limit": "1.2.0" } }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", + "dev": true + }, "pako": { "version": "0.2.9", "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz", @@ -8944,7 +8990,7 @@ "browserify-rsa": "4.0.1", "create-hash": "1.1.3", "parse-asn1": "5.1.0", - "randombytes": "2.0.5" + "randombytes": "2.0.6" } }, "punycode": { @@ -9035,9 +9081,9 @@ } }, "randombytes": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.5.tgz", - "integrity": "sha512-8T7Zn1AhMsQ/HI1SjcCfT/t4ii3eAqco3yOcSzS4mozsOz69lHLsoMXmF9nZgnFanYscnSlUSgs8uZyKzpE6kg==", + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", + "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", "requires": { "safe-buffer": "5.1.1" } @@ -9047,7 +9093,7 @@ "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.3.tgz", "integrity": "sha512-YL6GrhrWoic0Eq8rXVbMptH7dAxCs0J+mh5Y0euNekPPYaxEmdVGim6GdoxoRzKW2yJoU8tueifS7mYxvcFDEQ==", "requires": { - "randombytes": "2.0.5", + "randombytes": "2.0.6", "safe-buffer": "5.1.1" } }, @@ -9552,14 +9598,15 @@ } }, "standard-version": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-4.2.0.tgz", - "integrity": "sha1-MBfoxc7SqS23UBeQJVw7qFFXN10=", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-4.3.0.tgz", + "integrity": "sha512-2UJ2BIUNa7+41PH4FvYicSQED2LCt2RXjmNFis+JZlxZtwzNnGn4uuL8WBUqHoC9b+bJ0AHIAX/bilzm+pGPeA==", "dev": true, "requires": { "chalk": "1.1.3", "conventional-changelog": "1.1.7", "conventional-recommended-bump": "1.1.0", + "dotgitignore": "1.0.3", "figures": "1.7.0", "fs-access": "1.0.1", "semver": "5.4.1", @@ -9901,7 +9948,7 @@ "integrity": "sha1-vpIYwTDCACnhB7D5Z/sj3gV50Tw=", "requires": { "bl": "0.9.5", - "end-of-stream": "1.4.0", + "end-of-stream": "1.4.1", "readable-stream": "1.0.34", "xtend": "4.0.1" }, @@ -10042,12 +10089,6 @@ "integrity": "sha1-n5up2e+odkw4dpi8v+sshI8RrbM=", "dev": true }, - "tryit": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz", - "integrity": "sha1-OTvnMKlEb9Hq1tpZoBQwjzbCics=", - "dev": true - }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", @@ -10086,13 +10127,24 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, "uglify-js": { - "version": "2.8.29", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", - "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "version": "3.3.5", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.5.tgz", + "integrity": "sha512-ZebM2kgBL/UI9rKeAbsS2J0UPPv7SBy5hJNZml/YxB1zC6JK8IztcPs+cxilE4pu0li6vadVSFqiO7xFTKuSrg==", "requires": { - "source-map": "0.5.7", - "uglify-to-browserify": "1.0.2", - "yargs": "3.10.0" + "commander": "2.12.2", + "source-map": "0.6.1" + }, + "dependencies": { + "commander": { + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.12.2.tgz", + "integrity": "sha512-BFnaq5ZOGcDN7FlrtBT4xxkgIToalIIxwjxLWVJ8bGTpe1LroqMiqQXdA7ygc7CRvaYS+9zfPGFnJqFSayx+AA==" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + } } }, "uglify-to-browserify": { @@ -10111,6 +10163,18 @@ "minimatch": "3.0.4", "through": "2.3.8", "uglify-js": "2.8.29" + }, + "dependencies": { + "uglify-js": { + "version": "2.8.29", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", + "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", + "requires": { + "source-map": "0.5.7", + "uglify-to-browserify": "1.0.2", + "yargs": "3.10.0" + } + } } }, "umd": { @@ -10316,7 +10380,7 @@ "resolved": "https://registry.npmjs.org/worker-farm/-/worker-farm-1.5.2.tgz", "integrity": "sha512-XxiQ9kZN5n6mmnW+mFJ+wXjNNI/Nx4DIdaAKLX1Bn6LYBWlN/zaBhu34DQYPZ1AJobQuu67S2OfDdNSVULvXkQ==", "requires": { - "errno": "0.1.5", + "errno": "0.1.6", "xtend": "4.0.1" } }, diff --git a/package.json b/package.json index d6de02c20..1f0f396ae 100644 --- a/package.json +++ b/package.json @@ -19,14 +19,13 @@ "debug": "^2.2.0", "fs-extra": "^0.30.0", "gemini-configparser": "^1.0.0", - "gemini-core": "^2.2.1", + "gemini-core": "^2.3.1", "gemini-coverage": "^1.0.0", "graceful-fs": "^4.1.11", "handlebars": "^4.0.5", "inherit": "~2.2.1", "js-yaml": "^3.2.5", "lodash": "^4.15.0", - "looks-same": "^3.0.0", "micromatch": "^2.3.11", "node-fetch": "^1.6.3", "plugins-loader": "^1.1.0", @@ -35,7 +34,7 @@ "sizzle": "^2.2.0", "source-map": "^0.5.3", "striptags": "2.1.1", - "uglify-js": "^2.7.3", + "uglify-js": "^3.3.5", "uglifyify": "^3.0.1", "wd": "^0.4.0", "worker-farm": "^1.3.1" @@ -60,8 +59,6 @@ }, "scripts": { "test-unit": "istanbul test _mocha -- --recursive test/unit", - "prepublish": "npm run prepare-calibrate-script", - "prepare-calibrate-script": "uglifyjs ./lib/browser/client-scripts/gemini.calibrate.js -m > ./lib/browser/client-scripts/gemini.calibrate.min.js --support-ie8", "postpublish": "npm run publish-site", "test-func": "istanbul test _mocha test/functional", "test-browser": "istanbul test _mocha test/browser", diff --git a/test/browser/calibrator.test.js b/test/browser/calibrator.test.js index 7573e42fe..6335d844c 100644 --- a/test/browser/calibrator.test.js +++ b/test/browser/calibrator.test.js @@ -1,6 +1,7 @@ 'use strict'; -var eachSupportedBrowser = require('./util').eachSupportedBrowser, - Calibrator = require('lib/calibrator'); + +const {eachSupportedBrowser} = require('./util'); +const {Calibrator} = require('gemini-core'); describe('calibrator', function() { eachSupportedBrowser(function() { diff --git a/test/functional/data/image/calibrate-broken.png b/test/functional/data/image/calibrate-broken.png deleted file mode 100644 index 989da40285d9cac1bae2e380c3c1293ceb9a13e2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 313 zcmeAS@N?(olHy`uVBq!ia0y~yVEPGU3v;jmNv=OaTNxM_89ZGaLn>~)y<^MA7%0(p z@wRs9w}e0`!?prNxOf5SXB}~m#Uk% z+A%PE`LMH3coqZ01K)ihgBQB)du_$QU~nk@)7_Ko3=HQ>U4V*8WPkc)FfknHa9J|F zYhJzEzt`psmwwM-U~n+kyZ$--$?TaxaC3ur{e|9b`x%A0j9(i>Iu!tegu&C*&t;uc GLK6TQ{evF> diff --git a/test/functional/data/image/calibrate.png b/test/functional/data/image/calibrate.png deleted file mode 100644 index ef64d730e2b5c911d2f9c7c508331686ea049c37..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 279 zcmeAS@N?(olHy`uVBq!ia0y~yV15H+3v;jmNv^N$H-XeWPZ!6Kid%2*Zsa{=AkcPE z`t0J$4jxy}gC-`9?N5|c&BE4I?Ej(?_G8L~?t8yEfjX{C?EZ5xiWy`?g{}Pc1p9l8 zK(@}Q2lG^K09gsi8_wr^*_pu3z|hcp@Zampr3d+d^5$&SE*xb*#tM-)lCPUV(hTd5 z08ME~n7?kB41=eupUXO@geCwCv15?{ diff --git a/test/unit/browser-pool.js b/test/unit/browser-pool.js index a6394e148..d7eead6ae 100644 --- a/test/unit/browser-pool.js +++ b/test/unit/browser-pool.js @@ -2,9 +2,8 @@ const BrowserPool = require('lib/browser-pool'); const BrowserFabric = require('lib/browser'); -const Calibrator = require('lib/calibrator'); const RunnerEvents = require('lib/constants/events'); -const CoreBrowserPool = require('gemini-core').BrowserPool; +const {BrowserPool: CoreBrowserPool, Calibrator} = require('gemini-core'); const AsyncEmitter = require('gemini-core').events.AsyncEmitter; const _ = require('lodash'); const Promise = require('bluebird'); diff --git a/test/unit/browser/new-browser.js b/test/unit/browser/new-browser.js index 8ab14a9b0..c9c05dd88 100644 --- a/test/unit/browser/new-browser.js +++ b/test/unit/browser/new-browser.js @@ -6,7 +6,7 @@ const _ = require('lodash'); const Camera = require('lib/browser/camera'); const ClientBridge = require('lib/browser/client-bridge'); -const Calibrator = require('lib/calibrator'); +const {Calibrator} = require('gemini-core'); const WdErrors = require('lib/constants/wd-errors'); const GeminiError = require('lib/errors/gemini-error'); diff --git a/test/unit/calibrator.test.js b/test/unit/calibrator.test.js deleted file mode 100644 index 3cfde4949..000000000 --- a/test/unit/calibrator.test.js +++ /dev/null @@ -1,70 +0,0 @@ -'use strict'; - -const Promise = require('bluebird'); -const path = require('path'); -const fs = require('fs'); -const {Image} = require('gemini-core'); -const Calibrator = require('lib/calibrator'); -const GeminiError = require('lib/errors/gemini-error'); -const {browserWithId} = require('../util'); - -describe('calibrator', function() { - let browser, calibrator; - - function setScreenshot(imageName) { - const imgPath = path.join(__dirname, '..', 'functional', 'data', 'image', imageName); - const imgData = fs.readFileSync(imgPath); - - browser.captureViewportImage.returns(Promise.resolve(new Image(imgData))); - } - - beforeEach(function() { - browser = browserWithId('id'); - sinon.stub(browser); - browser.evalScript.returns(Promise.resolve({innerWidth: 984})); //width of viewport in test image - browser.open.returns(Promise.resolve()); - calibrator = new Calibrator(); - }); - - it('should calculate correct crop area', function() { - setScreenshot('calibrate.png'); - const result = calibrator.calibrate(browser); - return Promise.all([ - assert.eventually.propertyVal(result, 'top', 2), - assert.eventually.propertyVal(result, 'left', 2) - ]); - }); - - it('should return also features detected by script', function() { - setScreenshot('calibrate.png'); - browser.evalScript.returns(Promise.resolve({feature: 'value', innerWidth: 984})); - const result = calibrator.calibrate(browser); - return assert.eventually.propertyVal(result, 'feature', 'value'); - }); - - it('should not perform the calibration process two times', function() { - setScreenshot('calibrate.png'); - return calibrator.calibrate(browser) - .then(() => calibrator.calibrate(browser)) - .then(function() { - assert.calledOnce(browser.open); - assert.calledOnce(browser.evalScript); - assert.calledOnce(browser.captureViewportImage); - }); - }); - - it('should return cached result second time', function() { - setScreenshot('calibrate.png'); - const result = calibrator.calibrate(browser) - .then(() => calibrator.calibrate(browser)); - return Promise.all([ - assert.eventually.propertyVal(result, 'top', 2), - assert.eventually.propertyVal(result, 'left', 2) - ]); - }); - - it('should fail on broken calibration page', function() { - setScreenshot('calibrate-broken.png'); - return assert.isRejected(calibrator.calibrate(browser), GeminiError); - }); -});