metaltest/consolereporter.js

50 lines
1016 B
JavaScript
Raw Normal View History

2022-11-08 22:29:58 -05:00
import chalk from 'chalk'
2022-12-04 23:40:07 -05:00
2022-11-08 22:29:58 -05:00
const log = (...args) => process.stdout.write(...args)
const consolereporter = () => {
const report = {
start: (title) => {
log(chalk.cyanBright(title) + ' ')
},
success: (test) => {
log(chalk.greenBright('✓ '))
},
fail: (test, e) => {
log(chalk.redBright('✗ '))
},
end: (stats) => {
2022-12-04 16:06:06 -05:00
const { testFail } = stats
log('\n')
2022-11-08 22:29:58 -05:00
for (const test of testFail) {
log('\n' + chalk.redBright(test.name) + '\n')
prettyError(test.error)
log('\n')
}
}
}
return report
}
2022-12-04 23:40:07 -05:00
import { stackParser } from './stackparser.js'
2022-11-08 22:29:58 -05:00
const prettyError = (error) => {
if (typeof error == 'string') {
log(chalk.yellowBright(error))
log('\n')
return
}
2022-12-04 23:40:07 -05:00
const stack = stackParser(error.stack)
log(chalk.yellowBright(stack.title) + '\n')
2022-11-08 22:29:58 -05:00
2022-12-04 23:40:07 -05:00
if (stack.diff != '\n ')
log(chalk.white(stack.diff))
2022-11-08 22:29:58 -05:00
2022-12-04 23:40:07 -05:00
if (stack.where != '')
log(chalk.gray(stack.where) + '\n')
2022-11-08 22:29:58 -05:00
}
export { consolereporter }