Permalink
Browse files

Updated Travis CI

  • Loading branch information...
1 parent c608689 commit 1373647d638c88e2e9d1171c207f196058278029 @buger committed Jan 9, 2012
Showing with 143 additions and 26 deletions.
  1. +1 −1 .travis.yml
  2. 0 README
  3. +1 −0 README.md
  4. +64 −0 spec/run_jasmine.coffee
  5. +77 −25 spec/run_jasmine.js
View
@@ -10,4 +10,4 @@ before_script:
- sh -e /etc/init.d/xvfb start
script:
- - DISPLAY=:99.0 phantomjs spec/run_jasmine.js index.html?test_mode
+ - DISPLAY=:99.0 phantomjs spec/run_jasmine.js index.html
View
No changes.
View
@@ -0,0 +1 @@
+[![Build Status](https://secure.travis-ci.org/chromus/chromus.png)](http://travis-ci.org/chromus/chromus)
@@ -0,0 +1,64 @@
+fs = require('fs')
+
+page = new WebPage()
+
+
+waitFor = (testFx, onReady, timeOutMillis=30000) ->
+ start = new Date().getTime()
+ condition = false
+ f = ->
+ if (new Date().getTime() - start < timeOutMillis) and not condition
+ # If not time-out yet and condition not yet fulfilled
+ condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code
+ else
+ if not condition
+ # If condition still not fulfilled (timeout but condition is 'false')
+
+ page_dom = page.evaluate ->
+ document.getElementById('background_page').contentWindow.document.body.querySelector('.finished-at').length
+
+ bg_page = page.evaluate ->
+ document.getElementById('background_page').contentWindow.document.body.innerHTML
+
+ console.log "'waitFor()' timeout", page_dom, bg_page
+
+ phantom.exit(1)
+ else
+ # Condition fulfilled (timeout and/or condition is 'true')
+ console.log "'waitFor()' finished in #{new Date().getTime() - start}ms."
+ if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled
+ clearInterval interval #< Stop this interval
+ interval = setInterval f, 1000 #< repeat check every 100ms
+
+page.onConsoleMessage = (msg) ->
+ console.log(msg)
+
+file_name = fs.absolute(phantom.args[0]) + "?test_mode"
+
+page.open file_name, (status) ->
+ if status isnt "success"
+ console.log "Unable to access network"
+ phantom.exit(1)
+ else
+ waitFor ->
+ page.evaluate ->
+ if document.getElementById('background_page').contentWindow.document.body.querySelector('.finished-at')
+ return true
+ return false;
+ , ->
+ passed = page.evaluate ->
+ passed = 0
+
+ list = document.getElementById('background_page').contentWindow.document.querySelectorAll('div.jasmine_reporter >div.suite.failed')
+
+ for el in list
+ passed = 1
+
+ descs = el.querySelectorAll('.description')
+ for desc in descs
+ console.error desc.innerText
+
+ passed
+
+
+ phantom.exit(passed);
View
@@ -1,29 +1,81 @@
-page.open(phantom.args[0], function(status){
+(function() {
+ var file_name, fs, page, waitFor;
+
+ fs = require('fs');
+
+ page = new WebPage();
+
+ waitFor = function(testFx, onReady, timeOutMillis) {
+ var condition, f, interval, start;
+ if (timeOutMillis == null) timeOutMillis = 30000;
+ start = new Date().getTime();
+ condition = false;
+ f = function() {
+ var bg_page, page_dom;
+ if ((new Date().getTime() - start < timeOutMillis) && !condition) {
+ return condition = (typeof testFx === 'string' ? eval(testFx) : testFx());
+ } else {
+ if (!condition) {
+ page_dom = page.evaluate(function() {
+ return document.getElementById('background_page').contentWindow.document.body.querySelector('.finished-at').length;
+ });
+ bg_page = page.evaluate(function() {
+ return document.getElementById('background_page').contentWindow.document.body.innerHTML;
+ });
+ console.log("'waitFor()' timeout", page_dom, bg_page);
+ return phantom.exit(1);
+ } else {
+ console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
+ if (typeof onReady === 'string') {
+ eval(onReady);
+ } else {
+ onReady();
+ }
+ return clearInterval(interval);
+ }
+ }
+ };
+ return interval = setInterval(f, 1000);
+ };
+
+ page.onConsoleMessage = function(msg) {
+ return console.log(msg);
+ };
+
+ file_name = fs.absolute(phantom.args[0]) + "?test_mode";
+
+ page.open(file_name, function(status) {
if (status !== "success") {
- console.log("Unable to access network");
- phantom.exit();
+ console.log("Unable to access network");
+ return phantom.exit(1);
} else {
- waitFor(function(){
- return page.evaluate(function(){
- if (document.body.querySelector('.finished-at')) {
- return true;
- }
- return false;
- });
- }, function(){
- page.evaluate(function(){
- console.log(document.body.querySelector('.description').innerText);
- list = document.body.querySelectorAll('div.jasmine_reporter > div.suite.failed');
- for (i = 0; i < list.length; ++i) {
- el = list[i];
- desc = el.querySelectorAll('.description');
- console.log('');
- for (j = 0; j < desc.length; ++j) {
- console.log(desc[j].innerText);
- }
- }
- });
- phantom.exit();
+ return waitFor(function() {
+ return page.evaluate(function() {
+ if (document.getElementById('background_page').contentWindow.document.body.querySelector('.finished-at')) {
+ return true;
+ }
+ return false;
});
+ }, function() {
+ var passed;
+ passed = page.evaluate(function() {
+ var desc, descs, el, list, _i, _j, _len, _len2;
+ passed = 0;
+ list = document.getElementById('background_page').contentWindow.document.querySelectorAll('div.jasmine_reporter >div.suite.failed');
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
+ el = list[_i];
+ passed = 1;
+ descs = el.querySelectorAll('.description');
+ for (_j = 0, _len2 = descs.length; _j < _len2; _j++) {
+ desc = descs[_j];
+ console.error(desc.innerText);
+ }
+ }
+ return passed;
+ });
+ return phantom.exit(passed);
+ });
}
-});
+ });
+
+}).call(this);

0 comments on commit 1373647

Please sign in to comment.