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.
54 lines
1.2 KiB
54 lines
1.2 KiB
9 months ago
|
import glob from "fast-glob";
|
||
|
import path from "path";
|
||
|
|
||
|
export const description = "Runs tests.";
|
||
|
|
||
|
export const options = [];
|
||
|
|
||
|
export const required = [
|
||
|
["--glob <regex>", "Directory pattern to find test runners.", "./tests/**/*_test?.js"],
|
||
|
];
|
||
|
|
||
|
const report_error = (id, error) => {
|
||
|
console.error(error, `Running function ${id}`);
|
||
|
}
|
||
|
|
||
|
export const main = async (opts) => {
|
||
|
const test_files = await glob(opts.glob);
|
||
|
|
||
|
const stats = {
|
||
|
pass: 0, fail: 0
|
||
|
}
|
||
|
|
||
|
const errors = {}
|
||
|
|
||
|
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);
|
||
|
}
|