import glob from "fast-glob"; import path from "path"; export const description = "Runs tests."; export const options = []; export const required = [ ["--glob ", "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); }