<commit_before>var
  Q = require('q'),
  assert = require('assert'),
  fs = require('fs'),
  mkdirp = require('mkdirp'),
  path = require('path'),
  asserters = require('wd').asserters,
  express = require('express');

var app = express();
app.use(express.static(path.resolve('/')));
app.listen(3000);

var PageTestCase = function(browser, options, page) {
    this.options = options;
    this.page = page;
    this.browser = browser;
};

var CreateReferenceScreenshot = function(browser, options, page) {
  this.options = options;
  this.page = page;
  this.browser = browser;
};

PageTestCase.prototype.addBatchTo = function (suite, deferred) {
  var batch = {};
  var that = this;

  batch[this.page.name] = {
    topic: function(){
      var
        callback = this.callback,
        resultImage = that.options.resultsPath + '/' + that.page.name + '.png',
        resultImageFileName = path.resolve(resultImage),
        previousImage = that.options.screenshotsPath + '/' + that.page.name + '.png',
        diffImageFileName = path.resolve(that.options.resultsPath + '/' + that.page.name + '.diff.png');

      mkdirp(path.dirname(resultImageFileName));

      that.browser.
        get(that.page.url).
        waitFor(asserters.jsCondition('loaded === true')).
        saveScreenshot(resultImageFileName).
        get('http://localhost:3000' + path.resolve(__dirname, 'image-comparison.html')).
        execute('compare("' + path.resolve(previousImage) + '","' + path.resolve(resultImage) + '")').
        waitForElementById('result', 30000).
        text().
        then(function (value) {
          if (value === '0.00') {
            callback(null, value);
            return;
          }

          that.browser.
            execute('return window.diffImageData').
            then(function (data) {
              var writeFile = Q.denodeify(fs.writeFile);

              return writeFile(diffImageFileName, data, 'base64');
            }).then(function () {
              callback(null, value);
            });

        });
    },
    'should match previous screenshot': function(err, value) {
      assert(parseFloat(value) <= 0.3, 'Mismatch of ' + value + ' found for ' + that.page.name);
    }
  };

  suite.addBatch(batch);
<commit_msg>removing 'loaded' assertion, it is not necessary<commit_after>var
  Q = require('q'),
  assert = require('assert'),
  fs = require('fs'),
  mkdirp = require('mkdirp'),
  path = require('path'),
  asserters = require('wd').asserters,
  express = require('express');

var app = express();
app.use(express.static(path.resolve('/')));
app.listen(3000);

var PageTestCase = function(browser, options, page) {
    this.options = options;
    this.page = page;
    this.browser = browser;
};

var CreateReferenceScreenshot = function(browser, options, page) {
  this.options = options;
  this.page = page;
  this.browser = browser;
};

PageTestCase.prototype.addBatchTo = function (suite, deferred) {
  var batch = {};
  var that = this;

  batch[this.page.name] = {
    topic: function(){
      var
        callback = this.callback,
        resultImage = that.options.resultsPath + '/' + that.page.name + '.png',
        resultImageFileName = path.resolve(resultImage),
        previousImage = that.options.screenshotsPath + '/' + that.page.name + '.png',
        diffImageFileName = path.resolve(that.options.resultsPath + '/' + that.page.name + '.diff.png');

      mkdirp(path.dirname(resultImageFileName));

      that.browser.
        get(that.page.url).
        saveScreenshot(resultImageFileName).
        get('http://localhost:3000' + path.resolve(__dirname, 'image-comparison.html')).
        execute('compare("' + path.resolve(previousImage) + '","' + path.resolve(resultImage) + '")').
        waitForElementById('result', 30000).
        text().
        then(function (value) {
          if (value === '0.00') {
            callback(null, value);
            return;
          }

          that.browser.
            execute('return window.diffImageData').
            then(function (data) {
              var writeFile = Q.denodeify(fs.writeFile);

              return writeFile(diffImageFileName, data, 'base64');
            }).then(function () {
              callback(null, value);
            });

        });
    },
    'should match previous screenshot': function(err, value) {
      assert(parseFloat(value) <= 0.3, 'Mismatch of ' + value + ' found for ' + that.page.name);
    }
  };

  suite.addBatch(batch);

{'fraction_non_alphanumeric': 0.1572832886505809, 'fraction_numerical': 0.008936550491510277, 'mean_word_length': 2.6517128874388254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7217010', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1300, 'n_words': 252}