Extract the error reporter

master
Frédéric Matte 2022-12-05 16:50:37 -05:00
parent 979f078ac3
commit 7bde58b5ed
3 changed files with 41 additions and 26 deletions

View File

@ -15,36 +15,11 @@ const consolereporter = () => {
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 }

39
reporter/errorreporter.js Normal file
View File

@ -0,0 +1,39 @@
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)
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 { errorreporter }

View File

@ -1,3 +1,4 @@
export { consolereporter } from './consolereporter.js'
export { linereporter } from './linereporter.js'
export { totalreporter } from './totalreporter.js'
export { totalreporter } from './totalreporter.js'
export { errorreporter } from './errorreporter.js'