added unit tests, parsing class fields

This commit is contained in:
metacryst
2024-03-13 16:07:26 -05:00
parent dbf4d7cb19
commit fc4434b5de
4 changed files with 260 additions and 89 deletions

61
Test/parse.test.js Normal file
View File

@@ -0,0 +1,61 @@
window.testSuites.push( class testParse {
testParseClassFieldsWithEqualityCheck() {
class Space extends HTMLElement {
form = Forms.observe(window.location.pathname, this)
contents = [
...this.form.children.map(form => {
switch(form.type) {
case "file" === "file":
return File(form)
case "space":
return ChildSpace(form)
case "link":
return Link()
}
})
]
constructor() {
super()
}
}
const fields = window.Registry.parseClassFields(Space.toString());
if(!(JSON.stringify(fields) === JSON.stringify(["form", "contents"]))) {
return `Fields don't match`
}
}
testParseClassFieldsWithInnerFunctionVariable() {
class Space extends HTMLElement {
form = Forms.observe(window.location.pathname, this)
contents = [
...this.form.children.map(form => {
let file;
file = "hey"
switch(form.type) {
case "file" === "file":
return File(form)
case "space":
return ChildSpace(form)
case "link":
return Link()
}
})
]
constructor() {
super()
}
}
const fields = window.Registry.parseClassFields(Space.toString());
if(!(JSON.stringify(fields) === JSON.stringify(["form", "contents"]))) {
return `Fields don't match`
}
}
})

14
Test/test.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quill</title>
<link rel="icon" href="">
<link rel="stylesheet" href="">
<script src=""></script>
<script src="../index.js"></script>
<script src="test.js"></script>
</head>
<body>
</body>
</html>

56
Test/test.js Normal file
View File

@@ -0,0 +1,56 @@
console.log("Tests initializing.")
window.testSuites = [];
import ("./parse.test.js")
window.test = async function() {
// window.testSuites.sort();
window.alert = () => true;
window.confirm = () => true;
let failed = 0;
let success = 0;
var start = new Date();
for(let j=0; j<window.testSuites.length; j++) {
let testSuite = window.testSuites[j];
console.log(`%c ➽ ${j+1} ${testSuite.name.replace("test", "")}`, 'color: #ffffff; font-size: 17px; padding-left: -20px; padding-top: 10px; padding-bottom: 10px; text-align: right;')
let suite = new testSuite();
let testNum = 0;
let suiteContents = Object.getOwnPropertyNames(testSuite.prototype)
for(let i=0; i<suiteContents.length; i++) {
let test = suiteContents[i];
if(typeof suite[test] === 'function' && test !== "constructor") {
testNum++;
let fail = await suite[test]();
if(fail) {
failed++;
console.log(`%c ${testNum}. ${test}: ${fail}`, 'background: #222; color: rgb(254, 62, 43)');
} else {
success++;
console.log(`%c ${testNum}. ${test}`, 'background: #222; color: #00FF00');
}
}
// Need to flush ws buffer since saving is disabled, and that is what usually does the flushing
// Frame.ws.sendMessage('Flush Buffer');
}
// await wait(100);
}
console.log("")
console.log("")
let elapsed = new Date() - start;
if(failed === 0) {
console.log(`%cRan ${failed+success} tests in ${elapsed}ms`, 'background: #222; color: #00FF00');
console.log(`%c ${success} passed`, 'background: #222; color: #00FF00');
console.log(`%c ${failed} failed`, 'background: #222;');
} else {
console.log(`%cRan ${failed+success} tests in ${elapsed}ms`, 'background: #222; color: rgb(254, 62, 43)');
console.log(`%c ${success} `, 'background: #222; color: #00FF00', "passed");
console.log(`%c ${failed} failed`, 'background: #222; color: rgb(254, 62, 43)');
}
}
window.wait = ms => new Promise(res => setTimeout(res, ms));
window.__defineGetter__("test", test);