Skip to content

Commit

Permalink
Adding support for reporting global javascript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
swistak committed Apr 6, 2013
1 parent a641404 commit e431dcc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/guard/jasmine/phantomjs/guard-jasmine.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ errors = {}
# Catch JavaScript errors
#
page.onError = (msg, trace) ->
if currentSpecId && currentSpecId isnt -1
if currentSpecId
errors[currentSpecId] ||= []
errors[currentSpecId].push({ msg: msg, trace: trace })

Expand All @@ -42,7 +42,7 @@ page.onConsoleMessage = (msg, line, source) ->
logs[currentSpecId] = []

else
logs[currentSpecId].push(msg) if currentSpecId isnt -1
logs[currentSpecId].push(msg)

# Initialize the page before the JavaScript is run.
#
Expand Down
7 changes: 3 additions & 4 deletions lib/guard/jasmine/phantomjs/guard-jasmine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions lib/guard/jasmine/phantomjs/lib/result.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion lib/guard/jasmine/phantomjs/src/result.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ class Result

suite

addGlobalError: (suite) ->
noSuites = !suite.suites || suite.suites.length == 0
noSpecs = !suite.specs || suite.specs.length == 0
globalErrors = @errors[-1] && @errors[-1].length != 0

if noSuites && noSpecs && globalErrors
err = @errors[-1][0]
errMsg = [ err.msg ]
for b in err.trace
errMsg.push "\n #{b.file}:#{b.line} #{b.function}"
suite.error = errMsg.join("")
suite.passed = false

# Clean unnecessary properties from the result
#
# @param [Object] suite the suite result
Expand All @@ -69,7 +82,9 @@ class Result
#
process: ->
@addLogs(@result) if @options.console isnt 'never'
@addErrors(@result) if @options.errors isnt 'never'
if @options.errors isnt 'never'
@addErrors(@result)
@addGlobalError(@result)
@cleanResult(@result)

@result
Expand Down

0 comments on commit e431dcc

Please sign in to comment.