X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fphantom%2Fevaluate.js;h=e7cc91fcf58bab5fce5b8c2dc03b36bbfb45d5ff;hb=7d9fc47cbffe624f129f5552976649dcb1909cbb;hp=e4f7934f0853cfcfcf1242955a4df89ff9db3590;hpb=dbf249f204487107f43e90783dcc243ecd94eae7;p=mkws-moved-to-github.git diff --git a/test/phantom/evaluate.js b/test/phantom/evaluate.js index e4f7934..e7cc91f 100644 --- a/test/phantom/evaluate.js +++ b/test/phantom/evaluate.js @@ -20,40 +20,71 @@ page.viewportSize = { }; var run_time = 12; // poll up to seconds + +/************************/ + +function wait_for_jasmine(checkFx, readyFx, failFx, timeout) { + var max_timeout = timeout ? timeout : run_time * 1000, + start = new Date().getTime(), + result, + condition = false; + + var interval = setInterval(function() { + console.log("."); + + // success + if (condition) { + // console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms."); + readyFx(result); + clearInterval(interval); + phantom.exit(0); + } + + // timeout + else if ( new Date().getTime() - start >= max_timeout ) { + result.time = (new Date().getTime() - start); + failFx(result); + phantom.exit(1); + } + + // checking + else { + result = checkFx(); + condition = result.mkws.jasmine_done; + } + + }, 500); //< repeat check every N ms +}; + + + page.open(url, function (status) { console.log("fetch " + url + " with status: " + status); console.log("polling MKWS test status..."); - var r; - for (var i = 1; i <= run_time; i++) { - setTimeout(function () { - var result = page.evaluate(function (s) { - // return document.querySelector(s).innerText; - return { - mkws: window.mkws, - duration: window.$(".duration").text(), - passing: window.$(".passingAlert").text() - }; - }, 'title'); - - console.log("."); + var exit = wait_for_jasmine(function () { + return page.evaluate(function () { + return { + mkws: window.mkws, + duration: window.$(".duration").text(), + passing: window.$(".passingAlert").text() + }; + })}, + + function(result) { if (result.mkws.jasmine_done) { console.log("MKWS tests are successfully done. Hooray!"); - console.log("duration: " + result.duration); - console.log("passing: " + result.passing); - phantom.exit(0); + console.log("jasmine duration: " + result.duration); + console.log("jasmine passing: " + result.passing); } - r = result; - }, i * 1000); - } - + }, - setTimeout(function () { - var error_png = "./mkws-error.png"; - console.log("MKWS tests failed after " + run_time + " seconds"); - console.log("keep screenshot in '" + error_png + "'"); + function (result) { + var error_png = "./mkws-error.png"; + console.log("MKWS tests failed after " + result.time/1000 + " seconds"); + console.log("keep screenshot in '" + error_png + "'"); + page.render(error_png); + }, + run_time * 1000); - page.render(error_png); - phantom.exit(1); - }, (run_time + 1) * 1000); });