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

70 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.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
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-29 23:37:23 +00:00
JHW.print('stdout', "The code tried to leave the test page. Check for unhandled form submits and link clicks.\n")
2011-11-05 18:19:41 +00:00
if e
e.returnValue = 'string'
return 'string'
2011-10-25 15:25:28 +00:00
window.confirm = (message) ->
2011-12-29 23:37:23 +00:00
JHW.print('stdout', "#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.\n")
2011-10-25 15:25:28 +00:00
true
window.alert = (message) ->
2011-12-29 23:37:23 +00:00
JHW.print('stdout', "[alert] ".foreground('red') + message + "\n")
2011-10-25 15:25:28 +00:00
JHW._hasErrors = false
JHW._handleError = (message, lineNumber, sourceURL) ->
2011-12-29 23:37:23 +00:00
JHW.print('stderr', message + "\n")
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
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()
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-29 23:37:23 +00:00
JHW.print('stdout', msg + "\n")
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