2022-11-08 22:29:58 -05:00
|
|
|
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) => {
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
const prettyError = (error) => {
|
|
|
|
if (typeof error == 'string') {
|
|
|
|
log(chalk.yellowBright(error))
|
|
|
|
log('\n')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const msg = error.stack
|
|
|
|
const i = msg.indexOf('\n')
|
|
|
|
|
|
|
|
const title = msg.slice(0, i)
|
|
|
|
log(chalk.yellowBright(title) + '\n')
|
|
|
|
|
|
|
|
const at = msg.indexOf(' at ')
|
|
|
|
const diff = msg.slice(i + 1, at - 1)
|
|
|
|
if (diff != '\n ')
|
|
|
|
log(chalk.white(diff))
|
|
|
|
|
|
|
|
const atEnd = msg.slice(at).indexOf('\n')
|
|
|
|
const where = msg.slice(at + 3, at + atEnd)
|
|
|
|
|
|
|
|
if (where != '')
|
|
|
|
log(chalk.gray(where) + '\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
export { consolereporter }
|