+
+/************************/
+
+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
+};
+
+
+