Add the Line Reporter

master
Frédéric Matte 2022-12-04 16:07:28 -05:00
parent 64d10c8dfb
commit 7a8a4ad629
2 changed files with 36 additions and 1 deletions

View File

@ -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

34
linereporter.js Normal file
View File

@ -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 }