diff --git a/index.js b/index.js index 61a8e83..6824287 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import { consolereporter } from './consolereporter.js' +import { linereporter } from './linereporter.js' import { totalreporter } from './totalreporter.js' import { runifmain } from './runifmain.js' @@ -66,5 +67,5 @@ const metaltest = (title) => { return runner } -export { metaltest, consolereporter, totalreporter, runifmain } +export { metaltest, consolereporter, linereporter, totalreporter, runifmain } export default metaltest \ No newline at end of file diff --git a/linereporter.js b/linereporter.js new file mode 100644 index 0000000..2d1e5dd --- /dev/null +++ b/linereporter.js @@ -0,0 +1,34 @@ +import chalk from 'chalk' + +const linereporter = () => { + const lines = [] + + const report = { + start: (title) => { + console.log(chalk.cyanBright(title)) + }, + success: (test) => { + console.log(chalk.greenBright('✓'), test.name) + }, + fail: (test, e) => { + const line = e.stack.match(/at.*:(.*):/)[1] + lines.push(line) + console.log(chalk.redBright('✗'), line, test.name) + }, + end: (stats) => { + const { success, fail, testFail } = stats + console.log(chalk.redBright('✗ ' + fail), chalk.greenBright('✓ ' + success)) + + if (testFail.length == 1) { + console.log('Lines in error', chalk.redBright(lines)) + + const { error: { stack: e } } = testFail[0] + console.log(e.slice(e.indexOf('\n') + 1, e.indexOf(' at') - 1)); + } + } + } + + return report +} + +export { linereporter } \ No newline at end of file