<commit_before>var util = require('util');
var path = require('path')
var fs = require('fs');
var webdriver = require('selenium-webdriver');
var remote = require('selenium-webdriver/remote');
var jasmine = require('jasmine-node');
var protractor = require('./protractor.js');
var SauceLabs = require('saucelabs');

var args = process.argv.slice(2);

// Default configuration.
var config = {
  seleniumServerJar: null,
  seleniumArgs: [],
  seleniumPort: null,
  seleniumAddress: null,
  capabilities: {
    'browserName': 'chrome'
  },
  jasmineNodeOpts: {
    specFolders: [],
    onComplete: null,
    isVerbose: false,
    showColors: true,
    includeStackTrace: true
  }
}

var originalOnComplete = config.jasmineNodeOpts.onComplete;

var server;
var driver;
var id;

var cleanUp = function(runner, log) {
  var passed = runner.results().failedCount == 0;
  if (sauceAccount) {
    sauceAccount.updateJob(id, {'passed': passed}, function() {});
  }
  if (originalOnComplete) {
    originalOnComplete(runner, log);
  }
  driver.quit();
  if (server) {
    util.puts('Shutting down selenium standalone server');
    server.stop();
  }
};

var printVersion = function () {
  util.puts('Version ' + JSON.parse(
      fs.readFileSync(__dirname + '/../package.json', 'utf8')).version);
  process.exit(0);
};

var run = function() {
  // Check the spec folders.
  var specs = config.jasmineNodeOpts.specFolders;
  for (var i = 0; i < specs.length; ++i) {
    specs[i] = path.resolve(process.cwd(), specs[i]);
    if (!fs.existsSync(specs[i])) {
      throw new Error('Test folder/file ' + specs[i] + ' not found.');
    }
  }

  if (config.sauceUser && config.sauceKey) {
    config.capabilities.username = config.sauceUser;
    config.capabilities.accessKey = config.sauceKey;
    config.seleniumAddress = 'http://' + config.sauceUser + ':' +
        config.sauceKey + '@ondemand.saucelabs.com:80/wd/hub';

    util.puts('Using SauceLabs selenium server at ' + config.seleniumAddress);
    startJasmineTests();
  } else if (config.seleniumAddress) {

    util.puts('Using the selenium server at ' + config.seleniumAddress);
    startJasmineTests();<commit_msg>fix(cleanUp): Added step to exit process with error code if tests did not pass.<commit_after>var util = require('util');
var path = require('path')
var fs = require('fs');
var webdriver = require('selenium-webdriver');
var remote = require('selenium-webdriver/remote');
var jasmine = require('jasmine-node');
var protractor = require('./protractor.js');
var SauceLabs = require('saucelabs');

var args = process.argv.slice(2);

// Default configuration.
var config = {
  seleniumServerJar: null,
  seleniumArgs: [],
  seleniumPort: null,
  seleniumAddress: null,
  capabilities: {
    'browserName': 'chrome'
  },
  jasmineNodeOpts: {
    specFolders: [],
    onComplete: null,
    isVerbose: false,
    showColors: true,
    includeStackTrace: true
  }
}

var originalOnComplete = config.jasmineNodeOpts.onComplete;

var server;
var driver;
var id;

var cleanUp = function(runner, log) {
  var passed = runner.results().failedCount == 0;
  if (sauceAccount) {
    sauceAccount.updateJob(id, {'passed': passed}, function() {});
  }
  if (originalOnComplete) {
    originalOnComplete(runner, log);
  }
  driver.quit();
  if (server) {
    util.puts('Shutting down selenium standalone server');
    server.stop();
  }

  process.exit(passed? 0 : 1);
};

var printVersion = function () {
  util.puts('Version ' + JSON.parse(
      fs.readFileSync(__dirname + '/../package.json', 'utf8')).version);
  process.exit(0);
};

var run = function() {
  // Check the spec folders.
  var specs = config.jasmineNodeOpts.specFolders;
  for (var i = 0; i < specs.length; ++i) {
    specs[i] = path.resolve(process.cwd(), specs[i]);
    if (!fs.existsSync(specs[i])) {
      throw new Error('Test folder/file ' + specs[i] + ' not found.');
    }
  }

  if (config.sauceUser && config.sauceKey) {
    config.capabilities.username = config.sauceUser;
    config.capabilities.accessKey = config.sauceKey;
    config.seleniumAddress = 'http://' + config.sauceUser + ':' +
        config.sauceKey + '@ondemand.saucelabs.com:80/wd/hub';

    util.puts('Using SauceLabs selenium server at ' + config.seleniumAddress);
    startJasmineTests();
  } else if (config.seleniumAddress) {

    util.puts('Using the selenium server at ' + config.seleniumAddress);
    startJasmineTests();
{'fraction_non_alphanumeric': 0.15217391304347827, 'fraction_numerical': 0.0036231884057971015, 'mean_word_length': 3.8485181119648737, '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': '7334923', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1465, 'n_words': 323}