1 system = require 'system'
4 # Wait until the test condition is true or a timeout occurs. Useful for waiting
5 # on a server response or for a ui change (fadeIn, etc.) to occur.
7 # @param testFx javascript condition that evaluates to a boolean,
8 # it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
9 # as a callback function.
10 # @param onReady what to do when testFx condition is fulfilled,
11 # it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
12 # as a callback function.
13 # @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
15 waitFor = (testFx, onReady, timeOutMillis=3000) ->
16 start = new Date().getTime()
19 if (new Date().getTime() - start < timeOutMillis) and not condition
20 # If not time-out yet and condition not yet fulfilled
21 condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
24 # If condition still not fulfilled (timeout but condition is 'false')
25 console.log "'waitFor()' timeout"
28 # Condition fulfilled (timeout and/or condition is 'true')
29 console.log "'waitFor()' finished in #{new Date().getTime() - start}ms."
30 if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
31 clearInterval interval #< Stop this interval
32 interval = setInterval f, 100 #< repeat check every 100ms
34 if system.args.length isnt 2
35 console.log 'Usage: run-jasmine.coffee URL'
38 page = require('webpage').create()
40 # Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
41 page.onConsoleMessage = (msg) ->
44 page.open system.args[1], (status) ->
45 if status isnt 'success'
46 console.log 'Unable to access network'
51 if document.body.querySelector '.finished-at'
56 console.log document.body.querySelector('.description').innerText
57 list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage')
59 console.log el.innerText