This commit is contained in:
Kevin McIntyre
2025-06-18 01:00:00 -04:00
commit f84b511895
228 changed files with 42509 additions and 0 deletions

2
jdenticon-js/test/e2e/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.bundle.js
*.bundle.js.map

View 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();
});
}

View 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>

View 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>

View 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);
}

View 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 "&lt;";
if (match === ">") return "&gt;";
if (match === "&") return "&amp;";
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>

View 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>

View 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>

View 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;
}

View 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 &lt;head&gt; - 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 &lt;head&gt;</figcaption>
</figure>
<script src="common.js"></script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

View 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;

View 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);

View 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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 605 B

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

View 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

View 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;

View 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);

View 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);

View 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");

View 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(),
],
};

View 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");

View 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);
}
});

View 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",
},
}