metaltest/reporter/linereporter.js

37 lines
878 B
JavaScript
Raw Normal View History

2022-12-04 16:07:28 -05:00
import chalk from 'chalk'
2022-12-05 17:07:06 -05:00
import { stackParser } from '../lib/stackparser.js'
2022-12-04 16:07:28 -05:00
2022-12-05 16:49:27 -05:00
const log = (...args) => console.log(...args)
2022-12-04 16:07:28 -05:00
const linereporter = () => {
const lines = []
const report = {
start: (title) => {
2022-12-05 16:49:27 -05:00
log(chalk.cyanBright(title))
2022-12-04 16:07:28 -05:00
},
success: (test) => {
2022-12-05 16:49:27 -05:00
log(chalk.greenBright('✓'), test.name)
2022-12-04 16:07:28 -05:00
},
fail: (test, e) => {
const line = e.stack.match(/at.*:(.*):/)[1]
lines.push(line)
2022-12-05 16:49:27 -05:00
log(chalk.redBright('✗'), line, test.name)
2022-12-04 16:07:28 -05:00
},
end: (stats) => {
const { success, fail, testFail } = stats
2022-12-05 16:49:27 -05:00
log(chalk.redBright('✗ ' + fail), chalk.greenBright('✓ ' + success))
2022-12-04 16:07:28 -05:00
if (testFail.length == 1) {
2022-12-05 16:49:27 -05:00
log('Lines in error', chalk.redBright(lines))
2022-12-04 16:07:28 -05:00
2022-12-04 23:40:07 -05:00
const stack = stackParser(testFail[0].error.stack)
2022-12-05 16:49:27 -05:00
log(stack.diff)
2022-12-04 16:07:28 -05:00
}
}
}
return report
}
export { linereporter }