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

81 lines
2.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-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 = this._findSpecLine()
output += " (#{bestChoice.file}:#{bestChoice.lineNumber})" if bestChoice.file
JHW.printName(output)
2011-05-12 21:02:11 +00:00
for result in @results
do (result) =>
JHW.printResult(result)
_findSpecLine: ->
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]]
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
jasmine.Suite.prototype.getSuiteSplitName = ->
parts = if @parentSuite then @parentSuite.getSuiteSplitName() else []
parts.push(@description)
parts
jasmine.Spec.prototype.getSpecSplitName = ->
parts = @suite.getSuiteSplitName()
parts.push(@description)
parts
2011-05-12 21:02:11 +00:00
class jasmine.HeadlessReporter
constructor: ->
@results = []
@failedCount = 0
@length = 0
reportRunnerResults: (runner) ->
for result in @results
do (result) =>
result.print()
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) ->
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()
2011-05-12 21:02:11 +00:00
JHW.specPassed()
else
JHW.specFailed(spec.getSpecSplitName().join('||'))
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()
2011-05-12 21:02:11 +00:00
do (result) =>
if result.type == 'expect' and !result.passed_
2011-05-12 22:47:56 +00:00
failureResult.addResult(result.message)
2011-05-12 21:02:11 +00:00
@results.push(failureResult)
reportSpecStarting: (spec) ->
reportSuiteResults: (suite) ->