forked from defunkt/jquery-pjax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-qunit.coffee
54 lines (41 loc) · 1.27 KB
/
run-qunit.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
47
48
49
50
51
52
53
54
fs = require 'fs'
print = (s) -> fs.write "/dev/stderr", s, 'w'
page = new WebPage()
page.onConsoleMessage = (msg) -> console.error msg
timeoutId = null
deferTimeout = ->
clearTimeout timeoutId if timeoutId
timeoutId = setTimeout ->
console.error "Timeout"
phantom.exit 1
, 3000
exited = false
page.open phantom.args[0], ->
deferTimeout()
setInterval ->
return if exited
tests = page.evaluate ->
tests = document.getElementById('qunit-tests').children
for test in tests when test.className isnt 'running' and not test.recorded
test.recorded = true
if test.className is 'pass'
'.'
else if test.className is 'fail'
'F'
for test in tests when test
deferTimeout()
print test
result = page.evaluate ->
result = document.getElementById('qunit-testresult')
tests = document.getElementById('qunit-tests').children
if result.innerText.match /completed/
console.error ""
for test in tests when test.className is 'fail'
console.error test.innerText
console.error result.innerText
return parseInt result.getElementsByClassName('failed')[0].innerText
return
if result?
exited = true
phantom.exit result
, 100