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

101 lines
2.4 KiB
CoffeeScript
Raw Permalink 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
puts = (message) ->
JHW.print('stdout', message + "\n")
warn = (message) ->
puts(message) if !JHW.isQuiet()
# 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()
warn "The code tried to leave the test page. Check for unhandled form submits and link clicks."
2011-11-05 18:19:41 +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
# script errors
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
# dialogs
window.confirm = ->
warn "#{"[confirm]".foreground('red')} You should mock window.confirm. Returning true."
true
window.prompt = ->
warn "#{"[prompt]".foreground('red')} You should mock window.prompt. Returning true."
true
2011-10-25 15:25:28 +00:00
window.alert = (message) ->
warn "[alert] ".foreground('red') + message
2011-10-26 02:22:29 +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
puts msg
2011-10-25 15:25:28 +00:00
2012-01-11 20:41:27 +00:00
JHW.createCoffeeScriptFileException = (e) ->
2012-01-12 21:47:36 +00:00
if e and e.sourceURL
2012-01-11 20:41:27 +00:00
filename = e.sourceURL.split('/').pop()
2012-01-12 21:47:36 +00:00
e =
name: e.name
message: e.message
sourceURL: e.sourceURL
lineNumber: e.line
if window.CoffeeScriptToFilename and realFilename = window.CoffeeScriptToFilename[filename]
e.sourceURL = realFilename
e.lineNumber = "~" + String(e.line)
2012-01-11 20:41:27 +00:00
e
2011-10-26 12:45:23 +00:00
window.CoffeeScriptToFilename = {}
2011-10-26 12:55:44 +00:00
window.CSTF = window.CoffeeScriptToFilename