<commit_before>#!/usr/bin/env node
"use strict";

var path = require('path');
var spawn = require('child_process').spawn;

var wd = require('wd');
var devserver = require('./dev-server.js');

var SELENIUM_PATH = '../vendor/selenium-server-standalone-2.38.0.jar';
var testUrl = 'http://127.0.0.1:8000/tests/test.html';
var testTimeout = 30 * 60 * 1000;

var client;

if (process.env.GREP) {
  testUrl += '?grep=' + process.env.GREP;
}

if (process.env.TRAVIS) {
  process.exit(0);
}

function startServers(callback) {

  // Starts the file and CORS proxy
  devserver.start();

  // Start selenium
  var started = false;
  var args = [
    '-jar',
    path.resolve(__dirname, SELENIUM_PATH),
  ];

  var selenium = spawn('java', args, {});
  selenium.stdout.on('data', function (data) {
    if (!started &&
        /Started org.openqa.jetty.jetty.servlet.ServletHandler/.test(data)) {
      started = true;
      callback();
    }
  });
}

function testError(e) {
  console.error(e);
  console.error('Doh, tests failed');
  client.quit().then(function () {
    process.exit(3);
  });
}

function testComplete(result) {

  var total = result.passed + result.failed;

  if (result.failed) {
    console.log('failed ' + result.failed + ' of ' + total + ' tests');
    console.log(JSON.stringify(result.failures, false, 4));
  } else {
    console.log('passed ' + result.passed + ' of ' + total + ' tests');
  }

  client.quit().then(function () {
    process.exit(result.failed ? 1 : 0);<commit_msg>(#1437) - Poll for selenium status being ready<commit_after>#!/usr/bin/env node
"use strict";

var path = require('path');
var spawn = require('child_process').spawn;

var request = require('request');
var wd = require('wd');
var devserver = require('./dev-server.js');

var SELENIUM_PATH = '../vendor/selenium-server-standalone-2.38.0.jar';
var testUrl = 'http://127.0.0.1:8000/tests/test.html';
var testTimeout = 30 * 60 * 1000;

var client;

if (process.env.GREP) {
  testUrl += '?grep=' + process.env.GREP;
}

if (process.env.TRAVIS) {
  process.exit(0);
}

function startServers(callback) {

  // Starts the file and CORS proxy
  devserver.start();

  // Start selenium
  spawn('java', ['-jar', path.resolve(__dirname, SELENIUM_PATH)], {});

  var retries = 0;
  var started = function () {

    if (++retries > 30) {
      console.error('Unable to connect to selenium');
      process.exit(1);
      return;
    }

    request('http://localhost:4444/wd/hub/status', function (err, resp) {
      if (resp && resp.statusCode === 200) {
        callback();
      } else {
        setTimeout(started, 1000);
      }
    });
  };

  started();
}

function testError(e) {
  console.error(e);
  console.error('Doh, tests failed');
  client.quit().then(function () {
    process.exit(3);
  });
}

function testComplete(result) {

  var total = result.passed + result.failed;

  if (result.failed) {
    console.log('failed ' + result.failed + ' of ' + total + ' tests');
    console.log(JSON.stringify(result.failures, false, 4));
  } else {
    console.log('passed ' + result.passed + ' of ' + total + ' tests');
  }

  client.quit().then(function () {
    process.exit(result.failed ? 1 : 0);
{'fraction_non_alphanumeric': 0.1807909604519774, 'fraction_numerical': 0.022912743251726302, 'mean_word_length': 3.238031914893617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7087098', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1094, 'n_words': 227}