Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a threshold for the image hash comparison
Browse files Browse the repository at this point in the history
wooferzfg committed May 27, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent dae3946 commit a4cac16
Showing 3 changed files with 29 additions and 1 deletion.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
"hex64": "^0.4.0",
"html-webpack-plugin": "^4.3.0",
"imghash": "0.0.7",
"leven": "^3.1.0",
"mocha": "^7.1.2",
"moment": "^2.25.0",
"node-fetch": "^2.6.0",
13 changes: 12 additions & 1 deletion test/rendering-test.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ const chrome = require("selenium-webdriver/chrome");
const chromedriver = require("chromedriver");
const imghash = require("imghash");
const hex64 = require("hex64");
const leven = require("leven");
const pixelmatch = require("pixelmatch");
const PNG = require("pngjs").PNG;

@@ -48,6 +49,12 @@ describe("Layout Rendering Tests", function() {
await driver.sleep(500);
}

const hashToBinary = (hash) => {
const buffer = Buffer.from(hash, "base64");
const values = Array.from(buffer.values());
return values.map((value) => value.toString(2).padStart(8, "0")).join("");
};

before(async () => {
console.log('Starting server...');

@@ -111,7 +118,11 @@ describe("Layout Rendering Tests", function() {

fs.renameSync(tempFilePath, actualScreenshotPath);

if (actualHash !== expectedHash) {
const actualBinary = hashToBinary(actualHash);
const expectedBinary = hashToBinary(expectedHash);
const distance = leven(actualBinary, expectedBinary);

if (distance <= 1) {
let showWarning = false;
try {
if (fs.existsSync(expectedScreenshotPath)) {

0 comments on commit a4cac16

Please sign in to comment.