кто-нибудь интегрировал тесты QUnit с ZombieJS? У меня есть сценарий, поэтому я хочу передать файл «tests.html» и опросить до завершения тестов, а затем прочитать результаты. Подобно тому, что я делаю с PhantomJS, и он отлично работает. В основном я хотел бы сравнить Phantom и Zombie с точки зрения производительности. Кроме того, у нас уже создано много тестов Qunit, поэтому я не хочу просто сбрасывать их и переписывать все с нуля в среде зомби (если я решу пойти на это в первую очередь :)
проблема, с которой я сталкиваюсь, заключается в том, что мои тесты никогда не завершаются, поэтому Qunit всегда находится в рабочем состоянии. Еще ничего не отлаживал подробно, но просто хотел убедиться, что я не упустил что-то очевидное.
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);
});
});