<commit_before>var path = require('path'),
    _ = require('lodash'),
    through = require('through2'),
    KarmaServer = require('karma').Server;

module.exports = function testUnit(options) {
  var karmaFiles = [];

  options = _.defaultsDeep({}, options, {
    // Honestly, these are the only three options you should care about
    // Overwriting any of the other options will probably start fires
    reporters: ['progress'],
    browsers: ['PhantomJS'],
    captureTimeout: 20 * 1000,

    autoWatch: false,
    singleRun: true,
    frameworks: [
        'jasmine',
        'jasmine-matchers'
      ],
    plugins: [
        // We have to require() these because otherwise Karma will look in the wrong place
        require('karma-jasmine'),
        require('karma-jasmine-matchers'),
        require('karma-ng-html2js-preprocessor'),
        require('karma-phantomjs-launcher'),
        require('karma-chrome-launcher'),
        require('karma-firefox-launcher'),
        require('karma-safari-launcher')
      ],
    preprocessors: {
        '**/*.tmpl': 'ng-html2js'
      },
    ngHtml2JsPreprocessor: {
        moduleName: 'override.me',
        cacheIdFromPath: function (filePath) {
            return path.basename(filePath);
          }
      }
  });

  return through.obj(
    function transform(chunk, encoding, callback) {
        this.push(chunk);
        karmaFiles.push(chunk.path);
        callback();
      },
    function flush(done) {
        var karmaOptions = _.merge({}, options, {
          files: karmaFiles
        });

        // Use _.ary here so we don't pass any args to the callback
        new KarmaServer(karmaOptions, _.ary(done, 0)).start();
      }
  );
};<commit_msg>Fix test-unit.js to throw an error on test failure<commit_after>var path = require('path'),
    _ = require('lodash'),
    through = require('through2'),
    gutil = require('gulp-util'),
    KarmaServer = require('karma').Server;

module.exports = function testUnit(options) {
  var karmaFiles = [];

  options = _.defaultsDeep({}, options, {
    // Honestly, these are the only three options you should care about
    // Overwriting any of the other options will probably start fires
    reporters: ['progress'],
    browsers: ['PhantomJS'],
    captureTimeout: 20 * 1000,

    autoWatch: false,
    singleRun: true,
    frameworks: [
        'jasmine',
        'jasmine-matchers'
      ],
    plugins: [
        // We have to require() these because otherwise Karma will look in the wrong place
        require('karma-jasmine'),
        require('karma-jasmine-matchers'),
        require('karma-ng-html2js-preprocessor'),
        require('karma-phantomjs-launcher'),
        require('karma-chrome-launcher'),
        require('karma-firefox-launcher'),
        require('karma-safari-launcher')
      ],
    preprocessors: {
        '**/*.tmpl': 'ng-html2js'
      },
    ngHtml2JsPreprocessor: {
        moduleName: 'override.me',
        cacheIdFromPath: function (filePath) {
            return path.basename(filePath);
          }
      }
  });

  return through.obj(
    function transform(chunk, encoding, callback) {
        this.push(chunk);
        karmaFiles.push(chunk.path);
        callback();
      },
    function flush(done) {
        var th = this, // 'this' refers to the stream itself
            karmaOptions = _.merge({}, options, {
                files: karmaFiles
              });

        new KarmaServer(karmaOptions, function onFinish(exitCode) {
          if (exitCode !== 0) {
            th.emit('error', new gutil.PluginError('test-unit', {
              message: 'Unit tests failed.',
              showStack: false
            }));
          }

          done();
        }).start();
      }
  );
};
{'fraction_non_alphanumeric': 0.13224686080683942, 'fraction_numerical': 0.005877638258081752, 'mean_word_length': 2.281332164767748, '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': '466043', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1072, 'n_words': 254}