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
|
2011-07-13 18:42:47 +00:00
|
|
|
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: ->
|
2011-07-13 18:42:47 +00:00
|
|
|
output = @name
|
2011-09-02 19:52:19 +00:00
|
|
|
bestChoice = HeadlessReporterResult.findSpecLine(@splitName)
|
2011-07-13 18:42:47 +00:00
|
|
|
output += " (#{bestChoice.file}:#{bestChoice.lineNumber})" if bestChoice.file
|
|
|
|
|
|
|
|
JHW.printName(output)
|
2011-05-12 21:02:11 +00:00
|
|
|
for result in @results
|
2011-07-22 13:40:40 +00:00
|
|
|
JHW.printResult(result)
|
2011-09-02 19:52:19 +00:00
|
|
|
@findSpecLine: (splitName) ->
|
2011-07-13 18:42:47 +00:00
|
|
|
bestChoice = { accuracy: 0, file: null, lineNumber: null }
|
|
|
|
|
2011-07-14 14:54:44 +00:00
|
|
|
for file, lines of HeadlessReporterResult.specLineNumbers
|
2011-07-13 18:42:47 +00:00
|
|
|
index = 0
|
2011-07-14 14:54:44 +00:00
|
|
|
lineNumber = 0
|
2011-09-02 19:52:19 +00:00
|
|
|
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
|
|
|
|
|
2011-07-13 18:42:47 +00:00
|
|
|
index++
|
|
|
|
|
|
|
|
if index > bestChoice.accuracy
|
|
|
|
bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
|
|
|
|
|
|
|
|
bestChoice
|
|
|
|
|
|
|
|
jasmine.Suite.prototype.getSuiteSplitName = ->
|
|
|
|
parts = if @parentSuite then @parentSuite.getSuiteSplitName() else []
|
2011-09-02 19:52:19 +00:00
|
|
|
parts.push(String(@description).replace(/[\n\r]/g, ' '))
|
2011-07-13 18:42:47 +00:00
|
|
|
parts
|
|
|
|
|
|
|
|
jasmine.Spec.prototype.getSpecSplitName = ->
|
|
|
|
parts = @suite.getSuiteSplitName()
|
2011-09-02 19:52:19 +00:00
|
|
|
parts.push(String(@description).replace(/[\n\r]/g, ' '))
|
2011-07-13 18:42:47 +00:00
|
|
|
parts
|
2011-05-12 21:02:11 +00:00
|
|
|
|
2011-09-02 19:52:19 +00:00
|
|
|
jasmine.Spec.prototype.getJHWSpecInformation = ->
|
|
|
|
parts = this.getSpecSplitName()
|
|
|
|
specLineInfo = HeadlessReporterResult.findSpecLine(parts)
|
|
|
|
parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}")
|
|
|
|
parts.join("||")
|
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
class jasmine.HeadlessReporter
|
2011-07-22 11:42:25 +00:00
|
|
|
constructor: (@callback = null) ->
|
2011-05-12 21:02:11 +00:00
|
|
|
@results = []
|
|
|
|
@failedCount = 0
|
|
|
|
@length = 0
|
|
|
|
reportRunnerResults: (runner) ->
|
2011-08-07 18:45:57 +00:00
|
|
|
return if this.hasError()
|
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
for result in @results
|
2011-07-22 13:40:40 +00:00
|
|
|
result.print()
|
2011-05-12 21:02:11 +00:00
|
|
|
|
2011-07-22 11:42:25 +00:00
|
|
|
this.callback() if @callback
|
2011-05-12 22:47:56 +00:00
|
|
|
JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount)
|
2011-09-02 19:52:19 +00:00
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
reportRunnerStarting: (runner) ->
|
2011-05-12 22:47:56 +00:00
|
|
|
@startTime = new Date()
|
2011-09-02 19:52:19 +00:00
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
reportSpecResults: (spec) ->
|
2011-08-07 18:45:57 +00:00
|
|
|
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()
|
2011-09-02 19:52:19 +00:00
|
|
|
JHW.specPassed(spec.getJHWSpecInformation())
|
2011-05-12 21:02:11 +00:00
|
|
|
else
|
2011-09-02 19:52:19 +00:00
|
|
|
JHW.specFailed(spec.getJHWSpecInformation())
|
2011-06-08 17:47:51 +00:00
|
|
|
@failedCount++
|
2011-07-13 18:42:47 +00:00
|
|
|
failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName())
|
2011-05-16 02:42:02 +00:00
|
|
|
for result in results.getItems()
|
2011-07-22 13:40:40 +00:00
|
|
|
if result.type == 'expect' and !result.passed_
|
|
|
|
failureResult.addResult(result.message)
|
2011-05-12 21:02:11 +00:00
|
|
|
@results.push(failureResult)
|
2011-09-02 19:52:19 +00:00
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
reportSpecStarting: (spec) ->
|
2011-08-07 18:45:57 +00:00
|
|
|
if this.hasError()
|
|
|
|
spec.finish()
|
|
|
|
spec.suite.finish()
|
2011-09-02 19:52:19 +00:00
|
|
|
|
2011-05-12 21:02:11 +00:00
|
|
|
reportSuiteResults: (suite) ->
|
2011-08-07 18:45:57 +00:00
|
|
|
hasError: ->
|
|
|
|
JHW.hasError()
|
|
|
|
|