<commit_before>var q = require('q'),
    path = require('path'),
    glob = require('glob'),
    Cucumber = require('cucumber');

/**
 * Execute the Runner's test cases through Cucumber.
 *
 * @param {Runner} runner The current Protractor Runner.
 * @param {Array} specs Array of Directory Path Strings.
 * @return {q.Promise} Promise resolved with the test results
 */
exports.run = function(runner, specs) {
  var results = {}
  require('./lib/runState').initialize(runner, results);

  return runner.runTestPreparer().then(function() {
    return q.promise(function(resolve, reject) {
      var cliArguments = convertOptionsToCliArguments(runner.getConfig().cucumberOpts);
      cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js'));
      cliArguments = cliArguments.concat(specs);

      Cucumber.Cli(cliArguments).run(function (isSuccessful) {
        try {
          if (runner.getConfig().onComplete) {
            runner.getConfig().onComplete();
          }

          resolve(results);
        } catch (err) {
          reject(err);
        }
      });
    });
  });

  function convertOptionsToCliArguments(options) {
    var cliArguments = ['node', 'cucumberjs'];

    for (var option in options) {
      var cliArgumentValues = convertOptionValueToCliValues(option, options[option]);

      if (cliArgumentValues.length) {
        cliArgumentValues.forEach(function (value) {
          cliArguments.push('--' + option, value);
        });
      } else {
        cliArguments.push('--' + option);
      }
    }

    return cliArguments;
  }

  function convertRequireOptionValuesToCliValues(values) {
    var configDir = runner.getConfig().configDir;

    return values.map(function(path) {
      // Handle glob matching
      return glob.sync(path, {cwd: configDir});
    }).reduce(function(opts, globPaths) {
      // Combine paths into flattened array
      return opts.concat(globPaths);
    }, []).map(function(requirePath) {
      // Resolve require absolute path
      return path.resolve(configDir, requirePath)
    }).filter(function(item, pos, orig) {
      // Make sure requires are unique
      return orig.indexOf(item) == pos;
    });
  }

  function convertGenericOptionValuesToCliValues(values) {
    return values.reduce(function (opts, value) {
      if (value !== true) {
        opts.push(value);
      }

      return opts;
    }, []);
  }

  function convertOptionValueToCliValues(option, values) {
    if (!Array.isArray(values)) {
      values = [values];
    }

    if (option === 'require') {
      return convertRequireOptionValuesToCliValues(values);
    } else {
      return convertGenericOptionValuesToCliValues(values);
    }
  }
};<commit_msg>Filter options that are empty arrays, pass option name if value is boolean true<commit_after>var q = require('q'),
    path = require('path'),
    glob = require('glob'),
    Cucumber = require('cucumber');

/**
 * Execute the Runner's test cases through Cucumber.
 *
 * @param {Runner} runner The current Protractor Runner.
 * @param {Array} specs Array of Directory Path Strings.
 * @return {q.Promise} Promise resolved with the test results
 */
exports.run = function(runner, specs) {
  var results = {}
  require('./lib/runState').initialize(runner, results);

  return runner.runTestPreparer().then(function() {
    return q.promise(function(resolve, reject) {
      var cliArguments = convertOptionsToCliArguments(runner.getConfig().cucumberOpts);
      cliArguments.push('--require', path.resolve(__dirname, 'lib', 'resultsCapturer.js'));
      cliArguments = cliArguments.concat(specs);

      Cucumber.Cli(cliArguments).run(function (isSuccessful) {
        try {
          if (runner.getConfig().onComplete) {
            runner.getConfig().onComplete();
          }

          resolve(results);
        } catch (err) {
          reject(err);
        }
      });
    });
  });

  function convertOptionsToCliArguments(options) {
    var cliArguments = ['node', 'cucumberjs'];

    for (var option in options) {
      var cliArgumentValues = convertOptionValueToCliValues(option, options[option]);

      if (cliArgumentValues === true) {
        cliArguments.push('--' + option);
      } else if (cliArgumentValues.length) {
        cliArgumentValues.forEach(function (value) {
          cliArguments.push('--' + option, value);
        });
      }
    }

    return cliArguments;
  }

  function convertRequireOptionValuesToCliValues(values) {
    var configDir = runner.getConfig().configDir;

    return values.map(function(path) {
      // Handle glob matching
      return glob.sync(path, {cwd: configDir});
    }).reduce(function(opts, globPaths) {
      // Combine paths into flattened array
      return opts.concat(globPaths);
    }, []).map(function(requirePath) {
      // Resolve require absolute path
      return path.resolve(configDir, requirePath)
    }).filter(function(item, pos, orig) {
      // Make sure requires are unique
      return orig.indexOf(item) == pos;
    });
  }

  function convertGenericOptionValuesToCliValues(values) {
    if (values[0] === true) {
      return values[0]
    } else {
      return values;
    }
  }

  function convertOptionValueToCliValues(option, values) {
    if (!Array.isArray(values)) {
      values = [values];
    }

    if (option === 'require') {
      return convertRequireOptionValuesToCliValues(values);
    } else {
      return convertGenericOptionValuesToCliValues(values);
    }
  }
};
{'fraction_non_alphanumeric': 0.13049024968106435, 'fraction_numerical': 0.00036449790413705123, 'mean_word_length': 2.994177583697234, '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': '28315', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1542, 'n_words': 346}