jasmine-headless-webkit/vendor/assets/coffeescripts/prolog.coffee

68 lines
1.8 KiB
CoffeeScript
Raw Normal View History

2011-10-25 15:25:28 +00:00
if window.JHW
window.console =
log: (data) ->
if typeof(jQuery) != 'undefined' && data instanceof jQuery
JHW.log(style_html($("<div />").append(data).html(), { indent_size: 2 }))
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
window.onbeforeunload = (e) ->
JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.')
2011-10-26 02:22:29 +00:00
JHW.hasError()
return false
2011-10-25 15:25:28 +00:00
window.confirm = (message) ->
2011-10-26 02:22:29 +00:00
JHW.stderr.puts("#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.")
2011-10-25 15:25:28 +00:00
true
window.alert = (message) ->
2011-10-26 02:22:29 +00:00
JHW.stderr.puts("[alert] ".foreground('red') + message)
2011-10-25 15:25:28 +00:00
JHW._hasErrors = false
JHW._handleError = (message, lineNumber, sourceURL) ->
JHW.stderr.puts(message)
JHW._hasErrors = true
false
2011-10-26 02:22:29 +00:00
JHW._setColors = (useColors) ->
Intense.useColors = useColors
2011-10-25 15:25:28 +00:00
createHandle = (handle) ->
2011-10-25 15:25:28 +00:00
JHW[handle] =
print: (content) -> JHW.print(handle, content)
puts: (content) -> JHW.print(handle, content + "\n")
createHandle(handle) for handle in [ 'stdout', 'stderr', 'report' ]
2011-10-26 02:22:29 +00:00
JHW._usedConsole = false
2011-10-25 15:25:28 +00:00
JHW.log = (msg) ->
2011-10-26 02:22:29 +00:00
JHW.hasUsedConsole()
JHW.report.puts("CONSOLE||#{msg}")
JHW._usedConsole = true
2011-10-25 15:25:28 +00:00
JHW.stdout.puts(msg)
2011-10-26 12:45:23 +00:00
window.CoffeeScriptToFilename = {}
2011-10-26 12:55:44 +00:00
window.CSTF = window.CoffeeScriptToFilename