<commit_before>'use strict';

const utils = require('../utils');
const projectConfig = require('../../config/project');
const globs = require('../globs');
const inTeamCity = require('../utils').inTeamCity;
const path = require('path');

module.exports = (gulp, plugins, {watch}) => {
  gulp.task('mocha', watch ? ['mocha:watch'] : ['_mocha']);

  gulp.task('mocha:watch', ['_mocha'], () => {
    gulp.watch(`${globs.base()}/**/*`, ['_mocha']);
  });

  gulp.task('_mocha', () => {
    plugins.util.log('Testing with Mocha');

    const mochaGlobs = projectConfig.specs.node() || globs.specs();
    const fileExt = utils.isTypescriptProject() ? 'ts' : 'js';
    const mochSetupPath = path.resolve(path.join('test', `mocha-setup.${fileExt}`));

    return gulp.src(mochaGlobs, {read: false})
      .pipe(plugins.spawnMocha({
        env: {NODE_ENV: 'test', SRC_PATH: './src'},
        reporter: inTeamCity() ? 'mocha-teamcity-reporter' : 'progress',
        timeout: 30000,
        require: [
          utils.isTypescriptProject() ? 'ts-node/register' : 'babel-register',
          path.join(__dirname, '..', 'ignore-extensions'),
          ...utils.exists(mochSetupPath) ? [mochSetupPath] : []
        ]
      }))
      .on('error', handleErrors);

    function handleErrors(err) {
      // gulp-spawn-mocha does not emits error on AssertionError, but just display them
      // if there's an AssertionError, it emits an error at the end of the stream
      if (!watch) {
        throw err;
      }

      this.emit('end');
    }
  });
};
<commit_msg>do transpile tests if no tsconfig/babel configurations<commit_after>'use strict';

const {isTypescriptProject, isBabelProject, exists} = require('../utils');
const projectConfig = require('../../config/project');
const globs = require('../globs');
const inTeamCity = require('../utils').inTeamCity;
const path = require('path');

module.exports = (gulp, plugins, {watch}) => {
  gulp.task('mocha', watch ? ['mocha:watch'] : ['_mocha']);

  gulp.task('mocha:watch', ['_mocha'], () => {
    gulp.watch(`${globs.base()}/**/*`, ['_mocha']);
  });

  gulp.task('_mocha', () => {
    plugins.util.log('Testing with Mocha');

    const mochaGlobs = projectConfig.specs.node() || globs.specs();
    const fileExt = isTypescriptProject() ? 'ts' : 'js';
    const mochSetupPath = path.resolve(path.join('test', `mocha-setup.${fileExt}`));
    let transpiler = [];

    if (isTypescriptProject()) {
      transpiler.push('ts-node/register');
    } else if (isBabelProject()) {
      transpiler.push('babel-register');
    }

    return gulp.src(mochaGlobs, {read: false})
      .pipe(plugins.spawnMocha({
        env: {NODE_ENV: 'test', SRC_PATH: './src'},
        reporter: inTeamCity() ? 'mocha-teamcity-reporter' : 'progress',
        timeout: 30000,
        require: [
          ...transpiler,
          path.join(__dirname, '..', 'ignore-extensions'),
          ...exists(mochSetupPath) ? [mochSetupPath] : []
        ]
      }))
      .on('error', handleErrors);

    function handleErrors(err) {
      // gulp-spawn-mocha does not emits error on AssertionError, but just display them
      // if there's an AssertionError, it emits an error at the end of the stream
      if (!watch) {
        throw err;
      }

      this.emit('end');
    }
  });
};

{'fraction_non_alphanumeric': 0.18945134889360413, 'fraction_numerical': 0.003031221582297666, 'mean_word_length': 3.024390243902439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6494677', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1071, 'n_words': 223}