Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@applitools/eyes.cypress

Package Overview
Dependencies
Maintainers
12
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@applitools/eyes.cypress - npm Package Compare versions

Comparing version 1.2.4 to 1.2.5

src/render-grid/sdk/createRenderRequests.js

2

package.json
{
"name": "@applitools/eyes.cypress",
"version": "1.2.4",
"version": "1.2.5",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -7,5 +7,2 @@ const {

ConsoleLogHandler,
RGridDom,
RenderRequest,
RenderInfo,
} = require('@applitools/eyes.sdk.core');

@@ -51,25 +48,16 @@

setRenderingInfo(renderingInfo) {
this._serverConnector.setRenderingAuthToken(renderingInfo.getAccessToken());
this._serverConnector.setRenderingServerUrl(renderingInfo.getServiceUrl());
}
/**
* Create a screenshot of a page on RenderingGrid server
*
* @param {String} url The url of the page to be rendered
* @param {RGridDom} rGridDom The DOM of a page with resources
* @param {RenderingInfo} [renderingInfo]
* @return {Promise.<String>} The results of the render
* @param {RenderRequest[]} renderRequests The requests to be sent to the rendering grid
* @return {Promise.<String[]>} The results of the render
*/
async postRender({url, resources, cdt, viewportSize, renderInfo}) {
this._serverConnector.setRenderingAuthToken(renderInfo.getAccessToken());
this._serverConnector.setRenderingServerUrl(renderInfo.getServiceUrl());
const rGridDom = this.createRGridDom({resources, cdt});
const renderRequest = new RenderRequest(
renderInfo.getResultsUrl(),
url,
rGridDom,
RenderInfo.fromRectangleSize(new RectangleSize(viewportSize)),
'Linux',
'chrome',
);
const runningRender = await this._renderWindowTask.postRender(renderRequest);
return runningRender.getRenderId();
async renderBatch(renderRequests) {
const runningRenders = await this._renderWindowTask.postRenderBatch(renderRequests);
return runningRenders.map(rr => rr.getRenderId());
}

@@ -81,6 +69,2 @@

async getRenderStatusByIds(renderIds) {
return await this._serverConnector.getRenderStatusByIds(renderIds);
}
async checkWindow({screenshotUrl, tag}) {

@@ -108,13 +92,4 @@ const regionProvider = new NullRegionProvider(this.getPromiseFactory()); // TODO receive from outside?

}
createRGridDom({cdt, resources}) {
const resourceArr = Object.values(resources);
const rGridDom = new RGridDom();
rGridDom.setDomNodes(cdt);
rGridDom.setResources(resourceArr);
return rGridDom;
}
}
module.exports = EyesWrapper;

@@ -10,2 +10,6 @@ const {Logger, ConsoleLogHandler} = require('@applitools/eyes.sdk.core');

log.setIsVerbose = function(isVerbose) {
logger._logHandler.setIsVerbose(isVerbose);
};
module.exports = log;

@@ -5,4 +5,8 @@ const EyesWrapper = require('./EyesWrapper');

const {URL} = require('url');
// const saveData = require('../troubleshoot/saveData');
const saveData = require('../troubleshoot/saveData');
const {setIsVerbose} = require('./log');
const createRenderRequests = require('./createRenderRequests');
let batchInfo;
async function openEyes({

@@ -15,4 +19,6 @@ appName,

isVerbose = false,
wrapper = new EyesWrapper({apiKey, isVerbose}),
saveDebugData = false,
wrappers,
}) {
setIsVerbose(isVerbose);
const renderPromises = [];

@@ -22,5 +28,3 @@

async function checkWindowDo() {
if (!renderInfo) {
renderInfo = await wrapper.getRenderInfo();
}
const renderInfo = await renderInfoPromise;

@@ -31,17 +35,20 @@ const absoluteUrls =

const renderId = await wrapper.postRender({
const renderRequests = createRenderRequests({
url,
resources,
tag,
cdt,
viewportSize,
viewportSizes,
renderInfo,
});
const renderIds = await renderWrapper.renderBatch(renderRequests);
// TODO troubleshoot flag
// await saveData({renderId, cdt, resources, url});
if (saveDebugData) {
for (const renderId of renderIds) {
await saveData({renderId, cdt, resources, url});
}
}
const screenshotUrl = await waitForRenderedStatus(renderId, wrapper);
const screenshotUrls = await waitForRenderedStatus(renderIds, renderWrapper);
return {screenshotUrl, tag};
return {screenshotUrls, tag};
}

@@ -57,8 +64,9 @@ const renderPromise = checkWindowDo();

for (const renderPromise of renderPromises) {
const renderResult = await renderPromise;
results.push(await wrapper.checkWindow(renderResult));
const {screenshotUrls, tag} = await renderPromise;
for (let i = 0, ii = screenshotUrls.length; i < ii; i++) {
results.push(await wrappers[i].checkWindow({screenshotUrl: screenshotUrls[i], tag}));
}
}
await wrapper.close();
await Promise.all(wrappers.map(wrapper => wrapper.close()));

@@ -68,6 +76,28 @@ return results;

let renderInfo;
async function initWrappers() {
wrappers = [];
for (const viewportSize of viewportSizes) {
const wrapper = new EyesWrapper({apiKey, isVerbose});
await wrapper.open(appName, testName, viewportSize);
wrappers.push(wrapper);
}
}
await wrapper.open(appName, testName, viewportSize);
const viewportSizes = Array.isArray(viewportSize) ? viewportSize : [viewportSize];
if (!wrappers) {
await initWrappers();
}
const renderWrapper = wrappers[0];
if (!batchInfo) {
batchInfo = renderWrapper.getBatch();
}
for (const wrapper of wrappers) {
wrapper.setBatch(batchInfo);
}
const renderInfoPromise = renderWrapper.getRenderInfo().then(renderInfo => {
renderWrapper.setRenderingInfo(renderInfo);
return renderInfo;
});
return {

@@ -79,2 +109,7 @@ checkWindow,

// for tests
openEyes.clearBatch = () => {
batchInfo = null;
};
module.exports = openEyes;

@@ -8,3 +8,3 @@ const {RenderStatus} = require('@applitools/eyes.sdk.core');

async function waitForRenderedStatus(renderId, wrapper) {
async function waitForRenderedStatus(renderIds, wrapper) {
async function getStatus() {

@@ -17,12 +17,18 @@ if (timeoutReached) {

try {
const renderStatus = await wrapper.getRenderStatus(renderId);
const status = renderStatus.getStatus();
if (!status || status === RenderStatus.RENDERING) {
const renderStatuses = await wrapper.getRenderStatus(renderIds);
const error = renderStatuses.find(
rs => (rs.getStatus() === RenderStatus.ERROR ? rs.getError() : null),
);
if (error) {
throw error;
}
const statuses = renderStatuses.map(rs => rs.getStatus());
if (statuses.some(status => !status || status === RenderStatus.RENDERING)) {
await psetTimeout(GET_STATUS_INTERVAL);
return await getStatus();
} else if (status === RenderStatus.ERROR) {
throw renderStatus.getError();
}
clearTimeout(timeoutId);
return renderStatus.getImageLocation();
return renderStatuses.map(rs => rs.getImageLocation());
} catch (ex) {

@@ -29,0 +35,0 @@ wrapper._logger.log(`error during getRenderStatus: ${ex}`);

@@ -126,6 +126,19 @@ // 'use strict';

function getFileExtension(contentType) {
let fileExtension = extension(contentType);
// NOTE: this is because of missing mime type(s) in the `mime-db` package. Patching more missing types should be done inside this `if` statement.
if (!fileExtension) {
if (contentType === 'application/font-woff2') {
fileExtension = 'woff2';
}
}
return fileExtension;
}
function getResourceName(resource) {
const sha256 = resource.getSha256Hash();
const contentType = resource.getContentType();
return `${sha256}.${extension(contentType)}`;
const fileExtension = getFileExtension(resource.getContentType());
return `${sha256}.${fileExtension}`;
}

@@ -132,0 +145,0 @@

@@ -7,2 +7,3 @@ 'use strict';

const {renderDomNodesToHtml, createAbsolutizedDomNodes, getResourceName} = require('./cdt');
const {mapValues} = require('lodash');

@@ -24,2 +25,6 @@ const writeFile = p(fs.writeFile);

writeFile(resolve(path, `${renderId}.html`), html);
writeFile(
resolve(path, 'resources.json'),
JSON.stringify(mapValues(resources, resource => resource.getContentType()), null, 2),
);
Object.keys(resources).map(resourceUrl => {

@@ -29,4 +34,5 @@ const resource = resources[resourceUrl];

if (content) {
log(`saving resource: ${resourceUrl}`);
return writeFile(resolve(path, getResourceName(resource)), content);
const resourceName = getResourceName(resource);
log(`saving resource: ${resourceUrl} as ${resourceName}`);
return writeFile(resolve(path, resourceName), content);
} else {

@@ -33,0 +39,0 @@ log(`NOT saving resource (missing content): ${resourceUrl}`);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc