jasmine-headless-webkit/jasmine/jasmine.headless-reporter.coffee

118 lines
3.3 KiB
CoffeeScript
Raw Normal View History

2011-05-12 21:02:11 +00:00
if !jasmine?
2011-06-13 12:14:24 +00:00
throw new Error("jasmine not laoded!")
2011-05-12 21:02:11 +00:00
2011-09-06 15:37:29 +00:00
# Jasmine extensions
getSplitName = (parts) ->
parts.push(String(@description).replace(/[\n\r]/g, ' '))
parts
jasmine.Suite.prototype.getSuiteSplitName = ->
this.getSplitName(if @parentSuite then @parentSuite.getSuiteSplitName() else [])
jasmine.Spec.prototype.getSpecSplitName = ->
this.getSplitName(@suite.getSuiteSplitName())
jasmine.Suite.prototype.getSplitName = getSplitName
jasmine.Spec.prototype.getSplitName = getSplitName
jasmine.Spec.prototype.getJHWSpecInformation = ->
parts = this.getSpecSplitName()
specLineInfo = HeadlessReporterResult.findSpecLine(parts)
parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}")
parts.join("||")
if !jasmine.WaitsBlock.prototype._execute
jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute
jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute
pauseAndRun = (onComplete) ->
JHW.timerPause()
this._execute ->
JHW.timerDone()
onComplete()
jasmine.WaitsBlock.prototype.execute = pauseAndRun
jasmine.WaitsForBlock.prototype.execute = pauseAndRun
# Try to get the line number of a failed spec
2011-07-14 14:54:44 +00:00
class window.HeadlessReporterResult
constructor: (@name, @splitName) ->
2011-05-12 21:02:11 +00:00
@results = []
2011-05-12 22:47:56 +00:00
addResult: (message) ->
@results.push(message)
2011-05-12 21:02:11 +00:00
print: ->
output = @name
bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
output += " (#{bestChoice.file}:#{bestChoice.lineNumber})" if bestChoice.file
JHW.printName(output)
2011-05-12 21:02:11 +00:00
for result in @results
JHW.printResult(result)
@findSpecLine: (splitName) ->
bestChoice = { accuracy: 0, file: null, lineNumber: null }
2011-07-14 14:54:44 +00:00
for file, lines of HeadlessReporterResult.specLineNumbers
index = 0
2011-07-14 14:54:44 +00:00
lineNumber = 0
while newLineNumberInfo = lines[splitName[index]]
2011-07-14 14:54:44 +00:00
if newLineNumberInfo.length == 0
lineNumber = newLineNumberInfo[0]
else
lastLine = null
for line in newLineNumberInfo
lastLine = line
break if line > lineNumber
lineNumber = lastLine
index++
if index > bestChoice.accuracy
bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
bestChoice
2011-09-06 15:37:29 +00:00
# The reporter itself.
2011-05-12 21:02:11 +00:00
class jasmine.HeadlessReporter
constructor: (@callback = null) ->
2011-05-12 21:02:11 +00:00
@results = []
@failedCount = 0
@length = 0
reportRunnerResults: (runner) ->
return if this.hasError()
2011-05-12 21:02:11 +00:00
for result in @results
result.print()
2011-05-12 21:02:11 +00:00
this.callback() if @callback
2011-05-12 22:47:56 +00:00
JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount)
2011-05-12 21:02:11 +00:00
reportRunnerStarting: (runner) ->
2011-05-12 22:47:56 +00:00
@startTime = new Date()
2011-05-12 21:02:11 +00:00
reportSpecResults: (spec) ->
return if this.hasError()
2011-05-16 02:42:02 +00:00
results = spec.results()
2011-06-08 17:47:51 +00:00
@length++
2011-05-16 02:42:02 +00:00
if results.passed()
JHW.specPassed(spec.getJHWSpecInformation())
2011-05-12 21:02:11 +00:00
else
JHW.specFailed(spec.getJHWSpecInformation())
2011-06-08 17:47:51 +00:00
@failedCount++
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName())
2011-05-16 02:42:02 +00:00
for result in results.getItems()
if result.type == 'expect' and !result.passed_
failureResult.addResult(result.message)
2011-05-12 21:02:11 +00:00
@results.push(failureResult)
2011-05-12 21:02:11 +00:00
reportSpecStarting: (spec) ->
if this.hasError()
spec.finish()
spec.suite.finish()
2011-05-12 21:02:11 +00:00
reportSuiteResults: (suite) ->
hasError: ->
JHW.hasError()