init
2
jdenticon-js/test/e2e/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.bundle.js
|
||||
*.bundle.js.map
|
||||
40
jdenticon-js/test/e2e/base-browser-test.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const tap = require("tap");
|
||||
const canvasRenderer = require("canvas-renderer");
|
||||
|
||||
export function testBrowser(jdenticon, bundle) {
|
||||
tap.test(bundle, bundleTest => {
|
||||
bundleTest.test("jdenticon.bundle", t => {
|
||||
t.equal(jdenticon.bundle, bundle);
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.test("jdenticon.version", t => {
|
||||
t.match(jdenticon.version, /^\d+(\.\d+)*$/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.test("jdenticon.configure", t => {
|
||||
t.doesNotThrow(() => jdenticon.configure({ backColor: "#fff" }));
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.test("jdenticon.drawIcon", t => {
|
||||
t.doesNotThrow(() => jdenticon.drawIcon(canvasRenderer.createCanvas(100, 100).getContext("2d"), "Icon1", 100));
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.test("jdenticon.toSvg", t => {
|
||||
t.match(jdenticon.toSvg("Icon1", 100), /^<svg/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.test("jdenticon.update*", t => {
|
||||
t.type(jdenticon.update, Function);
|
||||
t.type(jdenticon.updateCanvas, Function);
|
||||
t.type(jdenticon.updateSvg, Function);
|
||||
t.end();
|
||||
});
|
||||
|
||||
bundleTest.end();
|
||||
});
|
||||
}
|
||||
35
jdenticon-js/test/e2e/browser/assets/amd.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>"Icon0" - AMD - Should be equal</h1>
|
||||
<figure>
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAWlBMVEUAAP9aOuYxMYKdne+CXN5AQGLHx+lDQ2TIyOlDQ13NzedHR1ZHR1jW1ufY2OdLS1Dg4OVKSk/g4OWjc9Gjc9FLS02ldNDj4+RLS0yldNDj4+VMTEymddHl5eU2yqFLAAAAG3RSTlMRHy8vPVtbXFxra4iIiIjDw8TE0tPw8PDx8fEmYw1hAAABrUlEQVR42u2ZYWvCQBBE6542UVuT2Kaxnvf//2aR45hrl2mgxyKFfR+HjM9EggP35DiOY0x4fn0OP0PZveyEhLTOFWO6M367ToZ4ZxAe6jrnsKTMckC4n2Nm3tNQ1ylhSYUllFDmWJiFhrrOGBMYSzhEMNBQ1wkh1YQcSqwRErK6pk81fQ67WNORkNU1p1RzyuEx1hxJSOrmd/KA3wScEziXcIpgoqGuM8I1Fa54Ty6xcBEa6jrlcC0X1W/8pXzcnoe6zgnnfLOhDmXKj0VISOtc0596dY10x05oqOuO8xAwD2zrmAeEprqeB4Smup4HhJa6ngeMlrr+KyK01PWfKqOhTuaBYrNtqKuvQhxvn9uG+q8PFY7b7WP7x7qeB9TBLOt1PQ+Yg1nW63oeMAezrNf1POAObuF1Mg+Yg1t4ncMdsFDaHbBYOMwtm3ctwatvYYHDygKHwRKABQ6DIQELHO1DQlvgMBgSsMBhMSRggaN9SBBLdtgMCVjg+K9DAlgOCWA5JIDlkAA2Q4LTPiQ4JkMCrNcdx482/Gij5Whj8qMNP9rwow0/2nAcx7HjC8pg1fBM8ggRAAAAAElFTkSuQmCC" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="AMDIcon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(value) AMD</figcaption>
|
||||
</figure>
|
||||
|
||||
<script>
|
||||
var jdenticon_config = {
|
||||
backColor: "#00f1",
|
||||
replaceMode: "observe"
|
||||
};
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/requirejs/2.1.22/require.min.js"></script>
|
||||
<script>
|
||||
|
||||
requirejs(["/node_modules/jdenticon/dist/jdenticon.min.js"], function (jd) {
|
||||
jd.update("#AMDIcon0", "Icon0");
|
||||
});
|
||||
|
||||
</script>
|
||||
<script src="common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
63
jdenticon-js/test/e2e/browser/assets/center.html
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>"Icon2" - Should be centered vertically and horizontally</h1>
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon2" width="60" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Icon2-update-vert" width="60" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg data-jdenticon-value="Icon2" width="60" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Icon2-update-vert" width="60" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon2" width="100" height="60"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Icon2-update-hori" width="100" height="60"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg data-jdenticon-value="Icon2" width="100" height="60"></svg>
|
||||
<figcaption><strong>SVG</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Icon2-update-hori" width="100" height="60"></svg>
|
||||
<figcaption><strong>SVG</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<script>
|
||||
var jdenticon_config = {
|
||||
backColor: "#00f1",
|
||||
};
|
||||
</script>
|
||||
<script src="/node_modules/jdenticon/dist/jdenticon.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/require1k@1.0.1/require1k.min.js"></script>
|
||||
<script>
|
||||
jdenticon.update("#canvas-Icon2-update-vert,#svg-Icon2-update-vert", "Icon2");
|
||||
jdenticon.update("#canvas-Icon2-update-hori,#svg-Icon2-update-hori", "Icon2");
|
||||
</script>
|
||||
<script src="common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
27
jdenticon-js/test/e2e/browser/assets/common.js
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
addEventListener("message", function (ev) {
|
||||
var data = JSON.parse(ev.data);
|
||||
|
||||
if ("scrollHeight" in data) {
|
||||
var iframe = document.getElementsByName(data.name);
|
||||
if (iframe && iframe.length) {
|
||||
iframe[0].style.height = data.scrollHeight + "px";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function postHeight(timeout) {
|
||||
setTimeout(function () {
|
||||
// IE9 does not support passing objects through postMessage
|
||||
window.parent.postMessage(JSON.stringify({
|
||||
scrollHeight: document.body.scrollHeight,
|
||||
name: window.name
|
||||
}), "*");
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
if (window.parent) {
|
||||
postHeight(0);
|
||||
postHeight(1000);
|
||||
addEventListener("resize", postHeight);
|
||||
}
|
||||
66
jdenticon-js/test/e2e/browser/assets/index.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon browser test</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<script src="common.js"></script>
|
||||
|
||||
<div class="test-metadata">
|
||||
<div class="jdenticon-info">Unknown Jdenticon version.</div>
|
||||
<div class="browser-info">Unknown browser</div>
|
||||
</div>
|
||||
|
||||
<!-- Tests are run in iframes to allow isolated testing of loaders and configuration -->
|
||||
<iframe name="amd" src="amd.html"></iframe>
|
||||
<iframe name="umd-in-head" src="umd-in-head.html"></iframe>
|
||||
<iframe name="normal" src="normal.html"></iframe>
|
||||
<iframe name="padding-0" src="padding.html?padding=0"></iframe>
|
||||
<iframe name="padding-30" src="padding.html?padding=30"></iframe>
|
||||
<iframe name="center" src="center.html"></iframe>
|
||||
|
||||
<script src="/node_modules/jdenticon/dist/jdenticon.min.js"></script>
|
||||
<script>
|
||||
|
||||
var BROWSER_REGEX = ["Firefox/", "SamsungBrowser/", "Opera/", "OPR/", "MSIE ", "Trident/", "Edge?/", "Chrome/", "Safari/"];
|
||||
|
||||
function htmlEncode(text) {
|
||||
var div = document.createElement("div");
|
||||
div.innerText = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function detectBrowser() {
|
||||
var html = navigator.userAgent;
|
||||
var hasMatch = false;
|
||||
|
||||
for (var i = 0; !hasMatch && i < BROWSER_REGEX.length; i++) {
|
||||
var tempHtml = html.replace(new RegExp("(\\b" + BROWSER_REGEX[i] + "\\S+)|<|>|&", "g"), function (match) {
|
||||
if (match === "<") return "<";
|
||||
if (match === ">") return ">";
|
||||
if (match === "&") return "&";
|
||||
hasMatch = true;
|
||||
return "<strong>" + htmlEncode(match) + "</strong>";
|
||||
})
|
||||
|
||||
if (hasMatch) {
|
||||
html = tempHtml;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMatch) {
|
||||
html = htmlEncode(html);
|
||||
}
|
||||
|
||||
var browserInfo = document.querySelector(".browser-info");
|
||||
browserInfo.innerHTML = html;
|
||||
}
|
||||
|
||||
var versionInfo = document.querySelector(".jdenticon-info");
|
||||
versionInfo.innerText = "Jdenticon " + jdenticon.version;
|
||||
|
||||
detectBrowser();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
224
jdenticon-js/test/e2e/browser/assets/normal.html
Normal file
@@ -0,0 +1,224 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>"Icon0" - Should be equal</h1>
|
||||
<figure>
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAWlBMVEUAAP9aOuYxMYKdne+CXN5AQGLHx+lDQ2TIyOlDQ13NzedHR1ZHR1jW1ufY2OdLS1Dg4OVKSk/g4OWjc9Gjc9FLS02ldNDj4+RLS0yldNDj4+VMTEymddHl5eU2yqFLAAAAG3RSTlMRHy8vPVtbXFxra4iIiIjDw8TE0tPw8PDx8fEmYw1hAAABrUlEQVR42u2ZYWvCQBBE6542UVuT2Kaxnvf//2aR45hrl2mgxyKFfR+HjM9EggP35DiOY0x4fn0OP0PZveyEhLTOFWO6M367ToZ4ZxAe6jrnsKTMckC4n2Nm3tNQ1ylhSYUllFDmWJiFhrrOGBMYSzhEMNBQ1wkh1YQcSqwRErK6pk81fQ67WNORkNU1p1RzyuEx1hxJSOrmd/KA3wScEziXcIpgoqGuM8I1Fa54Ty6xcBEa6jrlcC0X1W/8pXzcnoe6zgnnfLOhDmXKj0VISOtc0596dY10x05oqOuO8xAwD2zrmAeEprqeB4Smup4HhJa6ngeMlrr+KyK01PWfKqOhTuaBYrNtqKuvQhxvn9uG+q8PFY7b7WP7x7qeB9TBLOt1PQ+Yg1nW63oeMAezrNf1POAObuF1Mg+Yg1t4ncMdsFDaHbBYOMwtm3ctwatvYYHDygKHwRKABQ6DIQELHO1DQlvgMBgSsMBhMSRggaN9SBBLdtgMCVjg+K9DAlgOCWA5JIDlkAA2Q4LTPiQ4JkMCrNcdx482/Gij5Whj8qMNP9rwow0/2nAcx7HjC8pg1fBM8ggRAAAAAElFTkSuQmCC" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<h1>"Icon0" - Should be equal to above, but black and no background</h1>
|
||||
<figure>
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAMFBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABaPxwLAAAAD3RSTlMAECAwT1Bgf4C/wM/Q7/B+lp4GAAABKUlEQVR4Ae3ZwUrDUBSEYXtsYhLNPe//tiIlNPCDm5lQCvMtD8pP6GbgfkREXKzuX/eyHqHW/rOW7wjz3g/77DpC7X3Yy3SEtZ9WzxGqz8pyhKnPJssRlj5bxOMLvuTa3wS2ftpMR6jRh1GmI83Hn43ZdqTaHh9b+vE/NS1TmY8Rrx4SROKQIFKHBJE6JIjkIUGkDgkieUgQyUMCbp+8iUOCje/Bijgk2OjeWVGHBBqs6EOCDVb0IcEGK/qQYIMVfUiwwYo+JNhgRceGqYLG5ZXbT8NgxF6xNlDRG1wCrLChDwlW2NCHBCtsyEMCFTbkIYEKG/KQQIUNeUigwsZ7DgnyDwnyDwnyDwnyDwnyDwnyDwny/3tEnjbytJGnjTxt5GkjTxvXioj4BeoMdgqOkiMwAAAAAElFTkSuQmCC" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="explicit-config-update" data-jdenticon-value="Icon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update()</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="explicit-config-drawIcon" data-jdenticon-value="Icon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> drawIcon()</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="explicit-config-jquery" data-jdenticon-value="Icon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> jQuery(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<span id="explicit-config-toSvg"></span>
|
||||
<figcaption><strong>SVG</strong> toSvg(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<h1>"Icon04" - Should be equal but different to the icon above</h1>
|
||||
<figure>
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAARVBMVEUAAP9tgO1thu1xiO50i+4xMYJAQGJDQ2RDQ11HR1ZHR1hLS1Cpx+RKSk+oxuSox+SqyeOqyuNLS01LS0xMTExZl8esy+PUIpVsAAAAFHRSTlMRKiotLi9bXGuIiMPDxMXN4uXw8Y2KdJAAAAGXSURBVHgB7JHbioNAEAVPLh11zewmY6///6lLWCTi1MjQkDfrsanyIKODAAcH5+/zx/PTY36cFAZzkOb4CuckgWa3r5tJeGzIQSo0G/3FaOIj5fsbpdZn/yf34iPn9Y1Ss+wL2VQ/ck4boI3+ZpT4yDlvgGa+xiQ+ck4bpHW+ppOER8633OeSu6TB1wyS8Mj5lsuzkJ6X9j/hHFZQan0TzmEFpeRvksRHznmFJJt8YTLxkfPaCkn9tHyuFx85r6+QZMlfJBMfOd9bQcm6oTMJjg05ruxLgZy0+EZ7fv25Kk4g/21Gcf7as2NUhYIwisErePvf7gPbbwrDKKKcdBaHILeYwP+FEvKgS5wLedAlzIE86BLmYh5ECXM458Hhq/r7gfMzPkVN4lx8VKPEuZgHUeL8/f/kk9/EPEgS52IeRIlzMQ+ixLmYB1HiXMyDKHEu0iW/9TJO0j98D4ki6SGRJT0kuqSHRJEsJBYSCwmR65AQuQ4JkeuQEGH+JHt+ZaeNnTZ22vjbaWOnjZ02dtrYaQNeNh9j/APLmwnC0xscngAAAABJRU5ErkJggg==" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon04" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-hash="f97deee25dde01afb80ec1c7e4fae746492ddacb" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-hash</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-update-hash" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-update-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-jquery-hash" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> jQuery(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-jquery-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> jQuery(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-drawIcon-hash" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> drawIcon(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-drawIcon-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> drawIcon(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<span id="placeholder-canvas-Jdenticon-dynamic"></span>
|
||||
<figcaption><strong>Canvas</strong> dynamic</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-resize" data-jdenticon-value="Icon04" width="10" height="10"></canvas>
|
||||
<figcaption><strong>Canvas</strong> resize</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<figure>
|
||||
<svg data-jdenticon-value="Icon04" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg data-jdenticon-hash="f97deee25dde01afb80ec1c7e4fae746492ddacb" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> data-jdenticon-hash</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-update-hash" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> update(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-update-value" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-jquery-hash" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> jQuery(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-jquery-value" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> jQuery(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<span id="svg-Jdenticon-toSvg-hash"></span>
|
||||
<figcaption><strong>SVG</strong> toSvg(hash)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<span id="svg-Jdenticon-toSvg-value"></span>
|
||||
<figcaption><strong>SVG</strong> toSvg(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<figure>
|
||||
<span id="placeholder-svg-Jdenticon-dynamic"></span>
|
||||
<figcaption><strong>SVG</strong> dynamic</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-resize" data-jdenticon-value="Icon04" width="10" height="10"></svg>
|
||||
<figcaption><strong>SVG</strong> resize</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<script>
|
||||
var jdenticon_config = {
|
||||
backColor: "#00f1",
|
||||
replaceMode: "observe"
|
||||
};
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/jquery/3.2.1/jquery.slim.min.js"></script>
|
||||
<script src="/node_modules/jdenticon/dist/jdenticon.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/require1k@1.0.1/require1k.min.js"></script>
|
||||
<script>
|
||||
// Explicit config
|
||||
setTimeout(function () {
|
||||
var explicitConfig = {
|
||||
lightness: {
|
||||
color: [0.00, 0.00],
|
||||
grayscale: [0.00, 0.00]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.00,
|
||||
grayscale: 0.00
|
||||
},
|
||||
padding: 0.08
|
||||
};
|
||||
jdenticon.update("#explicit-config-update", null, explicitConfig);
|
||||
var ctx = document.getElementById("explicit-config-drawIcon").getContext("2d");
|
||||
jdenticon.drawIcon(ctx, "Icon0", 100, explicitConfig);
|
||||
document.getElementById("explicit-config-toSvg").innerHTML =
|
||||
jdenticon.toSvg("Icon0", 100, explicitConfig);
|
||||
$("#explicit-config-jquery").jdenticon("Icon0", explicitConfig);
|
||||
});
|
||||
|
||||
// update()
|
||||
jdenticon.update("#canvas-Jdenticon-update-value,#svg-Jdenticon-update-value", "Icon04");
|
||||
jdenticon.update("#canvas-Jdenticon-update-hash,#svg-Jdenticon-update-hash", "f97deee25dde01afb80ec1c7e4fae746492ddacb");
|
||||
|
||||
// drawIcon()
|
||||
var ctx = document.getElementById("canvas-Jdenticon-drawIcon-value").getContext("2d");
|
||||
jdenticon.drawIcon(ctx, "Icon04", 100, 0.08);
|
||||
|
||||
var ctx = document.getElementById("canvas-Jdenticon-drawIcon-hash").getContext("2d");
|
||||
jdenticon.drawIcon(ctx, "f97deee25dde01afb80ec1c7e4fae746492ddacb", 100, 0.08);
|
||||
|
||||
// toSvg()
|
||||
document.getElementById("svg-Jdenticon-toSvg-value").innerHTML =
|
||||
jdenticon.toSvg("Icon04", 100);
|
||||
|
||||
document.getElementById("svg-Jdenticon-toSvg-hash").innerHTML =
|
||||
jdenticon.toSvg("f97deee25dde01afb80ec1c7e4fae746492ddacb", 100);
|
||||
|
||||
// jQuery
|
||||
$("#canvas-Jdenticon-jquery-value,#svg-Jdenticon-jquery-value").jdenticon("Icon04");
|
||||
$("#canvas-Jdenticon-jquery-hash,#svg-Jdenticon-jquery-hash").jdenticon("f97deee25dde01afb80ec1c7e4fae746492ddacb");
|
||||
|
||||
// Dynamic icons
|
||||
setTimeout(function () {
|
||||
// Canvas
|
||||
document.getElementById("placeholder-canvas-Jdenticon-dynamic").innerHTML =
|
||||
'<canvas data-jdenticon-value="Icon04" width="100" height="100"> Error </canvas>';
|
||||
document.getElementById("canvas-Jdenticon-resize").setAttribute("width", "100");
|
||||
document.getElementById("canvas-Jdenticon-resize").setAttribute("height", "100");
|
||||
|
||||
// Svg
|
||||
document.getElementById("placeholder-svg-Jdenticon-dynamic").innerHTML =
|
||||
'<svg data-jdenticon-value="Icon04" width="100" height="100"> Error </svg>';
|
||||
document.getElementById("svg-Jdenticon-resize").setAttribute("width", "100");
|
||||
document.getElementById("svg-Jdenticon-resize").setAttribute("height", "100");
|
||||
}, 1000);
|
||||
</script>
|
||||
<script src="common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
97
jdenticon-js/test/e2e/browser/assets/padding.html
Normal file
@@ -0,0 +1,97 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>"Icon04" - Should be equal - <span id="padding-percent"></span>% padding in style</h1>
|
||||
<figure class="padding-0-only">
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAUVBMVEUAAP8fH6JtgPNrgu1vhe5yiO81NXE4OGU/P1RCQlJBQVJCQk1DQ05ERExDQ0xERElEREqoxuSoxuSox+SqyeOqyeJFRUZFRUZGRkZZl8esy+Mq/AT0AAAAGHRSTlMSISorLi8/TnqIiaantbbExMTFzeLm8PFg+1g3AAABrUlEQVR4AazS2W6DMBQG4XEW0yQsTZsEyvs/aJEqy0AzF5b8337SHLGw2vHrSJ156vCYHwfKZymBucIVSWWocEVSGYTi5fZ5u0RwsJTAPwrd9Lcu4GApgR01rynt1eBgKYENhSWVYwEHT2UQ6qb1OjDwVAahOG0XwcBTCYS47lofgIGnBNKVdtdqARQ8dZ/f7w4w7FoDgIKnTs+38DyVP4mnFhIo/yaeWkig9O+SVCIB6DepHhwsJZSBMK5SY8DBU5kEaHJsbHDw1JoECOnF9AEHTe1IAOK1HdprBAdLCWUomaSEatyQVCKB8nmK8/eZGitI/RTvtz07RmEYBqAYev9bt1uXPgIaTDDfYweJYkME36wmmeSXalUCFFItS4ByqhUJUE61IgHKqfb/Ovnb9wClj2mTAKUsaBKgFDhNApRSrUmAOvBPjtzJkdflVGsSoJBqUQIUUi1KgEKqRQlQSLUoIcqnSxYSk7xK0p+w4y5IStwFSYi7IAlx1ySLu8Xd4u6CuHs+Le6CJMRdkIS4SxKiFhLvlWyW3Sy7WXaz7GbZzbKbZTfLbpa9YJb9AArjwlhWWmFfAAAAAElFTkSuQmCC" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure class="padding-30-only">
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAJ1BMVEUAAP8wMIU4OGc4OGU+PlibteekwuOlwuRFRUZFRUZGRkZZl8esy+M8HoHgAAAACnRSTlMSME1Oa2ump/DxPobHuQAAANNJREFUeAHt1sEKgzAQhGFjklqN7/+8tSV1PCx42D0E+b+LCwO7IAxkwvMBAAAA9XWX+tV973vSPCdNSkNu9D1lOxRNSgNu9D1p+3onTUr9N/qevP3kSZPSmCOLeURpxJXl/5PWpOmSOtVzS1mPzeU6KfWq55aUc7pOSv3qcpPGaYYphtrdDEpd1O5mUOqidp9/R9+m1EPFM48oHf6I2m0eUeqhdptHlDqo3fYRpaOVcYDG278rtPH2ERr//MYb4htvGLLxvOp51fOq51U/PgAAAAAfGl0flQBGOTMAAAAASUVORK5CYII=" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon04" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-update-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-jquery-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> jQuery(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas id="canvas-Jdenticon-drawIcon-value" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> drawIcon(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<figure>
|
||||
<svg data-jdenticon-value="Icon04" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> data-jdenticon-value</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-update-value" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> update(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<svg id="svg-Jdenticon-jquery-value" width="100" height="100"></svg>
|
||||
<figcaption><strong>SVG</strong> jQuery(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<span id="svg-Jdenticon-toSvg-value"></span>
|
||||
<figcaption><strong>SVG</strong> toSvg(value)</figcaption>
|
||||
</figure>
|
||||
|
||||
|
||||
<script>
|
||||
var padding = 0;
|
||||
|
||||
// Load padding from query string
|
||||
var match = /\?padding=(\d+)/.exec(location.href);
|
||||
if (match) {
|
||||
padding = Number(match[1]);
|
||||
}
|
||||
|
||||
document.getElementById("padding-percent").innerHTML = padding;
|
||||
|
||||
var className = document.body.className;
|
||||
document.body.className = (className ? className + " " : "") + "padding-" + padding;
|
||||
|
||||
var jdenticon_config = {
|
||||
padding: padding / 100,
|
||||
backColor: "#00f1",
|
||||
};
|
||||
</script>
|
||||
<script src="https://cdn.jsdelivr.net/jquery/3.2.1/jquery.slim.min.js"></script>
|
||||
<script src="/node_modules/jdenticon/dist/jdenticon.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/require1k@1.0.1/require1k.min.js"></script>
|
||||
<script>
|
||||
jdenticon.update("#canvas-Jdenticon-update-value,#svg-Jdenticon-update-value", "Icon04");
|
||||
|
||||
var ctx = document.getElementById("canvas-Jdenticon-drawIcon-value").getContext("2d");
|
||||
jdenticon.drawIcon(ctx, "Icon04", 100);
|
||||
|
||||
document.getElementById("svg-Jdenticon-toSvg-value").innerHTML =
|
||||
jdenticon.toSvg("Icon04", 100);
|
||||
|
||||
$("#canvas-Jdenticon-jquery-value,#svg-Jdenticon-jquery-value").jdenticon("Icon04");
|
||||
</script>
|
||||
<script src="common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
64
jdenticon-js/test/e2e/browser/assets/styles.css
Normal file
@@ -0,0 +1,64 @@
|
||||
html {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font: bold 16px Arial;
|
||||
margin: 30px 0 15px;
|
||||
}
|
||||
|
||||
h1:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.test-metadata {
|
||||
font: 14px Arial;
|
||||
margin: 0 0 1em;
|
||||
min-height: 4em;
|
||||
background: #C1D1EA;
|
||||
padding: 10px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.jdenticon-info {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
canvas,
|
||||
svg,
|
||||
img {
|
||||
border: 6px solid #444;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
figure {
|
||||
width: 116px;
|
||||
font: 10px Arial;
|
||||
margin: 0 10px 16px 0;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
figure strong {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.padding-0 .padding-30-only,
|
||||
.padding-30 .padding-0-only {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
iframe {
|
||||
border: none;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
margin: 0 -20px;
|
||||
}
|
||||
26
jdenticon-js/test/e2e/browser/assets/umd-in-head.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jdenticon</title>
|
||||
<link rel="stylesheet" type="text/css" href="styles.css">
|
||||
<script>
|
||||
var jdenticon_config = {
|
||||
backColor: "#00f1"
|
||||
};
|
||||
</script>
|
||||
<script src="/node_modules/jdenticon/dist/jdenticon.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>"Icon0" - UMD in <head> - Should be equal</h1>
|
||||
<figure>
|
||||
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAWlBMVEUAAP9aOuYxMYKdne+CXN5AQGLHx+lDQ2TIyOlDQ13NzedHR1ZHR1jW1ufY2OdLS1Dg4OVKSk/g4OWjc9Gjc9FLS02ldNDj4+RLS0yldNDj4+VMTEymddHl5eU2yqFLAAAAG3RSTlMRHy8vPVtbXFxra4iIiIjDw8TE0tPw8PDx8fEmYw1hAAABrUlEQVR42u2ZYWvCQBBE6542UVuT2Kaxnvf//2aR45hrl2mgxyKFfR+HjM9EggP35DiOY0x4fn0OP0PZveyEhLTOFWO6M367ToZ4ZxAe6jrnsKTMckC4n2Nm3tNQ1ylhSYUllFDmWJiFhrrOGBMYSzhEMNBQ1wkh1YQcSqwRErK6pk81fQ67WNORkNU1p1RzyuEx1hxJSOrmd/KA3wScEziXcIpgoqGuM8I1Fa54Ty6xcBEa6jrlcC0X1W/8pXzcnoe6zgnnfLOhDmXKj0VISOtc0596dY10x05oqOuO8xAwD2zrmAeEprqeB4Smup4HhJa6ngeMlrr+KyK01PWfKqOhTuaBYrNtqKuvQhxvn9uG+q8PFY7b7WP7x7qeB9TBLOt1PQ+Yg1nW63oeMAezrNf1POAObuF1Mg+Yg1t4ncMdsFDaHbBYOMwtm3ctwatvYYHDygKHwRKABQ6DIQELHO1DQlvgMBgSsMBhMSRggaN9SBBLdtgMCVjg+K9DAlgOCWA5JIDlkAA2Q4LTPiQ4JkMCrNcdx482/Gij5Whj8qMNP9rwow0/2nAcx7HjC8pg1fBM8ggRAAAAAElFTkSuQmCC" width="100" height="100">
|
||||
<figcaption><strong>IMG</strong> static image</figcaption>
|
||||
</figure>
|
||||
|
||||
<figure>
|
||||
<canvas data-jdenticon-value="Icon0" width="100" height="100"></canvas>
|
||||
<figcaption><strong>Canvas</strong> UMD in <head></figcaption>
|
||||
</figure>
|
||||
<script src="common.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
BIN
jdenticon-js/test/e2e/browser/expected/macos-chrome.png
Normal file
|
After Width: | Height: | Size: 343 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/macos-firefox.png
Normal file
|
After Width: | Height: | Size: 372 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/macos-safari.png
Normal file
|
After Width: | Height: | Size: 389 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-bs1.png
Normal file
|
After Width: | Height: | Size: 185 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-bs2.png
Normal file
|
After Width: | Height: | Size: 185 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-bs3.png
Normal file
|
After Width: | Height: | Size: 185 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-chrome.png
Normal file
|
After Width: | Height: | Size: 309 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-edge.png
Normal file
|
After Width: | Height: | Size: 311 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-firefox.png
Normal file
|
After Width: | Height: | Size: 303 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-ie10.png
Normal file
|
After Width: | Height: | Size: 311 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-ie11.png
Normal file
|
After Width: | Height: | Size: 320 KiB |
BIN
jdenticon-js/test/e2e/browser/expected/win-ie9.png
Normal file
|
After Width: | Height: | Size: 312 KiB |
45
jdenticon-js/test/e2e/browser/screenshooter.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const { PNG } = require("pngjs");
|
||||
|
||||
async function screenshot(driver) {
|
||||
var dimensions = await driver.executeScript(`return {
|
||||
scrollWidth: document.body.offsetWidth,
|
||||
scrollHeight: document.body.offsetHeight,
|
||||
innerWidth: window.innerWidth || document.documentElement.clientWidth,
|
||||
innerHeight: window.innerHeight || document.documentElement.clientHeight
|
||||
}`);
|
||||
|
||||
const combinedImage = new PNG({
|
||||
width: dimensions.scrollWidth,
|
||||
height: dimensions.scrollHeight
|
||||
});
|
||||
|
||||
const xnum = Math.ceil(dimensions.scrollWidth / dimensions.innerWidth);
|
||||
const ynum = Math.ceil(dimensions.scrollHeight / dimensions.innerHeight);
|
||||
|
||||
for (let x = 0; x < xnum; x++) {
|
||||
for (let y = 0; y < ynum; y++) {
|
||||
|
||||
var scrollpos = await driver.executeScript(`
|
||||
window.scrollTo(${x * dimensions.innerWidth}, ${y * dimensions.innerHeight});
|
||||
return { x: window.scrollX || window.pageXOffset, y: window.scrollY || window.pageYOffset }`)
|
||||
|
||||
// Delay for Safari
|
||||
await driver.sleep(500);
|
||||
|
||||
const datauri = await driver.takeScreenshot();
|
||||
const image = PNG.sync.read(Buffer.from(datauri, "base64"));
|
||||
|
||||
PNG.bitblt(image, combinedImage,
|
||||
0, 0,
|
||||
Math.min(image.width, combinedImage.width - scrollpos.x),
|
||||
Math.min(image.height, combinedImage.height - scrollpos.y),
|
||||
scrollpos.x,
|
||||
scrollpos.y);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return PNG.sync.write(combinedImage);
|
||||
}
|
||||
|
||||
module.exports = screenshot;
|
||||
187
jdenticon-js/test/e2e/browser/test.js
Normal file
@@ -0,0 +1,187 @@
|
||||
const express = require("express");
|
||||
const fs = require("fs");
|
||||
const tap = require("tap");
|
||||
const webdriver = require("selenium-webdriver");
|
||||
const screenshot = require("./screenshooter");
|
||||
const BlinkDiff = require("blink-diff");
|
||||
const path = require("path");
|
||||
|
||||
// Command line arguments examples:
|
||||
// node test.js win ie11,chrome
|
||||
// node test.js macos safari,chrome,firefox
|
||||
|
||||
const environmentId = process.argv[2] || "";
|
||||
const enabledBrowsers = (process.argv[3] || "").split(/[,;]/g).filter(name => name);
|
||||
|
||||
if (!enabledBrowsers.length) {
|
||||
throw new Error("Expected browser names");
|
||||
}
|
||||
|
||||
const screenshotDir = process.env.BROWSER_SCREENSHOT_DIR || path.join(__dirname, "artifacts/screenshots");
|
||||
const diffDir = process.env.BROWSER_DIFF_DIR || path.join(__dirname, "artifacts/diffs");
|
||||
const expectedDir = process.env.BROWSER_EXPECTED_DIR || path.join(__dirname, "expected");
|
||||
|
||||
// fs.mkdirSync(_ , { recursive: true }) did not work on GitHub Actions using Node v12.18.2 (Windows and macOS).
|
||||
// Worked fine locally however. Replacing it with a custom recursive implementation.
|
||||
// Ignored GitHub issue for tracking any status:
|
||||
// https://github.com/nodejs/node/issues/27293
|
||||
function mkdirRecursive(dirPath) {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
const parent = path.dirname(dirPath)
|
||||
if (parent && parent !== dirPath) {
|
||||
mkdirRecursive(parent);
|
||||
}
|
||||
fs.mkdirSync(dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
mkdirRecursive(screenshotDir);
|
||||
mkdirRecursive(diffDir);
|
||||
|
||||
const BROWSER_DEFINITIONS = [
|
||||
{
|
||||
name: "ie11",
|
||||
uaCompatible: "IE=Edge",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.INTERNET_EXPLORER,
|
||||
"ie.ensureCleanSession": true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ie10",
|
||||
uaCompatible: "IE=10",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.INTERNET_EXPLORER,
|
||||
"ie.ensureCleanSession": true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ie9",
|
||||
uaCompatible: "IE=9",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.INTERNET_EXPLORER,
|
||||
"ie.ensureCleanSession": true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "firefox",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.FIREFOX,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "chrome",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.CHROME,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "edge",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.EDGE,
|
||||
"ms:edgeChromium": true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "safari",
|
||||
capabilities: {
|
||||
"browserName": webdriver.Browser.SAFARI,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
async function serve(root, options, asyncCallback) {
|
||||
const app = express();
|
||||
|
||||
app.use(express.static(root, options));
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
const listener = app.listen(async () => {
|
||||
try {
|
||||
await asyncCallback(listener);
|
||||
resolve();
|
||||
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
||||
} finally {
|
||||
listener.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function testBrowser(browserName) {
|
||||
const browser = BROWSER_DEFINITIONS.find(x => x.name === browserName);
|
||||
await tap.test(browserName, async t => {
|
||||
if (!browser) {
|
||||
t.fail(`Could not find a browser with the name ${browserName}.`);
|
||||
return;
|
||||
}
|
||||
|
||||
await serve(
|
||||
path.join(__dirname, "../../"),
|
||||
{
|
||||
"index": ["index.html"],
|
||||
setHeaders: resp => {
|
||||
// Prevent stale files
|
||||
resp.setHeader("Cache-Control", "no-store");
|
||||
|
||||
if (browser.uaCompatible) {
|
||||
resp.setHeader("X-UA-Compatible", browser.uaCompatible);
|
||||
}
|
||||
}
|
||||
},
|
||||
async listener => {
|
||||
const url = "http://localhost:" + listener.address().port + "/e2e/browser/assets/";
|
||||
|
||||
console.log(`Screenshot in ${browserName}`);
|
||||
console.log(url);
|
||||
|
||||
const driver = await new webdriver.Builder()
|
||||
.withCapabilities(browser.capabilities)
|
||||
.build();
|
||||
|
||||
await driver.manage().window().setRect({ width: 1000, height: 2000 });
|
||||
|
||||
const documentInitialised = () => driver.executeScript("return true");
|
||||
|
||||
try {
|
||||
await driver.get(url);
|
||||
await driver.wait(() => documentInitialised(), 10000);
|
||||
await driver.sleep(2500);
|
||||
|
||||
const screenshotBuffer = await screenshot(driver);
|
||||
fs.writeFileSync(path.join(screenshotDir, `${environmentId}-${browserName}.png`), screenshotBuffer);
|
||||
|
||||
} finally {
|
||||
await driver.quit();
|
||||
}
|
||||
|
||||
var diff = new BlinkDiff({
|
||||
imageAPath: path.join(expectedDir, `${environmentId}-${browserName}.png`),
|
||||
imageBPath: path.join(screenshotDir, `${environmentId}-${browserName}.png`),
|
||||
|
||||
thresholdType: BlinkDiff.THRESHOLD_PIXEL,
|
||||
threshold: 1000,
|
||||
|
||||
imageOutputPath: path.join(diffDir, `${environmentId}-${browserName}.png`),
|
||||
|
||||
// Ignore test metadata area containing browser versions etc.
|
||||
blockOut: [{ x: 0, y: 0, width: 20000, height: 100 }],
|
||||
});
|
||||
|
||||
const diffResult = await diff.runWithPromise();
|
||||
t.ok(diff.hasPassed(diffResult.code), `Found ${diffResult.differences} differences.`);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function testBrowsers(enabledBrowsers) {
|
||||
for (var i = 0; i < enabledBrowsers.length; i++) {
|
||||
await testBrowser(enabledBrowsers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
testBrowsers(enabledBrowsers);
|
||||
46
jdenticon-js/test/e2e/node/base.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const tap = require("tap");
|
||||
const canvasRenderer = require("canvas-renderer");
|
||||
const iconTest = require("./icons");
|
||||
|
||||
// The user might have modified the native object prototypes.
|
||||
// It should not break Jdenticon.
|
||||
Object.prototype.somethingOdd = function() {};
|
||||
Object.prototype.nothing = null;
|
||||
Object.prototype.anEmptyObject = {};
|
||||
|
||||
function testNode(jdenticon) {
|
||||
tap.test("jdenticon.version", t => {
|
||||
t.match(jdenticon.version, /^\d+(\.\d+)*$/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.configure", t => {
|
||||
t.doesNotThrow(() => jdenticon.configure({ backColor: "#fff" }));
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.drawIcon", t => {
|
||||
t.doesNotThrow(() => jdenticon.drawIcon(canvasRenderer.createCanvas(100, 100).getContext("2d"), "Icon1", 100));
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.toPng", t => {
|
||||
t.type(jdenticon.toPng("Icon1", 100), Buffer);
|
||||
iconTest(jdenticon);
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.toSvg", t => {
|
||||
t.match(jdenticon.toSvg("Icon1", 100), /^<svg/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.update*", t => {
|
||||
t.throws(() => jdenticon.update(), "jdenticon.update() is not supported on Node.js.");
|
||||
t.throws(() => jdenticon.updateCanvas(), "jdenticon.updateCanvas() is not supported on Node.js.");
|
||||
t.throws(() => jdenticon.updateSvg(), "jdenticon.updateSvg() is not supported on Node.js.");
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = testNode;
|
||||
BIN
jdenticon-js/test/e2e/node/expected/39.png
Normal file
|
After Width: | Height: | Size: 605 B |
1
jdenticon-js/test/e2e/node/expected/39.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50"><rect width="100%" height="100%" fill="#ffffff" opacity="1.00"/><path fill="#e7e7cf" d="M16.7 10a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M26.7 10a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M26.7 40a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M16.7 40a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M6.7 20a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M36.7 20a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M36.7 30a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0M6.7 30a3.3,3.3 0 1,1 6.7,0a3.3,3.3 0 1,1 -6.7,0"/><path fill="#000000" d="M5 5L15 5L15 10ZM45 5L45 15L40 15ZM45 45L35 45L35 40ZM5 45L5 35L10 35Z"/><path fill="#d5d5ab" d="M15 15L25 15L25 25L15 25ZM18.6 21.2a2.6,2.6 0 1,0 5.2,0a2.6,2.6 0 1,0 -5.2,0M35 15L35 25L25 25L25 15ZM26.2 21.2a2.6,2.6 0 1,0 5.2,0a2.6,2.6 0 1,0 -5.2,0M35 35L25 35L25 25L35 25ZM26.2 28.8a2.6,2.6 0 1,0 5.2,0a2.6,2.6 0 1,0 -5.2,0M15 35L15 25L25 25L25 35ZM18.6 28.8a2.6,2.6 0 1,0 5.2,0a2.6,2.6 0 1,0 -5.2,0"/></svg>
|
||||
|
After Width: | Height: | Size: 998 B |
BIN
jdenticon-js/test/e2e/node/expected/50.png
Normal file
|
After Width: | Height: | Size: 580 B |
1
jdenticon-js/test/e2e/node/expected/50.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50"><rect width="100%" height="100%" fill="#ffffff" opacity="1.00"/><path fill="#e3e3e3" d="M15 5L25 5L25 15ZM35 5L35 15L25 15ZM35 45L25 45L25 35ZM15 45L15 35L25 35ZM5 15L15 15L15 25ZM45 15L45 25L35 25ZM45 35L35 35L35 25ZM5 35L5 25L15 25Z"/><path fill="#464646" d="M15 10L10 15L5 10L10 5ZM40 15L35 10L40 5L45 10ZM35 40L40 35L45 40L40 45ZM10 35L15 40L10 45L5 40Z"/><path fill="#59c7bf" d="M25 15L25 23L20 15ZM35 25L27 25L35 20ZM25 35L25 27L30 35ZM15 25L23 25L15 30Z"/></svg>
|
||||
|
After Width: | Height: | Size: 552 B |
BIN
jdenticon-js/test/e2e/node/expected/73.png
Normal file
|
After Width: | Height: | Size: 446 B |
1
jdenticon-js/test/e2e/node/expected/73.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50"><rect width="100%" height="100%" fill="#ffffff" opacity="1.00"/><path fill="#4c4c4c" d="M25 10L20 15L15 10L20 5ZM30 15L25 10L30 5L35 10ZM25 40L30 35L35 40L30 45ZM20 35L25 40L20 45L15 40ZM15 20L10 25L5 20L10 15ZM40 25L35 20L40 15L45 20ZM35 30L40 25L45 30L40 35ZM10 25L15 30L10 35L5 30Z"/><path fill="#e5e5e5" d="M5 15L5 5L10 5ZM35 5L45 5L45 10ZM45 35L45 45L40 45ZM15 45L5 45L5 40Z"/><path fill="#cca766" d="M15 15L25 15L25 25L15 25ZM21.5 24L24 19L19 19ZM35 15L35 25L25 25L25 15ZM26 21.5L31 24L31 19ZM35 35L25 35L25 25L35 25ZM28.5 26L26 31L31 31ZM15 35L15 25L25 25L25 35ZM24 28.5L19 26L19 31Z"/></svg>
|
||||
|
After Width: | Height: | Size: 682 B |
BIN
jdenticon-js/test/e2e/node/expected/76.png
Normal file
|
After Width: | Height: | Size: 494 B |
1
jdenticon-js/test/e2e/node/expected/76.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50"><rect width="100%" height="100%" fill="#000000" opacity="0.16"/><path fill="#c36262" d="M15 5L25 5L25 15ZM35 5L35 15L25 15ZM35 45L25 45L25 35ZM15 45L15 35L25 35ZM5 15L15 15L15 25ZM45 15L45 25L35 25ZM45 35L35 35L35 25ZM5 35L5 25L15 25Z"/><path fill="#a63f3f" d="M15 15L5 15L5 10ZM35 15L35 5L40 5ZM35 35L45 35L45 40ZM15 35L15 45L10 45ZM15 15L25 15L25 25L15 25ZM21.5 24L24 19L19 19ZM35 15L35 25L25 25L25 15ZM26 21.5L31 24L31 19ZM35 35L25 35L25 25L35 25ZM28.5 26L26 31L31 31ZM15 35L15 25L25 25L25 35ZM24 28.5L19 26L19 31Z"/></svg>
|
||||
|
After Width: | Height: | Size: 609 B |
97
jdenticon-js/test/e2e/node/icons.js
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const tap = require("tap");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { PNG } = require("pngjs");
|
||||
|
||||
const expectedDir = path.join(__dirname, "expected");
|
||||
|
||||
function equal(obj1, obj2) {
|
||||
try {
|
||||
assert.deepStrictEqual(obj1, obj2);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function test(jdenticon, icon, style) {
|
||||
jdenticon.configure(style);
|
||||
|
||||
// PNG
|
||||
{
|
||||
const actual = jdenticon.toPng(icon, 50);
|
||||
const expected = fs.readFileSync(path.join(expectedDir, icon +".png"));
|
||||
|
||||
const actualDecoded = PNG.sync.read(actual);
|
||||
const expectedDecoded = PNG.sync.read(expected);
|
||||
|
||||
if (!equal(actualDecoded, expectedDecoded)) {
|
||||
actualDecoded.data = "...";
|
||||
expectedDecoded.data = "...";
|
||||
fs.writeFileSync(path.join(expectedDir, icon +".metadata.json"), JSON.stringify(expectedDecoded, undefined, 2));
|
||||
fs.writeFileSync(path.join(expectedDir, icon +"-actual.metadata.json"), JSON.stringify(actualDecoded, undefined, 2));
|
||||
fs.writeFileSync(path.join(expectedDir, icon +"-actual.png"), actual);
|
||||
tap.ok(false, "Icon '" + icon + "' failed PNG test.");
|
||||
}
|
||||
else {
|
||||
tap.ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
// SVG
|
||||
{
|
||||
const actual = jdenticon.toSvg(icon, 50);
|
||||
const expected = fs.readFileSync(path.join(expectedDir, icon +".svg"));
|
||||
|
||||
if (actual !== expected.toString()) {
|
||||
fs.writeFileSync(path.join(expectedDir, icon + "-actual.svg"), actual);
|
||||
tap.ok(false, "Icon '" + icon + "' failed SVG test.");
|
||||
console.log(expected.toString());
|
||||
console.log(actual);
|
||||
}
|
||||
else {
|
||||
tap.ok(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testIcons(jdenticon) {
|
||||
test(jdenticon, 73, {
|
||||
backColor: "#fff"
|
||||
});
|
||||
|
||||
test(jdenticon, 76, {
|
||||
hues: [ 134 /*green*/, 0 /*red*/, 60 /*yellow*/ ],
|
||||
lightness: {
|
||||
color: [0.29, 0.53],
|
||||
grayscale: [0.19, 0.40]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.45,
|
||||
grayscale: 0.72
|
||||
},
|
||||
backColor: "#0000002a"
|
||||
});
|
||||
|
||||
test(jdenticon, 39, {
|
||||
hues: [ 134 /*green*/, 0 /*red*/, 60 /*yellow*/ ],
|
||||
lightness: {
|
||||
color: [0.65, 0.86],
|
||||
grayscale: [0.00, 1.00]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.34,
|
||||
grayscale: 0.10
|
||||
},
|
||||
backColor: "#ffffffff"
|
||||
});
|
||||
|
||||
test(jdenticon, 50, {
|
||||
backColor: "#fff"
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = testIcons;
|
||||
30
jdenticon-js/test/e2e/node/test.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const tap = require("tap");
|
||||
const jdenticon = require("jdenticon");
|
||||
const baseNode = require("./base");
|
||||
|
||||
tap.test("jdenticon.bundle", t => {
|
||||
t.equal(jdenticon.bundle, "node-cjs");
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test("jdenticon.config", t => {
|
||||
const originalConsoleWarn = console.warn;
|
||||
const warn = [];
|
||||
|
||||
console.warn = function () {
|
||||
warn.push(Array.prototype.join.call(arguments, ""));
|
||||
}
|
||||
|
||||
try {
|
||||
jdenticon.config = {};
|
||||
} finally {
|
||||
console.warn = originalConsoleWarn;
|
||||
}
|
||||
|
||||
t.same(warn, ["jdenticon.config is deprecated. Use jdenticon.configure() instead."]);
|
||||
t.end();
|
||||
});
|
||||
|
||||
baseNode(jdenticon);
|
||||
|
||||
|
||||
11
jdenticon-js/test/e2e/node/test.mjs
Normal file
@@ -0,0 +1,11 @@
|
||||
import tap from "tap";
|
||||
import { bundle } from "jdenticon";
|
||||
import * as jdenticon from "jdenticon";
|
||||
import baseNode from "./base.js";
|
||||
|
||||
tap.test("jdenticon.bundle", t => {
|
||||
t.equal(bundle, "node-esm");
|
||||
t.end();
|
||||
});
|
||||
|
||||
baseNode(jdenticon);
|
||||
13
jdenticon-js/test/e2e/rollup/app.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { testBrowser } from "../base-browser-test";
|
||||
|
||||
import * as jdenticonEsm from "jdenticon";
|
||||
testBrowser(jdenticonEsm, "browser-esm");
|
||||
|
||||
import * as jdenticonEsmBrowser from "jdenticon/browser";
|
||||
testBrowser(jdenticonEsmBrowser, "browser-esm");
|
||||
|
||||
import * as jdenticonEsmNode from "jdenticon/node";
|
||||
testBrowser(jdenticonEsmNode, "node-esm");
|
||||
|
||||
import * as jdenticonUmd from "jdenticon/standalone";
|
||||
testBrowser(jdenticonUmd, "browser-umd");
|
||||
22
jdenticon-js/test/e2e/rollup/rollup.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||
import commonjs from "@rollup/plugin-commonjs";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
|
||||
export default {
|
||||
input: "./app.js",
|
||||
output: {
|
||||
file: "./app.bundle.js",
|
||||
format: "iife",
|
||||
globals: {
|
||||
"canvas-renderer": "{}",
|
||||
},
|
||||
},
|
||||
external: ["canvas-renderer"],
|
||||
plugins: [
|
||||
commonjs(),
|
||||
nodeResolve({
|
||||
browser: true,
|
||||
}),
|
||||
terser(),
|
||||
],
|
||||
};
|
||||
13
jdenticon-js/test/e2e/webpack/app.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { testBrowser } from "../base-browser-test";
|
||||
|
||||
import * as jdenticonEsm from "jdenticon";
|
||||
testBrowser(jdenticonEsm, "browser-esm");
|
||||
|
||||
import * as jdenticonEsmBrowser from "jdenticon/browser";
|
||||
testBrowser(jdenticonEsmBrowser, "browser-esm");
|
||||
|
||||
import * as jdenticonEsmNode from "jdenticon/node";
|
||||
testBrowser(jdenticonEsmNode, "node-esm");
|
||||
|
||||
import * as jdenticonUmd from "jdenticon/standalone";
|
||||
testBrowser(jdenticonUmd, "browser-umd");
|
||||
40
jdenticon-js/test/e2e/webpack/runner.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const process = require("process");
|
||||
const config = require("./webpack.config");
|
||||
const moduleAlias = require("module-alias");
|
||||
const webpackPackageName = process.argv[2];
|
||||
|
||||
// This file is used instead of webpack-cli to allow testing with multiple webpack versions
|
||||
|
||||
if (!webpackPackageName) {
|
||||
console.error("Usage: node runner.js (webpack4|webpack5)");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!/^webpack\d+$/.test(webpackPackageName)) {
|
||||
console.error("Invalid webpack package name specified");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
// The terser plugin in webpack4 imports "webpack/lib/RequestShortener", so we can't require the right webpack module
|
||||
// name and use it straight away. By using module-alias we make "webpack" requirable.
|
||||
moduleAlias.addAlias("webpack", webpackPackageName);
|
||||
|
||||
const webpack = require("webpack");
|
||||
|
||||
webpack(config, (err, stats) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(3);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(stats.toString({
|
||||
colors: true
|
||||
}));
|
||||
|
||||
console.log("---");
|
||||
|
||||
if (stats.hasErrors()) {
|
||||
process.exit(4);
|
||||
}
|
||||
});
|
||||
33
jdenticon-js/test/e2e/webpack/webpack.config.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
entry: path.join(__dirname, "app.js"),
|
||||
externals: {
|
||||
"tap": "commonjs tap",
|
||||
"canvas-renderer": "commonjs canvas-renderer"
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.mjs$/,
|
||||
enforce: 'pre',
|
||||
use: ['source-map-loader'],
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
enforce: 'pre',
|
||||
use: ['source-map-loader'],
|
||||
},
|
||||
],
|
||||
},
|
||||
stats: {
|
||||
warningsFilter: [/Failed to parse source map/],
|
||||
},
|
||||
devtool: "source-map",
|
||||
|
||||
output: {
|
||||
path: __dirname,
|
||||
filename: "app.bundle.js",
|
||||
},
|
||||
}
|
||||
5
jdenticon-js/test/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "jdenticon-test",
|
||||
"version": "1.0.0",
|
||||
"private": true
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { configure, drawIcon, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/browser";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
window.jdenticon_config = oldConfig;
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
toPng("value to hash", 100, newConfig);
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
var el = document.createElement("canvas");
|
||||
update(el, "value");
|
||||
update(el, "value", 0.08);
|
||||
update(el, "value", newConfig);
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
var ctx = el.getContext("2d");
|
||||
if (ctx) {
|
||||
drawIcon(ctx, "value", 100);
|
||||
drawIcon(ctx, "value", 100, 0.08);
|
||||
drawIcon(ctx, "value", 100, newConfig);
|
||||
}
|
||||
|
||||
// Ensure Jdenticon dodn't leak Node typings.
|
||||
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
|
||||
const timeoutRef: number = setTimeout(() => { }, 100);
|
||||
59
jdenticon-js/test/types/module-browser/module-test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { configure, drawIcon, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
window.jdenticon_config = oldConfig;
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
toPng("value to hash", 100, newConfig);
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
var el = document.createElement("canvas");
|
||||
update(el, "value");
|
||||
update(el, "value", 0.08);
|
||||
update(el, "value", newConfig);
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
var ctx = el.getContext("2d");
|
||||
if (ctx) {
|
||||
drawIcon(ctx, "value", 100);
|
||||
drawIcon(ctx, "value", 100, 0.08);
|
||||
drawIcon(ctx, "value", 100, newConfig);
|
||||
}
|
||||
|
||||
// Ensure Jdenticon dodn't leak Node typings.
|
||||
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
|
||||
const timeoutRef: number = setTimeout(() => { }, 100);
|
||||
10
jdenticon-js/test/types/module-browser/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": [],
|
||||
"lib": ["es6", "dom"],
|
||||
},
|
||||
"include": [
|
||||
"./*.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/node";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
const buffer: Buffer = toPng("value to hash", 100, newConfig);
|
||||
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
// Check that Node typings are loaded
|
||||
buffer.swap64();
|
||||
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
47
jdenticon-js/test/types/module-node14/module-test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
const buffer: Buffer = toPng("value to hash", 100, newConfig);
|
||||
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
// Check that Node typings are loaded
|
||||
buffer.swap64();
|
||||
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
10
jdenticon-js/test/types/module-node14/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": [ "node14" ],
|
||||
"lib": [ "es6" ],
|
||||
},
|
||||
"include": [
|
||||
"./*.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon/node";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
const buffer: Buffer = toPng("value to hash", 100, newConfig);
|
||||
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
// Check that Node typings are loaded
|
||||
buffer.swap64();
|
||||
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
47
jdenticon-js/test/types/module-node16/module-test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { configure, update, updateSvg, updateCanvas, toPng, toSvg, JdenticonConfig } from "jdenticon";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
const buffer: Buffer = toPng("value to hash", 100, newConfig);
|
||||
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
// Check that Node typings are loaded
|
||||
buffer.swap64();
|
||||
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
10
jdenticon-js/test/types/module-node16/tsconfig.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": [ "node16" ],
|
||||
"lib": [ "es6" ],
|
||||
},
|
||||
"include": [
|
||||
"./*.ts"
|
||||
]
|
||||
}
|
||||
19
jdenticon-js/test/types/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"typeRoots": [
|
||||
"../../node_modules/@types"
|
||||
],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"compileOnSave": false
|
||||
}
|
||||
60
jdenticon-js/test/types/umd/global-test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
const config: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
window.jdenticon_config = config;
|
||||
|
||||
jdenticon.configure(config);
|
||||
|
||||
jdenticon.toPng("value to hash", 100);
|
||||
jdenticon.toSvg("value to hash", 100);
|
||||
|
||||
jdenticon.toPng("value to hash", 100, 0.08);
|
||||
jdenticon.toSvg("value to hash", 100, 0.08);
|
||||
|
||||
jdenticon.toPng("value to hash", 100, config);
|
||||
jdenticon.toSvg("value to hash", 100, config);
|
||||
|
||||
var el = document.createElement("canvas");
|
||||
jdenticon.update(el, "value");
|
||||
jdenticon.update(el, "value", 0.08);
|
||||
jdenticon.update(el, "value", config);
|
||||
jdenticon.update("#selector", "value");
|
||||
jdenticon.update("#selector", "value", 0.08);
|
||||
jdenticon.update("#selector", "value", config);
|
||||
|
||||
jdenticon.updateSvg("#selector", "value", config);
|
||||
jdenticon.updateCanvas("#selector", "value", config);
|
||||
|
||||
jdenticon();
|
||||
|
||||
var ctx = el.getContext("2d");
|
||||
if (ctx) {
|
||||
jdenticon.drawIcon(ctx, "value", 100);
|
||||
jdenticon.drawIcon(ctx, "value", 100, 0.08);
|
||||
jdenticon.drawIcon(ctx, "value", 100, config);
|
||||
}
|
||||
|
||||
// Ensure Jdenticon dodn't leak Node typings.
|
||||
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
|
||||
const timeoutRef1: number = setTimeout(() => { }, 100);
|
||||
24
jdenticon-js/test/types/umd/jquery-test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/// <reference types="jquery" />
|
||||
|
||||
const jqueryConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
$("canvas").jdenticon("value");
|
||||
$("canvas").jdenticon("value", 0.08);
|
||||
$("canvas").jdenticon("value", jqueryConfig);
|
||||
|
||||
// Ensure Jdenticon dodn't leak Node typings.
|
||||
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
|
||||
const timeoutRef2: number = setTimeout(() => { }, 100);
|
||||
59
jdenticon-js/test/types/umd/module-test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { configure, drawIcon, update, updateSvg, updateCanvas, toPng, toSvg } from "jdenticon/standalone";
|
||||
|
||||
const newConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.40, 0.80],
|
||||
grayscale: [0.30, 0.90]
|
||||
},
|
||||
saturation: {
|
||||
color: 0.50,
|
||||
grayscale: 0.00
|
||||
},
|
||||
hues: [45, 677],
|
||||
padding: 0.3,
|
||||
replaceMode: "observe",
|
||||
backColor: "#86444400"
|
||||
};
|
||||
|
||||
const oldConfig: JdenticonConfig = {
|
||||
lightness: {
|
||||
color: [0.4, 0.8],
|
||||
grayscale: [0.3, 0.9]
|
||||
},
|
||||
saturation: 0.5
|
||||
};
|
||||
|
||||
window.jdenticon_config = oldConfig;
|
||||
|
||||
configure(oldConfig);
|
||||
|
||||
toPng("value to hash", 100);
|
||||
toSvg("value to hash", 100);
|
||||
|
||||
toPng("value to hash", 100, 0.08);
|
||||
toSvg("value to hash", 100, 0.08);
|
||||
|
||||
toPng("value to hash", 100, newConfig);
|
||||
toSvg("value to hash", 100, newConfig);
|
||||
|
||||
var el = document.createElement("canvas");
|
||||
update(el, "value");
|
||||
update(el, "value", 0.08);
|
||||
update(el, "value", newConfig);
|
||||
update("#selector", "value");
|
||||
update("#selector", "value", 0.08);
|
||||
update("#selector", "value", newConfig);
|
||||
|
||||
updateSvg("#selector", "value", newConfig);
|
||||
updateCanvas("#selector", "value", newConfig);
|
||||
|
||||
var ctx = el.getContext("2d");
|
||||
if (ctx) {
|
||||
drawIcon(ctx, "value", 100);
|
||||
drawIcon(ctx, "value", 100, 0.08);
|
||||
drawIcon(ctx, "value", 100, newConfig);
|
||||
}
|
||||
|
||||
// Ensure Jdenticon dodn't leak Node typings.
|
||||
// setTimeout returns a NodeJS.Timeout when the Node typings are loaded.
|
||||
const timeoutRef3: number = setTimeout(() => { }, 100);
|
||||
12
jdenticon-js/test/types/umd/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"jdenticon/standalone"
|
||||
],
|
||||
"lib": ["es6", "dom"],
|
||||
},
|
||||
"include": [
|
||||
"./*.ts"
|
||||
]
|
||||
}
|
||||
56
jdenticon-js/test/unit/sha1.js
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
import tap from "tap";
|
||||
import { sha1 } from "../../src/common/sha1.js";
|
||||
|
||||
tap.equal("92cfceb39d57d914ed8b14d0e37643de0797ae56", sha1(42));
|
||||
tap.equal("21d90aad4d34f48f4aad9b5fa3c37c118af16df9", sha1("Value to be hashed"));
|
||||
tap.equal("d5d4cd07616a542891b7ec2d0257b3a24b69856e", sha1()); // undefined
|
||||
tap.equal("2be88ca4242c76e8253ac62474851065032d6833", sha1(null));
|
||||
tap.equal("08a73daac75982601504c4ba956f49e73ee52667", sha1("abcåäö")); // non-ASCII chars
|
||||
tap.equal("da39a3ee5e6b4b0d3255bfef95601890afd80709", sha1(""));
|
||||
tap.equal("11f6ad8ec52a2984abaafd7c3b516503785c2072", sha1("x"));
|
||||
|
||||
// The message is broken down to 64 byte blocks. Test the region around 64 bytes.
|
||||
|
||||
// 54 chars
|
||||
tap.equal("6d9fbf872b4e22afee77d8c9e95c10ec03bc731d", sha1("012345678901234567890123456789012345678901234567890123"));
|
||||
|
||||
// 55 chars
|
||||
tap.equal("9f3a4ce7f66b1b74c34da2c5d732c39f81e0f8df", sha1("0123456789012345678901234567890123456789012345678901234"));
|
||||
|
||||
// 56 chars
|
||||
tap.equal("0a40b8fbdaafb7c29651618ac15d27e772287130", sha1("01234567890123456789012345678901234567890123456789012345"));
|
||||
|
||||
// 57 chars
|
||||
tap.equal("46cc79601f8c6b81a4180774ce08465987a225a7", sha1("012345678901234567890123456789012345678901234567890123456"));
|
||||
|
||||
// 58 chars
|
||||
tap.equal("b2aac732d817277777547d2f067df99bb1b5c5ee", sha1("0123456789012345678901234567890123456789012345678901234567"));
|
||||
|
||||
// 59 chars
|
||||
tap.equal("beb7f3acc8e5c80ad813fb013406b58b0dc821ee", sha1("01234567890123456789012345678901234567890123456789012345678"));
|
||||
|
||||
// 60 chars
|
||||
tap.equal("f52e3c2732de7bea28f216d877d78dae1aa1ac6a", sha1("012345678901234567890123456789012345678901234567890123456789"));
|
||||
|
||||
// 61 chars
|
||||
tap.equal("2a1fc3a0fb3d5a6aac17068f5e12e3989269d221", sha1("0123456789012345678901234567890123456789012345678901234567890"));
|
||||
|
||||
// 62 chars
|
||||
tap.equal("bfbe32d71cb46704d9e185cb6b1e42e1b0965635", sha1("01234567890123456789012345678901234567890123456789012345678901"));
|
||||
|
||||
// 63 chars
|
||||
tap.equal("984b0f2f6d78c24020f5a79d409f67ab99302891", sha1("012345678901234567890123456789012345678901234567890123456789012"));
|
||||
|
||||
// 64 chars
|
||||
tap.equal("cf0800f7644ace3cb4c3fa33388d3ba0ea3c8b6e", sha1("0123456789012345678901234567890123456789012345678901234567890123"));
|
||||
|
||||
// 65 chars
|
||||
tap.equal("92de3a8444fe6d15268f0ba810aa43bc8b3a4ffe", sha1("01234567890123456789012345678901234567890123456789012345678901234"));
|
||||
|
||||
// 66 chars
|
||||
tap.equal("54af28647b3c9f53d5c20b2b7877062eb69a4675", sha1("012345678901234567890123456789012345678901234567890123456789012345"));
|
||||
|
||||
// 130 chars (spans three blocks)
|
||||
tap.equal("1f548f0569669daed4fee89712d9019e3d276b55", sha1("0123456789012345678901234567890123456789012345678901234567890123012345678901234567890123456789012345678901234567890123456789012345"));
|
||||
17
jdenticon-js/test/unit/toPng.js
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
import tap from "tap";
|
||||
import { toPng } from "../../src/node-esm.js";
|
||||
|
||||
const pngHash = toPng("Icon1", 100);
|
||||
const pngValue = toPng("9faff4f3d6d7d75577ce810ec6d6a06be49c3a5a", 100);
|
||||
|
||||
tap.ok(pngHash);
|
||||
tap.ok(pngHash instanceof Buffer);
|
||||
tap.ok(pngHash.length > 500);
|
||||
|
||||
tap.ok(pngValue);
|
||||
tap.ok(pngValue instanceof Buffer);
|
||||
tap.ok(pngValue.length > 500);
|
||||
|
||||
tap.ok(pngHash.equals(pngValue));
|
||||
9
jdenticon-js/test/unit/toSvg.js
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
import tap from "tap";
|
||||
import { toSvg } from "../../src/node-esm.js";
|
||||
|
||||
const expectedSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path fill="#c0e5b2" d="M29 18.5L39.5 8L50 18.5L39.5 29ZM60.5 8L71 18.5L60.5 29L50 18.5ZM71 81.5L60.5 92L50 81.5L60.5 71ZM39.5 92L29 81.5L39.5 71L50 81.5ZM8 39.5L18.5 29L29 39.5L18.5 50ZM81.5 29L92 39.5L81.5 50L71 39.5ZM92 60.5L81.5 71L71 60.5L81.5 50ZM18.5 71L8 60.5L18.5 50L29 60.5Z"/><path fill="#81cc66" d="M11.5 18.5a7,7 0 1,1 14,0a7,7 0 1,1 -14,0M74.5 18.5a7,7 0 1,1 14,0a7,7 0 1,1 -14,0M74.5 81.5a7,7 0 1,1 14,0a7,7 0 1,1 -14,0M11.5 81.5a7,7 0 1,1 14,0a7,7 0 1,1 -14,0M50 29L50 45L40 29ZM71 50L55 50L71 40ZM50 71L50 55L60 71ZM29 50L45 50L29 60Z"/></svg>';
|
||||
|
||||
tap.equal(expectedSvg, toSvg("Icon1", 100));
|
||||
tap.equal(expectedSvg, toSvg("9faff4f3d6d7d75577ce810ec6d6a06be49c3a5a", 100));
|
||||