<commit_before>var _ = require('lodash');
var utils = module.exports;
var cp = require('child_process');
var path = require('path');
var fs = require('fs');

utils.run = function (cwd, options) {
  return new Promise(function (resolve, reject) {
    var child = cp.fork(__dirname + '/fork.js', [], {
      cwd: cwd
    });

    var result = {};

    child.on('error', function (err) {
      reject(err);
    });

    child.on('exit', function () {
      if (result.error) {
        reject(result.error);
      } else {
        resolve(result.value);
      }
    });

    child.on('message', function (value) {
      result = value;
      child.disconnect();
    });

    child.send(options);
  });
};

function checkout(p) {
  try {
    fs.statSync(p);
    cp.execSync('git checkout ' + p);
  } catch (e) {}
}

utils.reset = function (dir) {
  if (!dir) {
    throw new Error('utils.reset needs a path');
  }

  checkout(path.join(dir, 'package.json'));
  checkout(path.join(dir, 'bower.json'));
  checkout(path.join(dir, '.bowerrc'));
  checkout(path.join(dir, 'config.js'));
  checkout(path.join(dir, 'system_config.js'));
  checkout(path.join(dir, 'node_modules'));
  checkout(path.join(dir, 'bower_components'));
  checkout(path.join(dir, 'components'));
  checkout(path.join(dir, 'packages'));
  cp.execSync('git clean -fd ' + dir);
};

utils.write = function (filename, obj) {
  require('graceful-fs').writeFileSync(filename, JSON.stringify(obj, null, 2));
};<commit_msg>Add jspm_packages to be reset after test<commit_after>var _ = require('lodash');
var utils = module.exports;
var cp = require('child_process');
var path = require('path');
var fs = require('fs');

utils.run = function (cwd, options) {
  return new Promise(function (resolve, reject) {
    var child = cp.fork(__dirname + '/fork.js', [], {
      cwd: cwd
    });

    var result = {};

    child.on('error', function (err) {
      reject(err);
    });

    child.on('exit', function () {
      if (result.error) {
        reject(result.error);
      } else {
        resolve(result.value);
      }
    });

    child.on('message', function (value) {
      result = value;
      child.disconnect();
    });

    child.send(options);
  });
};

function checkout(p) {
  try {
    fs.statSync(p);
    cp.execSync('git checkout ' + p);
  } catch (e) {}
}

utils.reset = function (dir) {
  if (!dir) {
    throw new Error('utils.reset needs a path');
  }

  checkout(path.join(dir, 'package.json'));
  checkout(path.join(dir, 'bower.json'));
  checkout(path.join(dir, '.bowerrc'));
  checkout(path.join(dir, 'config.js'));
  checkout(path.join(dir, 'system_config.js'));
  checkout(path.join(dir, 'node_modules'));
  checkout(path.join(dir, 'bower_components'));
  checkout(path.join(dir, 'components'));
  checkout(path.join(dir, 'packages'));
  checkout(path.join(dir, 'jspm_packages'));
  cp.execSync('git clean -fd ' + dir);
};

utils.write = function (filename, obj) {
  require('graceful-fs').writeFileSync(filename, JSON.stringify(obj, null, 2));
};
{'fraction_non_alphanumeric': 0.19068076668869796, 'fraction_numerical': 0.0006609385327164573, 'mean_word_length': 3.425438596491228, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4282218', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1033, 'n_words': 206}