1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01:00

detectionTest: made addTest asynchronous

This commit is contained in:
kkapsner 2021-02-21 10:55:36 +01:00
parent 211d6710f6
commit aa3f9d878d

View File

@ -8,21 +8,8 @@ const addTest = (function(){
{className: "failed", text: "test failed"} {className: "failed", text: "test failed"}
]; ];
const ul = document.getElementById("tests"); const ul = document.getElementById("tests");
return function addTest(name, func){ return async function addTest(name, func){
const logs = [];
function log(){
logs.push(Array.prototype.slice.call(arguments).join(" "));
}
let status = 0;
try {
status = func(log)? 1: 2;
}
catch (error){
console.log(error);
status = 3;
}
const li = document.createElement("li"); const li = document.createElement("li");
li.className = statusDefinitions[status].className;
const nameNode = document.createElement("span"); const nameNode = document.createElement("span");
nameNode.className = "name"; nameNode.className = "name";
nameNode.textContent = name; nameNode.textContent = name;
@ -31,10 +18,23 @@ const addTest = (function(){
li.appendChild(document.createTextNode(": ")); li.appendChild(document.createTextNode(": "));
const statusNode = document.createElement("span"); const statusNode = document.createElement("span");
statusNode.className = "status"; statusNode.className = "status";
statusNode.textContent = statusDefinitions[status].text;
statusNode.title = logs.join("\n");
li.appendChild(statusNode); li.appendChild(statusNode);
ul.appendChild(li); ul.appendChild(li);
const logs = [];
function log(){
logs.push(Array.prototype.slice.call(arguments).join(" "));
}
let status = 0;
try {
status = await func(log)? 1: 2;
}
catch (error){
console.log(error);
status = 3;
}
li.className = statusDefinitions[status].className;
statusNode.textContent = statusDefinitions[status].text;
statusNode.title = logs.join("\n");
return li; return li;
}; };
}()); }());