 {View, $, $$} = require '../src/space-pen-extensions'
 
 sourceMaps = {}
-formatStackTrace = (message='', stackTrace) ->
+formatStackTrace = (spec, message='', stackTrace) ->
   return stackTrace unless stackTrace
 
   jasminePattern = /^\s*at\s+.*\(?.*\/jasmine(-[^\/]*)?\.js:\d+:\d+\)?\s*$/

  errorMatch = lines[0]?.match(/^Error: (.*)/)
  lines.shift() if message.trim() is errorMatch?[1]?.trim()

  # Remove prefix of lines matching: at [object Object].<anonymous> (path:1:2)
  for line, index in lines
    prefixMatch = line.match(/at \[object Object\]\.<anonymous> \(([^\)]+)\)/)
    lines[index] = "at #{prefixMatch[1]}" if prefixMatch

  lines = lines.map (line) -> line.trim()
  lines.join('\n').trim()

    @description.text(description)

    for result in @spec.results().getItems() when not result.passed()
      stackTrace = formatStackTrace(@spec, result.message, result.trace.stack)
      @specFailures.append $$ ->
        @div result.message, class: 'result-message fail'
        @pre stackTrace, class: 'stack-trace padded' if stackTrace
