Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improve stack formating
  • Loading branch information
pi0 committed Nov 2, 2018
1 parent 5c694af commit 2452511
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/reporters/basic.js
Expand Up @@ -15,7 +15,8 @@ export default class BasicReporter {
}

formatStack (stack) {
return ' at ' + parseStack(stack).join('\n at ')
return ' at ' + parseStack(stack)
.join('\n at ')
}

formatArgs (args) {
Expand Down
11 changes: 6 additions & 5 deletions src/reporters/fancy.js
Expand Up @@ -26,11 +26,12 @@ export default class FancyReporter extends BasicReporter {
}

formatStack (stack) {
return ' at ' + parseStack(stack)
.map(line => {
return line
})
.join(' ↲\n at ')
const color1 = chalkColor('cyan')
const color2 = chalkColor('grey')

return color2(' at ') + parseStack(stack)
.map(line => color1(line.replace(/(\(.*\))/, (m, p1) => color2(p1))))
.join(color2(' ↲\n at '))
}

typeColor (type, level) {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/error.js
@@ -1,9 +1,14 @@
import { sep } from 'path'

export function parseStack (stack) {
const cwd = process.cwd() + sep

let lines = stack
.split('\n')
.map(l => l
.trim()
.replace(/^at /, '')
.replace(cwd, '')
)

if (lines[0].indexOf('Error: ') === 0) {
Expand Down

0 comments on commit 2452511

Please sign in to comment.