Skip to content

Instantly share code, notes, and snippets.

@e2
Created February 28, 2012 11:07
Show Gist options
  • Save e2/1931928 to your computer and use it in GitHub Desktop.
Save e2/1931928 to your computer and use it in GitHub Desktop.
Running PhantomJS tests on Travis
language: ruby
rvm:
- 1.9.3
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- bundle exec rackup ./test/config.ru 2>/dev/null &
- sleep 2
script: phantomjs ./test/run-qunit.js "http://localhost:9292/"
function waitFor(test, complete, timeout) {
var result, start = new Date().getTime()
setInterval(function interval() {
if ((new Date().getTime() - start < timeout) && !result) {
result = test()
} else {
if (!result) {
phantom.exit(1)
} else {
complete()
clearInterval(interval)
}
}
}, 100)
}
var page = new WebPage()
page.onConsoleMessage = function(msg) {
console.log(msg)
}
page.open(phantom.args[0], function(status) {
waitFor(function() {
return page.evaluate(function(){
var el = document.getElementById('qunit-testresult')
return el && el.innerText.match('completed')
})
}, function() {
var failures = page.evaluate(function() {
var el = document.getElementById('qunit-testresult'),
fails = document.getElementsByClassName('fail')
for (var i = 0; i < fails.length; i++)
console.log(fails[i].innerText)
console.log(el.innerText)
return parseInt(el.getElementsByClassName('failed')[0].innerHTML)
})
phantom.exit(failures > 0 ? 1 : 0)
}, 10000)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment