Use regex to parse AssertionError

master
Frédéric Matte 2022-12-06 12:58:30 -05:00
parent 241e9cb516
commit 0a3d08244a
2 changed files with 10 additions and 11 deletions

View File

@ -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 }

View File

@ -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')