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);