has anyone integrated QUnit tests with ZombieJS? I have a script so i want to pass a "tests.html" file and poll until the tests complete, then read the results. Similar to what i'm doing with PhantomJS and it works perfectly fine. I'd mostly like to compare Phantom and Zombie with respect to performance. Also we have a lot of Qunit tests already created so i don't want to just dump them and rewrite everything from scratch in the Zombie environment (if i decide to go for it in the first place :)
the issue i am facing is that my tests never complete, so Qunit is always in running state. Haven't debugged anything in detail yet, but just wanted to make sure i am not missing something obvious.
var Browser = require("zombie");
var assert = require("assert");
// Load the page from localhost
browser = new Browser();
function waitFor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 100000, //< Default Max Timout is 3s
start = new Date().getTime(),
condition = false,
interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
// If not time-out yet and condition not yet fulfilled
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
} else {
if(!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
process.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
clearInterval(interval); //< Stop this interval
}
}
}, 100); //< repeat check every 250ms
};
browser.visit("tests.html", function () {
waitFor(function(){
return browser.evaluate(function(){
var el = browser.document.getElementById('qunit-testresult');
if (el && el.textContent.match('completed')) {
return true;
}
return false;
});
}, function(){
var failedNum = browser.evaluate(function(){
var el = browser.document.getElementById('qunit-testresult');
console.log(el.textContent);
try {
return el.getElementsByClassName('failed')[0].innerHTML;
} catch (e) { }
return 10000;
});
process.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
});
});