mimicry/test/main.js

64 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-09-09 13:22:19 +00:00
"use strict";
test();
function test () {
if (!Mimicry) {
log("Mimicry class was not loaded");
return;
}
log("Mimicry class is loaded");
log("Mimicry ready: " + Mimicry.ready);
let mimicry;
try {
mimicry = new Mimicry();
window.mimicry = mimicry;
log("Mimicry was successfully instantiated");
} catch (e) {
log("Error instantiating Mimicry");
return;
}
try {
mimicry.module(["module"], function (global, [module]) {
log("Mimicry empty module successfully resolved");
log("The background now is supposed to be bluish if you're testing in browser")
2023-09-16 13:01:49 +00:00
if (module instanceof Array) {
2023-09-09 13:22:19 +00:00
log("Value returned from additional module is correct");
2023-09-16 13:01:49 +00:00
let allGood = true;
for (let i = 0; i < module.length; ++i) {
if (!module[i]) {
log("Component number " + i + " returned from additional module is incorrect");
allGood = false;
}
}
if (allGood)
log("All components returned from additional module are correct");
} else {
2023-09-09 13:22:19 +00:00
log("Value returned from additional module is \"" + module + "\", which is incorrect");
2023-09-16 13:01:49 +00:00
}
const json = mimicry.getAsset("simple");
if (json instanceof Object && json.I === "am")
log("loaded by one of the modules asset (json) is present and valid");
else
log("loaded by one of the modules asset (json) is not present or invalid");
2023-09-09 13:22:19 +00:00
});
log("Successfully launched Mimicry empty module");
} catch (e) {
log("Error launching Mimicry empty module");
//return;
}
}
function log (message) {
const node = document.createTextNode(message);
const br = document.createElement("br");
document.body.appendChild(node);
document.body.appendChild(br);
}