<NME> casperTests.js
<BEF> /**
 * This test runs the extension end-to-end for a list of urls in url_list,
 * verifying that all urls trigger the banner.
 */

var TIMEOUT = 1 * 60 * 1000;  // per site, in ms
var fs = require('fs');
var utils = require('utils');
var rules = JSON.parse(fs.read('url_list'));

casper.userAgent('Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36');
casper.options.stepTimeout = TIMEOUT;
casper.options.onStepTimeout = function(request) {
casper.userAgent('Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36');
casper.options.stepTimeout = TIMEOUT;
casper.options.onStepTimeout = function() {
  this.test.fail(this.requestUrl + ' loads in less than ' + TIMEOUT + 'ms.');
};

// For loop won't work here for some reason.
function run(idx) {
  if (idx >= rules.length) return;
  var rule = rules[idx];
  casper.test.begin('Banner appears on ' + rule.example,
                    1, function(test) {
    if (expectVisible) {
      test.assert(bannerIsVisible, 'Banner should be visible on ' + url);
    } else {
      test.assert(!bannerIsVisible, 'Banner should *not* be visible on ' + url);
    }
  };

  casper.start().each(rules, function(self, rule) {

    casper.run(function() {
      test.done();

      run(idx + 1);
    });
  });
    self.then(function() {
      casper.echo('Loading ' + rule.root + ' ...');
    });
    self.thenOpen(rule.root, function() {
      if (rule.shouldRootDomainTrigger) {
        testBanner.call(this, rule.root, true);
      } else {
        testBanner.call(this, rule.root, false);
      }
    });
  });
  casper.run(function() {
    test.done();
  });
});

<MSG> Finish converting rules to helper functions

<DFF> @@ -14,12 +14,16 @@ var rules = JSON.parse(fs.read('test_url_list'));
 casper.userAgent('Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36');
 casper.options.stepTimeout = TIMEOUT;
 casper.options.onStepTimeout = function() {
-  this.test.fail(this.requestUrl + ' loads in less than ' + TIMEOUT + 'ms.');
+  casper.echo('Test timed out');
+  this.test.assert(false);
+  //this.test.fail(this.requestUrl + ' loads in less than ' + TIMEOUT + 'ms.');
+  run(this.idx + 1);
 };
 
 // For loop won't work here for some reason.
 function run(idx) {
   if (idx >= rules.length) return;
+  this.idx = idx;
   var rule = rules[idx];
   casper.test.begin('Banner appears on ' + rule.example,
                     1, function(test) {
@@ -34,7 +38,6 @@ function run(idx) {
 
     casper.run(function() {
       test.done();
-
       run(idx + 1);
     });
   });

{'addition_count': 5, 'commit_subject': 'Finish converting rules to helper functions', 'deletion_count': 2, 'file_extension': '.js', 'lang': 'js', 'license': 'mit', 'repo_name': 'typpo/ad-detector'}