testcafe-blink-diff
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -41,6 +41,20 @@ /* global window, document */ | ||
var isOK = tag('h3', null, imageInfo.ok ? 'It passed.' : 'It did not passed!'); | ||
var diff = tag('h2', null, ((imageInfo.diff) + "%")); | ||
var diff = tag('h2', null, ("Diff: " + (imageInfo.diff) + "%")); | ||
function click() { | ||
window.open(imageInfo.images.out); | ||
var modal = tag('div', { | ||
class: 'modal', | ||
click: function click() { | ||
document.body.removeChild(modal); | ||
document.body.style.overflow = ''; | ||
}, | ||
}); | ||
var imgOld = tag('img', { src: imageInfo.images.base }); | ||
var imgNew = tag('img', { src: imageInfo.images.actual }); | ||
var imgDiff = tag('img', { src: imageInfo.images.out }); | ||
document.body.style.overflow = 'hidden'; | ||
push(modal, imgOld, imgDiff, imgNew); | ||
push(document.body, modal); | ||
} | ||
@@ -47,0 +61,0 @@ |
@@ -140,2 +140,3 @@ const wargs = require('wargs'); | ||
const baseDir = path.dirname(images[groupedName][left]); | ||
const metaFile = path.join(baseDir, 'blockOut.json'); | ||
const outFile = path.join(baseDir, 'out.png'); | ||
@@ -146,2 +147,4 @@ | ||
tasks.push(() => new Promise((resolve, reject) => { | ||
const blockOut = fs.existsSync(metaFile) ? require(metaFile) : []; | ||
const diff = new BlinkDiff({ | ||
@@ -154,2 +157,3 @@ imageAPath: images[groupedName][left], | ||
blockOut: blockOut.map(_ => [_.left, _.top, _.width, _.height]), | ||
composition: false, | ||
@@ -174,2 +178,4 @@ | ||
sources.push(path.relative(imagesPath, outFile)); | ||
const prefix = baseDir === '.' ? '' : path.relative(imagesPath, baseDir); | ||
@@ -176,0 +182,0 @@ |
@@ -1,7 +0,22 @@ | ||
const GROUP = {}; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const KEYS = {}; | ||
const GROUPS = {}; | ||
const isFullPage = process.argv.slice(2).indexOf('--full-page'); | ||
const isTakeSnapshot = process.argv.slice(2).indexOf('--take-snapshot'); | ||
const snapshotName = isTakeSnapshot > -1 ? process.argv.slice(2)[isTakeSnapshot + 1] : null; | ||
const type = snapshotName || ((process.env.SNAPSHOT || isTakeSnapshot !== -1) ? 'base' : 'actual'); | ||
const type = (snapshotName && snapshotName.match(/^[a-z\d_]/) ? snapshotName : null) | ||
|| (isTakeSnapshot !== -1 ? 'base' : 'actual'); | ||
function noop() { | ||
// do nothing | ||
} | ||
function padLeft(value) { | ||
return `000${value}`.substr(-3); | ||
} | ||
function normalize(value) { | ||
@@ -15,25 +30,46 @@ return value | ||
function padLeft(value) { | ||
return `000${value}`.substr(-3); | ||
} | ||
// FIXME: implement blockOut, e.g. take a list of selectors, retrieve their coordinates, remap, etc. | ||
function takeSnapshot(t, label, timeout) { | ||
async function takeSnapshot(t, opts) { | ||
const options = Object.assign({}, opts); | ||
const groupId = t.testRun.test.fixture.name; | ||
if (!GROUP[groupId]) { | ||
GROUP[groupId] = 0; | ||
if (!GROUPS[groupId]) { | ||
GROUPS[groupId] = 0; | ||
KEYS[groupId] = Object.keys(GROUPS).length; | ||
} | ||
GROUP[groupId] += 1; | ||
GROUPS[groupId] += 1; | ||
const offset = padLeft(GROUP[groupId]); | ||
const filename = normalize(label || t.testRun.test.name); | ||
const imagePath = `${normalize(groupId)}/${offset}_${filename}/${type}.png`; | ||
const prefix = padLeft(KEYS[groupId]); | ||
const offset = padLeft(GROUPS[groupId]); | ||
const filename = normalize(options.label || t.testRun.test.name); | ||
const imagePath = `${prefix}_${normalize(groupId)}/${offset}_${filename}/${type}.png`; | ||
return t.wait(timeout === false ? 0 : (timeout || 500)).takeScreenshot(imagePath); | ||
await t.wait(options.timeout === false ? 0 : (options.timeout || 500)); | ||
if (!isFullPage || options.selector) { | ||
await t.takeElementScreenshot(options.selector || 'body', imagePath); | ||
} else { | ||
await t.takeScreenshot(imagePath); | ||
} | ||
if (options.blockOut) { | ||
const selectors = Array.isArray(options.blockOut) ? options.blockOut : [options.blockOut]; | ||
const results = await Promise.all(selectors.map(x => { | ||
if (typeof x !== 'function') { | ||
console.warn(`[testcafe-blink-diff] Expecting a Selector() instance, given '${x}'`); | ||
return; | ||
} | ||
return x().then(result => result.boundingClientRect); | ||
})); | ||
const baseDir = path.join(t.testRun.opts.screenshotPath, path.dirname(imagePath)); | ||
const metaFile = path.join(baseDir, 'blockOut.json'); | ||
fs.writeFileSync(metaFile, JSON.stringify(results)); | ||
} | ||
} | ||
module.exports = { | ||
takeSnapshot, | ||
takeSnapshot: isTakeSnapshot === -1 ? noop : takeSnapshot, | ||
}; |
{ | ||
"name": "testcafe-blink-diff", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Visual regression for Testcafé through BlinkDiff", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14466
308
0
4