-
Notifications
You must be signed in to change notification settings - Fork 18
/
run_jasmine.coffee
executable file
·46 lines (34 loc) · 1.2 KB
/
run_jasmine.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/local/bin/phantomjs
# Runs a Jasmine Suite from an html page
# @page is a PhantomJs page object
# @exit_func is the function to call in order to exit the script
class PhantomJasmineRunner
constructor: (@page, @exit_func = phantom.exit) ->
@tries = 0
@max_tries = 10
get_status: -> @page.evaluate(-> consoleReporter.status)
terminate: ->
switch @get_status()
when "success" then @exit_func 0
when "fail" then @exit_func 1
else @exit_func 2
# Script Begin
if phantom.args.length == 0
console.log "Need a url as the argument"
phantom.exit 1
page = new WebPage()
runner = new PhantomJasmineRunner(page)
# Don't supress console output
page.onConsoleMessage = (msg) ->
console.log msg
# Terminate when the reporter singals that testing is over.
# We cannot use a callback function for this (because page.evaluate is sandboxed),
# so we have to *observe* the website.
if msg == "ConsoleReporter finished"
runner.terminate()
address = phantom.args[0]
page.open address, (status) ->
if status != "success"
console.log "can't load the address!"
phantom.exit 1
# Now we wait until onConsoleMessage reads the termination signal from the log.