Skip to content

Instantly share code, notes, and snippets.

@asheb
Created July 20, 2014 09:39
Show Gist options
  • Save asheb/8f67d55ef597329d266e to your computer and use it in GitHub Desktop.
Save asheb/8f67d55ef597329d266e to your computer and use it in GitHub Desktop.
Dirty hack to make 'source-map-support' work with mocha in PhantomJS
sourceMapper = require 'source-map-support'
Dot = require '../../../node_modules/grunt-mocha/node_modules/mocha/lib/reporters/dot.js'
module.exports = Dot
##
parseLine = (line) ->
[_, file, row] = line.match /file:\/\/\/(.*):(\d*)/
frame =
getFileName: -> file
getLineNumber: -> row
getColumnNumber: -> 1
superEpilogue = Dot.prototype.epilogue
Dot.prototype.epilogue = ->
for test in @failures
test.err.stack = test.err.stack.split('\n').map((line)->
if line.match /^ at /
mapped = sourceMapper.wrapCallSite parseLine line
line.replace /file:\/\/\/(.*):(\d*)/,
"file:///#{mapped.getFileName()}:#{mapped.getLineNumber()}"
else
line
).join('\n')
superEpilogue.bind(@)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment