metaltest/reporter/errorreporter.js

38 lines
778 B
JavaScript
Raw Permalink Normal View History

2022-12-05 16:50:37 -05:00
import chalk from 'chalk'
const log = (...args) => process.stdout.write(...args)
const errorreporter = () => {
const report = {
end: (stats) => {
const { testFail } = stats
for (const test of testFail) {
log('\n' + chalk.redBright(test.name) + '\n')
prettyError(test.error)
}
}
}
return report
}
2022-12-05 17:07:06 -05:00
import { stackParser } from '../lib/stackparser.js'
2022-12-05 16:50:37 -05:00
const prettyError = (error) => {
if (typeof error == 'string') {
log(chalk.yellowBright(error))
log('\n')
return
}
const stack = stackParser(error.stack)
log(chalk.yellowBright(stack.title) + '\n')
2022-12-06 12:58:30 -05:00
if (stack.diff != '')
log(chalk.white(stack.diff) + '\n')
2022-12-05 16:50:37 -05:00
if (stack.where != '')
log(chalk.gray(stack.where) + '\n')
}
export { errorreporter }