Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const throwNoRefError = (refImg, capture) => {
const currImg = {path: temp.path({suffix: '.png'}), size: capture.image.getSize()};
return capture.image.save(currImg.path)
.then(() => Promise.reject(new NoRefImageError(refImg, currImg)));
};
const notUpdated = (refImg) => ({refImg, updated: false});
extendWithPageScreenshot(obj) {
const path = temp.path({suffix: '.png'});
return this.browser.captureViewportImage()
.then((screenImage) => [screenImage.getSize(), screenImage.save(path)])
.spread((size) => {
obj.img = {path, size};
})
.catch(_.noop)
.then(() => obj);
}
: Promise.reject(e);
const page = await browser.prepareScreenshot(
[].concat(selectors), {ignoreSelectors: [].concat(opts.ignoreElements)}
);
const {tempOpts} = RuntimeConfig.getInstance();
temp.attach(tempOpts);
const screenShooterOpts = {
allowViewportOverflow: opts.allowViewportOverflow,
screenshotDelay: opts.screenshotDelay
};
const currImgInst = await screenShooter.capture(page, screenShooterOpts);
const currImg = {path: temp.path(Object.assign(tempOpts, {suffix: '.png'})), size: currImgInst.getSize()};
await currImgInst.save(currImg.path);
const test = getTestContext(session.executionContext);
const refImg = {path: config.getScreenshotPath(test, state), size: null};
const {emitter} = browser;
if (!fs.existsSync(refImg.path)) {
return handleNoRefImage(currImg, refImg, state, {emitter}).catch((e) => handleCaptureProcessorError(e));
}
const {canHaveCaret, pixelRatio} = page;
const imageCompareOpts = {
tolerance: opts.tolerance,
antialiasingTolerance,
canHaveCaret,
pixelRatio,