An even more educational version of the Bandolier for Learn JS the Hard Way.
https://learnjsthehardway.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
977 B
43 lines
977 B
import glob from "fast-glob";
|
|
import path from "path";
|
|
|
|
const test_files = await glob("./tests/**/*_test?.js");
|
|
|
|
const stats = {
|
|
pass: 0, fail: 0
|
|
}
|
|
|
|
const errors = {}
|
|
|
|
const report_error = (id, error) => {
|
|
console.error(error, `Running function ${id}`);
|
|
}
|
|
|
|
for(let suite_name of test_files) {
|
|
const full_path = path.resolve(suite_name);
|
|
const test_module = await import(`file://${full_path}`);
|
|
|
|
for(let [name, func] of Object.entries(test_module)) {
|
|
const id = `${suite_name}:${name}`;
|
|
console.log("------- RUNNING", id);
|
|
try {
|
|
await func();
|
|
stats.pass += 1;
|
|
} catch(error) {
|
|
stats.fail += 1;
|
|
errors[id] = error;
|
|
report_error(func, id, error);
|
|
}
|
|
|
|
console.log("\n");
|
|
}
|
|
}
|
|
|
|
if(Object.keys(errors).length > 0) {
|
|
console.log("!!!!!!!!!!!!!! ERRORS !!!!!!!!!!!!!!!!");
|
|
for(let [id, error] of Object.entries(errors)) {
|
|
report_error(id, error);
|
|
}
|
|
}
|
|
|
|
console.log("\nPASS: ", stats.pass, "FAIL: ", stats.fail);
|
|
|