@applitools/core-base
Advanced tools
Comparing version 1.1.34 to 1.1.35
@@ -7,6 +7,11 @@ "use strict"; | ||
return async function checkAndClose({ target, settings, logger = defaultLogger, }) { | ||
var _a, _b, _c, _d, _e; | ||
settings !== null && settings !== void 0 ? settings : (settings = {}); | ||
(_a = settings.normalization) !== null && _a !== void 0 ? _a : (settings.normalization = {}); | ||
settings.normalization.limit = { | ||
maxImageHeight: Math.min((_c = (_b = settings.normalization.limit) === null || _b === void 0 ? void 0 : _b.maxImageHeight) !== null && _c !== void 0 ? _c : Infinity, requests.test.account.maxImageHeight), | ||
maxImageArea: Math.min((_e = (_d = settings.normalization.limit) === null || _d === void 0 ? void 0 : _d.maxImageArea) !== null && _e !== void 0 ? _e : Infinity, requests.test.account.maxImageArea), | ||
}; | ||
logger.log('Command "checkAndClose" is called with settings', settings); | ||
if (!target.isTransformed) { | ||
target = await (0, transform_target_1.transformTarget)({ target, settings }); | ||
} | ||
target = await (0, transform_target_1.transformTarget)({ target, settings }); | ||
const results = await requests.checkAndClose({ target, settings, logger }); | ||
@@ -13,0 +18,0 @@ return results; |
@@ -7,6 +7,11 @@ "use strict"; | ||
return async function check({ target, settings = {}, logger = defaultLogger, }) { | ||
var _a, _b, _c, _d, _e; | ||
settings !== null && settings !== void 0 ? settings : (settings = {}); | ||
(_a = settings.normalization) !== null && _a !== void 0 ? _a : (settings.normalization = {}); | ||
settings.normalization.limit = { | ||
maxImageHeight: Math.min((_c = (_b = settings.normalization.limit) === null || _b === void 0 ? void 0 : _b.maxImageHeight) !== null && _c !== void 0 ? _c : Infinity, requests.test.account.maxImageHeight), | ||
maxImageArea: Math.min((_e = (_d = settings.normalization.limit) === null || _d === void 0 ? void 0 : _d.maxImageArea) !== null && _e !== void 0 ? _e : Infinity, requests.test.account.maxImageArea), | ||
}; | ||
logger.log('Command "check" is called with settings', settings); | ||
if (!target.isTransformed) { | ||
target = await (0, transform_target_1.transformTarget)({ target, settings }); | ||
} | ||
target = await (0, transform_target_1.transformTarget)({ target, settings }); | ||
return requests.check({ target, settings, logger }); | ||
@@ -13,0 +18,0 @@ }; |
@@ -34,2 +34,9 @@ "use strict"; | ||
const results = await Promise.all(settings.map(async (settings) => { | ||
var _a, _b, _c, _d, _e; | ||
const account = await requests.getAccountInfo({ settings, logger }); | ||
(_a = settings.normalization) !== null && _a !== void 0 ? _a : (settings.normalization = {}); | ||
settings.normalization.limit = { | ||
maxImageHeight: Math.min((_c = (_b = settings.normalization.limit) === null || _b === void 0 ? void 0 : _b.maxImageHeight) !== null && _c !== void 0 ? _c : Infinity, account.maxImageHeight), | ||
maxImageArea: Math.min((_e = (_d = settings.normalization.limit) === null || _d === void 0 ? void 0 : _d.maxImageArea) !== null && _e !== void 0 ? _e : Infinity, account.maxImageArea), | ||
}; | ||
target = await (0, transform_target_1.transformTarget)({ target, settings }); | ||
@@ -36,0 +43,0 @@ return requests.extractText({ target, settings, logger }); |
@@ -7,2 +7,9 @@ "use strict"; | ||
return async function locateText({ target, settings, logger = defaultLogger, }) { | ||
var _a, _b, _c, _d, _e; | ||
const account = await requests.getAccountInfo({ settings, logger }); | ||
(_a = settings.normalization) !== null && _a !== void 0 ? _a : (settings.normalization = {}); | ||
settings.normalization.limit = { | ||
maxImageHeight: Math.min((_c = (_b = settings.normalization.limit) === null || _b === void 0 ? void 0 : _b.maxImageHeight) !== null && _c !== void 0 ? _c : Infinity, account.maxImageHeight), | ||
maxImageArea: Math.min((_e = (_d = settings.normalization.limit) === null || _d === void 0 ? void 0 : _d.maxImageArea) !== null && _e !== void 0 ? _e : Infinity, account.maxImageArea), | ||
}; | ||
logger.log('Command "locateText" is called with settings', settings); | ||
@@ -9,0 +16,0 @@ target = await (0, transform_target_1.transformTarget)({ target, settings }); |
@@ -7,2 +7,9 @@ "use strict"; | ||
return async function locate({ target, settings, logger = defaultLogger, }) { | ||
var _a, _b, _c, _d, _e; | ||
const account = await requests.getAccountInfo({ settings, logger }); | ||
(_a = settings.normalization) !== null && _a !== void 0 ? _a : (settings.normalization = {}); | ||
settings.normalization.limit = { | ||
maxImageHeight: Math.min((_c = (_b = settings.normalization.limit) === null || _b === void 0 ? void 0 : _b.maxImageHeight) !== null && _c !== void 0 ? _c : Infinity, account.maxImageHeight), | ||
maxImageArea: Math.min((_e = (_d = settings.normalization.limit) === null || _d === void 0 ? void 0 : _d.maxImageArea) !== null && _e !== void 0 ? _e : Infinity, account.maxImageArea), | ||
}; | ||
logger.log('Command "locate" is called with settings', settings); | ||
@@ -9,0 +16,0 @@ target = await (0, transform_target_1.transformTarget)({ target, settings }); |
@@ -350,3 +350,3 @@ "use strict"; | ||
const matchOptions = transformCheckOptions({ target, settings }); | ||
const response = await req(`/api/sessions/running/${encodeURIComponent(test.testId)}/matchandend`, { | ||
resultsPromise = req(`/api/sessions/running/${encodeURIComponent(test.testId)}/matchandend`, { | ||
name: 'checkAndClose', | ||
@@ -375,11 +375,13 @@ method: 'POST', | ||
logger, | ||
}).then(async (response) => { | ||
if (response.status === 404) { | ||
supportsCheckAndClose = false; | ||
return checkAndClose({ target, settings }); | ||
} | ||
const result = await response.json(); | ||
result.userTestId = test.userTestId; | ||
logger.log('Request "checkAndClose" finished successfully with body', result); | ||
return [result]; | ||
}); | ||
if (response.status === 404) { | ||
supportsCheckAndClose = false; | ||
return checkAndClose({ target, settings }); | ||
} | ||
const result = await response.json(); | ||
result.userTestId = test.userTestId; | ||
logger.log('Request "checkAndClose" finished successfully with body', result); | ||
return [result]; | ||
return resultsPromise; | ||
} | ||
@@ -386,0 +388,0 @@ async function close({ settings, logger = defaultLogger, } = {}) { |
@@ -32,2 +32,5 @@ "use strict"; | ||
async function transformTarget({ target, settings, }) { | ||
var _a; | ||
if (target.isTransformed) | ||
return target; | ||
if (target.image instanceof URL) | ||
@@ -46,2 +49,6 @@ target.image = target.image.href; | ||
const image = (0, image_1.makeImage)(target.image); | ||
if (image.height === 0 || image.width === 0) { | ||
await image.debug('image is empty, try to getObject'); | ||
await image.toObject(); | ||
} | ||
if ((settings === null || settings === void 0 ? void 0 : settings.normalization) || (settings === null || settings === void 0 ? void 0 : settings.region)) { | ||
@@ -62,2 +69,6 @@ await image.debug({ ...settings.debugImages, suffix: 'original' }); | ||
} | ||
if ((_a = settings.normalization) === null || _a === void 0 ? void 0 : _a.limit) { | ||
const height = cropToHeightLimit(image, settings.normalization.limit); | ||
image.crop({ y: 0, x: 0, width: image.width, height }); | ||
} | ||
} | ||
@@ -71,1 +82,8 @@ target.image = await image.toPng(); | ||
exports.transformTarget = transformTarget; | ||
function cropToHeightLimit(image, limit) { | ||
const { maxImageHeight, maxImageArea } = limit; | ||
if (image.height > maxImageHeight || image.height * image.width > maxImageArea) { | ||
return Math.min(maxImageArea / image.width, maxImageHeight); | ||
} | ||
return image.height; | ||
} |
{ | ||
"name": "@applitools/core-base", | ||
"version": "1.1.34", | ||
"version": "1.1.35", | ||
"homepage": "https://applitools.com", | ||
@@ -43,3 +43,3 @@ "bugs": { | ||
"test": "mocha --no-timeouts -r ts-node/register --parallel --jobs 15 './test/**/*.spec.ts'", | ||
"test:sanity": "yarn test:unit", | ||
"test:sanity": "yarn test:unit && yarn test:it", | ||
"test:e2e": "mocha --no-timeouts -r ts-node/register './test/e2e/*.spec.ts'", | ||
@@ -46,0 +46,0 @@ "test:it": "mocha --no-timeouts -r ts-node/register './test/it/*.spec.ts'", |
@@ -229,2 +229,6 @@ /// <reference types="node" /> | ||
scaleRatio?: number; | ||
limit?: { | ||
maxImageArea: number; | ||
maxImageHeight: number; | ||
}; | ||
}; | ||
@@ -231,0 +235,0 @@ autProxy?: Proxy; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103637
1924