2019-11-26 03:16:16 +00:00
|
|
|
import cookie from "./cookie.mjs";
|
|
|
|
import errors from "./errors.mjs";
|
|
|
|
|
|
|
|
class Test {
|
|
|
|
constructor(name, fnc) {
|
2020-06-17 13:04:32 +00:00
|
|
|
this.name = name;
|
|
|
|
this.fnc = fnc;
|
2019-11-26 03:16:16 +00:00
|
|
|
}
|
|
|
|
async runTest() {
|
|
|
|
return this.fnc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:04:32 +00:00
|
|
|
const tests = [cookie, errors].flatMap(t => t(Test));
|
2019-11-26 03:16:16 +00:00
|
|
|
|
|
|
|
(async () => {
|
|
|
|
console.log("running tests...");
|
2020-06-17 13:04:32 +00:00
|
|
|
const testResults = await Promise.all(
|
|
|
|
tests.map(async t => {
|
|
|
|
try {
|
|
|
|
t.result = await t.runTest();
|
|
|
|
if (t.result !== !!t.result) {
|
|
|
|
t.result = false;
|
|
|
|
console.error("test did not return a boolean: " + t.name);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error(
|
|
|
|
"uncaught error in test: " + t.name + "\n",
|
|
|
|
error
|
|
|
|
);
|
2019-11-26 03:16:16 +00:00
|
|
|
t.result = false;
|
|
|
|
}
|
2020-06-17 13:04:32 +00:00
|
|
|
return t;
|
|
|
|
})
|
|
|
|
);
|
2019-11-26 03:16:16 +00:00
|
|
|
testResults.forEach(t => {
|
2020-06-17 13:04:32 +00:00
|
|
|
if (t.result) console.info("✔ " + t.name);
|
|
|
|
else console.warn("✘ " + t.name);
|
2019-11-26 03:16:16 +00:00
|
|
|
});
|
2020-06-17 13:04:32 +00:00
|
|
|
const succeededTests = testResults
|
|
|
|
.map(t => t.result)
|
|
|
|
.reduce((a, b) => a + b);
|
2019-11-26 03:16:16 +00:00
|
|
|
const success = succeededTests === testResults.length;
|
2020-06-17 13:04:32 +00:00
|
|
|
(success ? console.info : console.warn)(
|
|
|
|
(success ? "✔" : "✘") +
|
|
|
|
" " +
|
|
|
|
succeededTests +
|
|
|
|
"/" +
|
|
|
|
testResults.length +
|
|
|
|
" tests successful"
|
|
|
|
);
|
2019-11-26 03:16:16 +00:00
|
|
|
!success && process.exit(1);
|
|
|
|
})();
|