Add a stackparser
parent
036f7a0563
commit
4c3cca0cd3
|
@ -1,4 +1,5 @@
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
|
||||||
const log = (...args) => process.stdout.write(...args)
|
const log = (...args) => process.stdout.write(...args)
|
||||||
|
|
||||||
const consolereporter = () => {
|
const consolereporter = () => {
|
||||||
|
@ -28,6 +29,7 @@ const consolereporter = () => {
|
||||||
return report
|
return report
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { stackParser } from './stackparser.js'
|
||||||
const prettyError = (error) => {
|
const prettyError = (error) => {
|
||||||
if (typeof error == 'string') {
|
if (typeof error == 'string') {
|
||||||
log(chalk.yellowBright(error))
|
log(chalk.yellowBright(error))
|
||||||
|
@ -35,22 +37,14 @@ const prettyError = (error) => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg = error.stack
|
const stack = stackParser(error.stack)
|
||||||
const i = msg.indexOf('\n')
|
log(chalk.yellowBright(stack.title) + '\n')
|
||||||
|
|
||||||
const title = msg.slice(0, i)
|
if (stack.diff != '\n ')
|
||||||
log(chalk.yellowBright(title) + '\n')
|
log(chalk.white(stack.diff))
|
||||||
|
|
||||||
const at = msg.indexOf(' at ')
|
if (stack.where != '')
|
||||||
const diff = msg.slice(i + 1, at - 1)
|
log(chalk.gray(stack.where) + '\n')
|
||||||
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 }
|
export { consolereporter }
|
|
@ -1,4 +1,5 @@
|
||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
|
import { stackParser } from './stackparser.js'
|
||||||
|
|
||||||
const linereporter = () => {
|
const linereporter = () => {
|
||||||
const lines = []
|
const lines = []
|
||||||
|
@ -22,8 +23,8 @@ const linereporter = () => {
|
||||||
if (testFail.length == 1) {
|
if (testFail.length == 1) {
|
||||||
console.log('Lines in error', chalk.redBright(lines))
|
console.log('Lines in error', chalk.redBright(lines))
|
||||||
|
|
||||||
const { error: { stack: e } } = testFail[0]
|
const stack = stackParser(testFail[0].error.stack)
|
||||||
console.log(e.slice(e.indexOf('\n') + 1, e.indexOf(' at') - 1));
|
console.log(stack.diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
const stackParser = (stack) => {
|
||||||
|
const endOfLine = stack.indexOf('\n')
|
||||||
|
|
||||||
|
const title = stack.slice(0, endOfLine)
|
||||||
|
|
||||||
|
const at = stack.indexOf(' at ')
|
||||||
|
const diff = stack.slice(endOfLine + 1, at - 1)
|
||||||
|
|
||||||
|
const endOfLineAfterAt = stack.slice(at).indexOf('\n')
|
||||||
|
const where = stack.slice(at + 3, at + endOfLineAfterAt)
|
||||||
|
|
||||||
|
return { title, diff, where }
|
||||||
|
}
|
||||||
|
|
||||||
|
export { stackParser }
|
|
@ -0,0 +1,19 @@
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { metaltest, consolereporter } from './index.js'
|
||||||
|
import { stackParser } from "./stackparser.js"
|
||||||
|
|
||||||
|
const test = metaltest('Stack parser')
|
||||||
|
|
||||||
|
test('Diff', () => {
|
||||||
|
try {
|
||||||
|
assert.deepEqual({ name: 'Name' }, { name: 'Name2' })
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
const stack = stackParser(e.stack)
|
||||||
|
assert.ok(stack.diff.includes("name: 'Name'"))
|
||||||
|
assert.ok(stack.diff.includes("name: 'Name2'"))
|
||||||
|
assert.ok(stack.where.includes('stackparser.test.js'))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.run(consolereporter())
|
Loading…
Reference in New Issue