From a38c1dd2f1162e1d7b920619af9b7c16925de952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Matte?= Date: Fri, 11 Oct 2024 13:38:34 -0400 Subject: [PATCH] Show stats and the end of a run --- lib/runifmain.js | 8 ++++++-- reporter/endreporter.js | 17 +++++++++++++++++ reporter/index.js | 3 ++- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 reporter/endreporter.js diff --git a/lib/runifmain.js b/lib/runifmain.js index 2b51303..6e1d6b3 100644 --- a/lib/runifmain.js +++ b/lib/runifmain.js @@ -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) diff --git a/reporter/endreporter.js b/reporter/endreporter.js new file mode 100644 index 0000000..c3b2122 --- /dev/null +++ b/reporter/endreporter.js @@ -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 } diff --git a/reporter/index.js b/reporter/index.js index 30b55a0..72f3907 100644 --- a/reporter/index.js +++ b/reporter/index.js @@ -1,4 +1,5 @@ export { summaryreporter } from './summaryreporter.js' export { linereporter } from './linereporter.js' export { totalreporter } from './totalreporter.js' -export { errorreporter } from './errorreporter.js' \ No newline at end of file +export { errorreporter } from './errorreporter.js' +export { endreporter } from './endreporter.js'