Show stats and the end of a run

master
Frédéric Matte 2024-10-11 13:38:34 -04:00
parent 149be7074d
commit a38c1dd2f1
3 changed files with 25 additions and 3 deletions

View File

@ -6,12 +6,16 @@ const isMain = (meta) => {
return path.includes(process.argv[1])
}
import { errorreporter, summaryreporter } from '../index.js'
import { errorreporter, summaryreporter, endreporter } from '../index.js'
const runifmain = async (meta, fn, ...args) => {
if (!isMain(meta)) return
if (fn.name === 'runner' && fn.run) {
if (args.length == 0) args.push(summaryreporter(), errorreporter())
if (args.length == 0) args.push(
summaryreporter(),
errorreporter(),
endreporter(),
)
await fn.run(...args)
} else {
await fn(...args)

17
reporter/endreporter.js Normal file
View File

@ -0,0 +1,17 @@
import chalk from 'chalk'
import { log } from '../lib/log.js'
const percentage = (dividend, divisor) => (dividend / divisor * 100).toFixed(0)
const endreporter = () => {
let success = 0, fail = 0, skip = 0
return {
success: (test) => { success++ },
fail: (test, e) => { fail++ },
skip: (test) => { skip++ },
end: (stats) => { log(`${chalk.redBright(`Fail: ${fail}`)} - ${chalk.greenBright(`Sucess: ${success}`)} - ${chalk.blueBright(`Skip: ${skip}`)} - ${chalk.yellowBright(`Ratio: ${percentage(success, success + fail)}%`)}`) },
}
}
export { endreporter }

View File

@ -1,4 +1,5 @@
export { summaryreporter } from './summaryreporter.js'
export { linereporter } from './linereporter.js'
export { totalreporter } from './totalreporter.js'
export { errorreporter } from './errorreporter.js'
export { errorreporter } from './errorreporter.js'
export { endreporter } from './endreporter.js'