Skip to content

Commit

Permalink
Update the PhantomJS test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed May 19, 2017
1 parent aeec7eb commit 243d445
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 55 deletions.
5 changes: 4 additions & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ while ! lsof -i :$port >/dev/null; do
sleep .05
done

phantomjs ./test/run-qunit.coffee "http://localhost:$port/"
phantomjs ./test/run-qunit.js \
"http://localhost:$port/?jquery=3.2" \
"http://localhost:$port/?jquery=2.2" \
"http://localhost:$port/?jquery=1.12"
54 changes: 0 additions & 54 deletions test/run-qunit.coffee

This file was deleted.

87 changes: 87 additions & 0 deletions test/run-qunit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
var fs = require('fs')
var suites = require('system').args.slice(1)

function print(s) {
fs.write('/dev/stdout', s, 'w')
}

var page = require('webpage').create()
page.onConsoleMessage = function(msg) {
console.log(msg)
}
page.onError = function(msg) {
console.error('ERROR: ' + msg)
}

var timeoutId = null
function deferTimeout() {
if (timeoutId) clearTimeout(timeoutId)
timeoutId = setTimeout(function() {
console.error('Timeout')
phantom.exit(1)
}, 3000)
}

var endresult = 0

function runSuite() {
var suite = suites.shift()
if (!suite) {
phantom.exit(endresult)
return
}

page.open(suite, function() {
deferTimeout()

var interval = setInterval(function() {
var tests = page.evaluate(function() {
var results = []
var els = document.getElementById('qunit-tests').children

for (var i = 0; i < els.length; i++) {
var test = els[i]
if (test.className !== 'running' && !test.recorded) {
test.recorded = true
if (test.className === 'pass') results.push('.')
else if (test.className === 'fail') results.push('F')
}
}

return results
})

for (var i = 0; i < tests.length; i++) {
deferTimeout()
print(tests[i])
}

var result = page.evaluate(function() {
var testresult = document.getElementById('qunit-testresult')
var els = document.getElementById('qunit-tests').children

if (testresult.innerText.match(/completed/)) {
console.log('')

for (var i = 0; i < els.length; i++) {
var test = els[i]
if (test.className === 'fail') {
console.error(test.innerText)
}
}

console.log(testresult.innerText)
return parseInt(testresult.getElementsByClassName('failed')[0].innerText)
}
})

if (result != null) {
endresult = result
clearInterval(interval)
runSuite()
}
}, 100)
})
}

runSuite()

0 comments on commit 243d445

Please sign in to comment.