2011-10-25 15:25:28 +00:00
|
|
|
if window.JHW
|
|
|
|
window.console =
|
|
|
|
log: (data) ->
|
|
|
|
if typeof(jQuery) != 'undefined' && data instanceof jQuery
|
2011-11-21 06:14:57 +00:00
|
|
|
JHW.log(style_html($("<div />").append(data.clone()).html(), { indent_size: 2 }))
|
2011-10-25 15:25:28 +00:00
|
|
|
else
|
|
|
|
useJsDump = true
|
|
|
|
|
|
|
|
try
|
|
|
|
if typeof data.toJSON == 'function'
|
|
|
|
JHW.log("JSON: #{JSON.stringify(data, null, 2)}")
|
|
|
|
useJsDump = false
|
|
|
|
catch e
|
|
|
|
|
|
|
|
if useJsDump
|
|
|
|
dump = jsDump.doParse(data)
|
|
|
|
if dump.indexOf("\n") == -1
|
|
|
|
JHW.log(dump)
|
|
|
|
else
|
|
|
|
JHW.log("jsDump: #{dump}")
|
2011-10-27 00:05:05 +00:00
|
|
|
|
2011-10-25 15:25:28 +00:00
|
|
|
pp: (data) ->
|
|
|
|
JHW.log(if jasmine then jasmine.pp(data) else console.log(data))
|
2011-10-27 00:05:05 +00:00
|
|
|
|
2011-10-25 15:25:28 +00:00
|
|
|
peek: (data) ->
|
|
|
|
console.log(data)
|
|
|
|
data
|
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
puts = (message) ->
|
|
|
|
JHW.print('stdout', message + "\n")
|
|
|
|
|
|
|
|
# handle unloading
|
2011-10-25 15:25:28 +00:00
|
|
|
window.onbeforeunload = (e) ->
|
2011-11-05 18:19:41 +00:00
|
|
|
e = e || window.event
|
|
|
|
|
2011-10-26 02:22:29 +00:00
|
|
|
JHW.hasError()
|
2011-12-30 15:47:08 +00:00
|
|
|
puts "The code tried to leave the test page. Check for unhandled form submits and link clicks."
|
2011-11-05 18:19:41 +00:00
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
e.returnValue = 'string' if e
|
2011-11-05 18:19:41 +00:00
|
|
|
|
|
|
|
return 'string'
|
2011-10-25 15:25:28 +00:00
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
# script errors
|
2011-10-25 19:41:22 +00:00
|
|
|
JHW._hasErrors = false
|
|
|
|
JHW._handleError = (message, lineNumber, sourceURL) ->
|
2011-12-29 23:37:23 +00:00
|
|
|
JHW.print('stderr', message + "\n")
|
2011-10-25 19:41:22 +00:00
|
|
|
JHW._hasErrors = true
|
|
|
|
false
|
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
# dialogs
|
|
|
|
window.confirm = (message) ->
|
|
|
|
puts "#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true."
|
|
|
|
|
|
|
|
true
|
2011-10-25 15:25:28 +00:00
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
window.alert = (message) ->
|
|
|
|
puts "[alert] ".foreground('red') + message
|
2011-10-26 02:22:29 +00:00
|
|
|
|
2011-12-30 15:47:08 +00:00
|
|
|
# color support
|
|
|
|
JHW._setColors = (useColors) -> Intense.useColors = useColors
|
|
|
|
|
|
|
|
# console.log support
|
|
|
|
JHW._usedConsole = false
|
2011-10-25 15:25:28 +00:00
|
|
|
JHW.log = (msg) ->
|
2011-10-26 02:22:29 +00:00
|
|
|
JHW.hasUsedConsole()
|
2011-12-29 23:37:23 +00:00
|
|
|
|
|
|
|
for reporter in jasmine.getEnv().reporter.subReporters_
|
|
|
|
reporter.consoleLogUsed(msg) if reporter.consoleLogUsed?
|
|
|
|
|
2011-10-26 02:22:29 +00:00
|
|
|
JHW._usedConsole = true
|
2011-12-30 15:47:08 +00:00
|
|
|
|
|
|
|
puts msg
|
2011-10-25 15:25:28 +00:00
|
|
|
|
2011-10-26 12:45:23 +00:00
|
|
|
window.CoffeeScriptToFilename = {}
|
2011-10-26 12:55:44 +00:00
|
|
|
window.CSTF = window.CoffeeScriptToFilename
|
|
|
|
|