metaltest/consolereporter.js

50 lines
1016 B
JavaScript

import chalk from 'chalk'
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) => {
const { testFail } = stats
log('\n')
for (const test of testFail) {
log('\n' + chalk.redBright(test.name) + '\n')
prettyError(test.error)
log('\n')
}
}
}
return report
}
import { stackParser } from './stackparser.js'
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')
if (stack.diff != '\n ')
log(chalk.white(stack.diff))
if (stack.where != '')
log(chalk.gray(stack.where) + '\n')
}
export { consolereporter }