Skip to content

Instantly share code, notes, and snippets.

@guncha
Created December 10, 2015 20:08
Show Gist options
  • Save guncha/f45ceef6d483c384290a to your computer and use it in GitHub Desktop.
Save guncha/f45ceef6d483c384290a to your computer and use it in GitHub Desktop.
Jasmine HTMLReporter stack traces using source maps

To get a quick and dirty stack traces with Jasmine's HTML Reporter, add this on the spec runner page after jasmine/boot.js.

<script type="text/javascript" src="sourcemapped-stacktrace.js"></script>
<script type="text/javascript">
  jasmine.getEnv().addReporter({
    jasmineDone: function() {
      var traces = document.querySelectorAll(".jasmine-stack-trace")
      for(var i = 0; i < traces.length; i++) {
        (function(node){
          sourceMappedStackTrace.mapStackTrace(node.textContent, function(stack) {
            node.textContent = node.previousSibling.textContent + "\n" + stack.join("\n")
          })
        })(traces[i])
      }
    }
  })
</script>

It will add a new reporter that when Jasmine is done, will transform the stack traces using @novocaine's https://github.com/novocaine/sourcemapped-stacktrace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment