<commit_before>'use strict';

var captureExit = require('capture-exit');
captureExit.captureExit();

var glob = require('glob');
var Mocha = require('mocha');
var RSVP = require('rsvp');
var fs = require('fs-extra');
var mochaOnlyDetector = require('mocha-only-detector');

if (process.env.EOLNEWLINE) {
  require('os').EOL = '\n';
}

fs.removeSync('.deps-tmp');

var root = 'tests/{unit,integration,acceptance}';
var _checkOnlyInTests = RSVP.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test,-slow}.js'));
var optionOrFile = process.argv[2];
// default to `tap` reporter in CI otherwise default to `spec`
var reporter = process.env.MOCHA_REPORTER || (process.env.CI ? 'tap' : 'spec');
var mocha = new Mocha({
  timeout: 5000,
  reporter: reporter,
  // retries: 2
});
var testFiles = glob.sync(root + '/**/*-test.js');
var lintPosition = testFiles.indexOf('tests/unit/lint-test.js');
var lint = testFiles.splice(lintPosition, 1);
var docsLintPosition = testFiles.indexOf('tests/unit/docs-lint-test.js');
var docsLint = testFiles.splice(docsLintPosition, 1);

testFiles = lint.concat(docsLint).concat(testFiles);

if (optionOrFile === 'all') {
  addFiles(mocha, testFiles);
  addFiles(mocha, '/**/*-slow.js');
} else if (optionOrFile === 'slow')  {
  addFiles(mocha, '/**/*-slow.js');
} else if (optionOrFile === 'lint')  {
  addFiles(mocha, lint);
  addFiles(mocha, docsLint);
} else if (process.argv.length > 2)  {
  addFiles(mocha, process.argv.slice(2));
} else {
  addFiles(mocha, testFiles);
}

function addFiles(mocha, files) {
  files = (typeof files === 'string') ? glob.sync(root + files) : files;
  files.forEach(mocha.addFile.bind(mocha));
}

function checkOnlyInTests() {
  console.log('Verifing `.only` in tests');
  return _checkOnlyInTests().then(function() {
    console.log('No `.only` found');
  });
}

function runMocha() {
  console.time('Mocha Tests Running Time');
  mocha.run(function(failures) {
    console.timeEnd('Mocha Tests Running Time');
    process.exit(failures);
  });
}

function ciVerificationStep() {
  if (process.env.CI === 'true') {
    return checkOnlyInTests();
  } else {
    return RSVP.resolve();
  }
}

ciVerificationStep()
  .then(function() {
    runMocha();
  })
  .catch(function(error) {
    console.error(error);
    console.error(error.stack);
    process.exit(1);
  });
<commit_msg>Reset `retries`.<commit_after>'use strict';

var captureExit = require('capture-exit');
captureExit.captureExit();

var glob = require('glob');
var Mocha = require('mocha');
var RSVP = require('rsvp');
var fs = require('fs-extra');
var mochaOnlyDetector = require('mocha-only-detector');

if (process.env.EOLNEWLINE) {
  require('os').EOL = '\n';
}

fs.removeSync('.deps-tmp');

var root = 'tests/{unit,integration,acceptance}';
var _checkOnlyInTests = RSVP.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test,-slow}.js'));
var optionOrFile = process.argv[2];
// default to `tap` reporter in CI otherwise default to `spec`
var reporter = process.env.MOCHA_REPORTER || (process.env.CI ? 'tap' : 'spec');
var mocha = new Mocha({
  timeout: 5000,
  reporter: reporter,
  retries: 2
});
var testFiles = glob.sync(root + '/**/*-test.js');
var lintPosition = testFiles.indexOf('tests/unit/lint-test.js');
var lint = testFiles.splice(lintPosition, 1);
var docsLintPosition = testFiles.indexOf('tests/unit/docs-lint-test.js');
var docsLint = testFiles.splice(docsLintPosition, 1);

testFiles = lint.concat(docsLint).concat(testFiles);

if (optionOrFile === 'all') {
  addFiles(mocha, testFiles);
  addFiles(mocha, '/**/*-slow.js');
} else if (optionOrFile === 'slow')  {
  addFiles(mocha, '/**/*-slow.js');
} else if (optionOrFile === 'lint')  {
  addFiles(mocha, lint);
  addFiles(mocha, docsLint);
} else if (process.argv.length > 2)  {
  addFiles(mocha, process.argv.slice(2));
} else {
  addFiles(mocha, testFiles);
}

function addFiles(mocha, files) {
  files = (typeof files === 'string') ? glob.sync(root + files) : files;
  files.forEach(mocha.addFile.bind(mocha));
}

function checkOnlyInTests() {
  console.log('Verifing `.only` in tests');
  return _checkOnlyInTests().then(function() {
    console.log('No `.only` found');
  });
}

function runMocha() {
  console.time('Mocha Tests Running Time');
  mocha.run(function(failures) {
    console.timeEnd('Mocha Tests Running Time');
    process.exit(failures);
  });
}

function ciVerificationStep() {
  if (process.env.CI === 'true') {
    return checkOnlyInTests();
  } else {
    return RSVP.resolve();
  }
}

ciVerificationStep()
  .then(function() {
    runMocha();
  })
  .catch(function(error) {
    console.error(error);
    console.error(error.stack);
    process.exit(1);
  });

{'fraction_non_alphanumeric': 0.1851145038167939, 'fraction_numerical': 0.004664970313825276, 'mean_word_length': 4.628878281622912, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4637067', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1657, 'n_words': 329}