@cznec/screenshot-compare
Advanced tools
Comparing version 1.0.5 to 1.0.8
{ | ||
"name": "@cznec/screenshot-compare", | ||
"version": "1.0.5", | ||
"author": "@cznec", | ||
"version": "1.0.8", | ||
"homepage": "https://github.com/cznec/screenshot-compare", | ||
@@ -5,0 +6,0 @@ "keywords": [ |
# @cznec/screenshot-compare | ||
Website testing tool for screenshot capture and compare. | ||
Website testing tool for screenshot capture and compare. | ||
Package is under construction 🚧 but it works! 😉 | ||
@@ -90,3 +91,1 @@ ### Installing | ||
More documentation under construction 🚧 |
@@ -7,4 +7,5 @@ const prompts = require('prompts') | ||
const md5 = require('md5') | ||
const PNG = require('pngjs').PNG; | ||
const pixelmatch = require('pixelmatch'); | ||
const PNG = require('pngjs').PNG | ||
const pixelmatch = require('pixelmatch') | ||
require('colors') | ||
@@ -19,3 +20,3 @@ | ||
constructor(opt) { | ||
this.opt = opt; | ||
this.opt = opt | ||
@@ -53,3 +54,3 @@ this.required() | ||
async initBrowser() { | ||
this.browser = await puppeteer.launch(); | ||
this.browser = await puppeteer.launch() | ||
} | ||
@@ -65,3 +66,3 @@ | ||
initial: true | ||
}]); | ||
}]) | ||
@@ -74,13 +75,13 @@ if (!response.value) this.error('Exit()') | ||
let delayAlt = itemDelay | ||
let delayAltInterval = null; | ||
let delayAltInterval = null | ||
delayAltInterval = setInterval(() => { | ||
delayAlt -= 100 | ||
process.stdout.clearLine(); | ||
process.stdout.cursorTo(0); | ||
process.stdout.write(`Delay: ${delayAlt}`.gray); | ||
process.stdout.clearLine() | ||
process.stdout.cursorTo(0) | ||
process.stdout.write(`Delay: ${delayAlt}`.gray) | ||
if (delayAlt <= 0) { | ||
clearInterval(delayAltInterval) | ||
process.stdout.clearLine(); | ||
process.stdout.cursorTo(0); | ||
process.stdout.clearLine() | ||
process.stdout.cursorTo(0) | ||
} | ||
@@ -106,3 +107,3 @@ }, 100) | ||
const item = items[i] | ||
const page = await this.browser.newPage(); | ||
const page = await this.browser.newPage() | ||
const meta = this.getItemMeta(item) | ||
@@ -148,3 +149,3 @@ | ||
if (item.pageLog) | ||
page.on('console', msg => console.log('PAGE LOG:', msg.text())); | ||
page.on('console', msg => console.log('PAGE LOG:', msg.text())) | ||
@@ -200,13 +201,38 @@ /** | ||
compare(img1Path, img2Path, diffPath) { | ||
const img1 = PNG.sync.read(fs.readFileSync(img1Path)); | ||
const img2 = PNG.sync.read(fs.readFileSync(img2Path)); | ||
const {width, height} = img1; | ||
const diff = new PNG({width, height}); | ||
const img1 = PNG.sync.read(fs.readFileSync(img1Path)) | ||
const img2 = PNG.sync.read(fs.readFileSync(img2Path)) | ||
const width1 = img1.width | ||
const height1 = img1.height | ||
const width2 = img2.width | ||
const height2 = img2.height | ||
if (width1 !== width2) { | ||
console.error("Images widths must be the same size") | ||
return | ||
} | ||
const width = width1 | ||
const height = height1 > height2 ? height1 : height2 | ||
const pxCount = width * height | ||
const temp1 = new PNG({width, height}) | ||
const temp2 = new PNG({width, height}) | ||
const diff = new PNG({width, height}) | ||
temp1.data = img1.data | ||
temp2.data = img2.data | ||
if (height1 !== height2) { | ||
const smaller = temp1.data.length < temp2.data.length ? temp1 : temp2 | ||
const pixelFill = [] | ||
for (let i = diff.data.length - smaller.data.length; i > 0; i--) { pixelFill.push(155) } | ||
smaller.data = Buffer.from([...smaller.data].concat(pixelFill)) | ||
} | ||
try { | ||
const px = pixelmatch(img1.data, img2.data, diff.data, width, height, {threshold: 0}); | ||
const px = pixelmatch(temp1.data, temp2.data, diff.data, width, height, {threshold: 0}) | ||
console.log(`Diff: ${(px/pxCount) *100}% (pixel diff: ${px})`.blue) | ||
fs.writeFileSync(diffPath, PNG.sync.write(diff)); | ||
fs.writeFileSync(diffPath, PNG.sync.write(diff)) | ||
} catch (e) { | ||
@@ -213,0 +239,0 @@ console.log(e) |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
11601
292
1
91