Use regex to parse AssertionError
parent
241e9cb516
commit
0a3d08244a
|
@ -1,15 +1,14 @@
|
|||
const regAssertParser = /(.*?)\n+(.*?)\n+(( at.*?file:\/\/(.*?):(\d+):(\d+).*?\)).*)/s
|
||||
|
||||
const stackParser = (stack) => {
|
||||
const endOfLine = stack.indexOf('\n')
|
||||
const m = stack.match(regAssertParser)
|
||||
|
||||
const title = stack.slice(0, endOfLine)
|
||||
const info = m
|
||||
.slice(1)
|
||||
.map(x => x.trim())
|
||||
const [title, diff, stacktrace, where, file, line, column] = info
|
||||
|
||||
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 }
|
||||
return { title, diff, where, file, line, column, stacktrace }
|
||||
}
|
||||
|
||||
export { stackParser }
|
|
@ -29,8 +29,8 @@ const prettyError = (error) => {
|
|||
const stack = stackParser(error.stack)
|
||||
log(chalk.yellowBright(stack.title) + '\n')
|
||||
|
||||
if (stack.diff != '\n ')
|
||||
log(chalk.white(stack.diff))
|
||||
if (stack.diff != '')
|
||||
log(chalk.white(stack.diff) + '\n')
|
||||
|
||||
if (stack.where != '')
|
||||
log(chalk.gray(stack.where) + '\n')
|
||||
|
|
Loading…
Reference in New Issue