Skip to content

Commit

Permalink
Test compatibility with PhantomJS 2
Browse files Browse the repository at this point in the history
PhantomJS 2 dropped support for test runner script being authored in
CoffeeScript, so compile this script to JS and use that instead.
  • Loading branch information
mislav committed Jul 12, 2016
1 parent c61f38f commit 82d31d8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 74 deletions.
2 changes: 1 addition & 1 deletion make
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ target.all = ->
target.test = ->
test_app = require './test/server'
server = test_app.listen port
exec "phantomjs --disk-cache=true test/runner.coffee 'http://localhost:#{port}/'", (code) ->
exec "phantomjs --disk-cache=true test/runner.js 'http://localhost:#{port}/'", (code) ->
server.close -> exit(code)

target[zepto_js] = ->
Expand Down
2 changes: 1 addition & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ done
trap terminate_test_server EXIT

phantomjs --disk-cache=true \
test/runner.coffee "$test_url" "$@" \
test/runner.js "$test_url" "$@" \
2> >(grep -v "CoreText performance note" >&2)

exit $?
72 changes: 0 additions & 72 deletions test/runner.coffee

This file was deleted.

83 changes: 83 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
(function() {
var fs = require('fs')
var system = require('system')
var args = system.args.slice(1)

var prefix = args.shift() || ("file://" + fs.workingDirectory + "/")

var suites
if (args.length > 0) {
suites = args
} else {
var modules = 'zepto ajax callbacks data deferred ajax_deferred detect touch event form fx selector stack'.split(/\s+/)
suites = modules.map(function(name) {
return "test/" + name + ".html"
})
}

var page = require('webpage').create()

page.onConsoleMessage = function(msg) {
console.log(msg)
}

page.onError = function(msg, trace) {
console.log('ERROR: ' + msg)
}

function waitFor(testFn, onReady, timeout) {
if (timeout == null) {
timeout = 30000
}
var start = new Date()
var interval = setInterval(function() {
if (testFn()) {
clearInterval(interval)
onReady()
} else if (new Date() - start > timeout) {
console.log("timed out.")
phantom.exit(1)
}
}, 100)
}

function loadNextSuite() {
if (!suites.length) {
phantom.exit()
} else {
var url = suites.shift() + "?verbosity=WARN"
if (!/:\/\//.test(url)) {
url = prefix + url
}
page.open(url, function(status) {
if (status !== "success") {
console.log("failed opening " + url)
return phantom.exit(1)
}
waitFor(function() {
return page.evaluate(function() {
var res = document.getElementById('results')
if (res) {
return /finished/.test(res.className)
}
})
}, function() {
var passed = page.evaluate(function() {
var res = document.getElementById('results')
var paths = location.pathname.split('/')
console.log((paths[paths.length - 1] + " - ") + res.textContent)
return /passed/.test(res.className)
})
if (passed) {
loadNextSuite()
} else {
phantom.exit(1)
}
})
})
}
}

loadNextSuite()

}).call(this)

0 comments on commit 82d31d8

Please sign in to comment.