<commit_before>/*
 * grunt-protractor-cucumber
 * https://github.com/karthiktv006/grunt-protractor-cucumber
 *
 * Copyright (c) 2016 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var _ = require('lodash'),
    argv = require('yargs').argv,
    path = require('path'),

    configFile,
    baseTestDir,
    seleniumAddress,
    configuration,
    outputDir,
    featuresDir,
    reportFormat;

module.exports = function(grunt) {

  // Grunt tasks
  grunt.registerTask('e2e', 'Run end to end test using protractor and cucumber framework.', e2e);
  grunt.registerTask('e2e-rerun', 'Rerun failed scenarios alone.', e2eRerun);
  grunt.registerTask('e2e-dry-run', 'dry-run:folder | Invokes formatters without executing the steps.', e2eDryRun);

  //////////////////// Task functions

  function e2e (suite, feature, tags, browser) {
    var rerunFlag = argv.rerun || argv.r,
        flags;

    setupConfig();

    suite = suite || '';
    feature = feature || '';
    tags = tags || '';
    browser = browser || '';

    flags = getFlagsForProtractor(suite, feature, tags, browser, {});

    var done = this.async();
    protractorRunner(flags, done);

    if (rerunFlag) {
      grunt.task.run('e2e-rerun:' + browser);
    }
  }

  function e2eRerun (browser) {
    if (!configFile) {
      setupConfig();
    }

    var rerunScenarios,
        mode = {
          rerun: true
        },
        rerunReportFile = path.resolve(outputDir, reportFormat.rerun || 'rerun.txt'),
        flags;

    rerunScenarios = grunt.file.read(rerunReportFile, 'utf8');

    if (rerunScenarios) {
      rerunScenarios = rerunScenarios.trim().split('\n');
      grunt.option('specs', rerunScenarios);
      flags = getFlagsForProtractor(null, null, null, browser, mode);
      this.async();
      protractorRunner(flags, stitchJsonFiles);
    }
  }

  function e2eDryRun (team, file) {
    var mode = {
          dryrun: true
        },
        flags;

    process.env['DRY_RUN'] = true;

    if (!configFile) {
      setupConfig();
    }

    file = file || '';
    flags = getFlagsForProtractor(team, file, null, null, mode);
    var done = this.async();
    protractorRunner(flags, done);
    // grunt.task.run('run:dry-run');
  }

  /////////////////// Private functions

  var protractorRunner = function (flags, done) {
    var ptr = grunt.util.spawn({
      cmd: 'node',
      args: flags
    }, function(error) {
      if (error) {
        grunt.file.write(path.resolve(outputDir, 'error.txt'), error);
      }
      done();
    });

    ptr.stdout.pipe(process.stdout);
    ptr.stderr.pipe(process.stderr);
  };

  var setupConfig = function () {
    // check if all are defined
    configFile = path.resolve(grunt.config.data.protractorCucumber.configFile),
    baseTestDir = path.resolve(grunt.config.data.protractorCucumber.baseTestDir),
    seleniumAddress = grunt.config.data.protractorCucumber.seleniumAddress,
    configuration = require(configFile);
    outputDir = configuration.config.report.output || path.resolve('test', 'output'),
    featuresDir = path.resolve(baseTestDir,  'features');
    reportFormat = configuration.config.report.format;
  };

  var getFlagsForProtractor = function (suite, feature, tags, browser, mode) {

    if (!grunt.file.exists(outputDir)) {
      grunt.file.mkdir(outputDir);
    }

    if (suite) {
      grunt.option('specs', path.resolve(featuresDir, suite, '**/*.feature'));
    }
    if (feature) {
      grunt.option('specs', path.resolve(featuresDir, suite, '**/*', feature));
    }
    if (tags) {
      tags = tags.split('&&');
    }

    if (argv.browserName) {<commit_msg>fix feature under a folder<commit_after>/*
 * grunt-protractor-cucumber
 * https://github.com/karthiktv006/grunt-protractor-cucumber
 *
 * Copyright (c) 2016 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var _ = require('lodash'),
    argv = require('yargs').argv,
    path = require('path'),

    configFile,
    baseTestDir,
    seleniumAddress,
    configuration,
    outputDir,
    featuresDir,
    reportFormat;

module.exports = function(grunt) {

  // Grunt tasks
  grunt.registerTask('e2e', 'Run end to end test using protractor and cucumber framework.', e2e);
  grunt.registerTask('e2e-rerun', 'Rerun failed scenarios alone.', e2eRerun);
  grunt.registerTask('e2e-dry-run', 'dry-run:folder | Invokes formatters without executing the steps.', e2eDryRun);

  //////////////////// Task functions

  function e2e (suite, feature, tags, browser) {
    var rerunFlag = argv.rerun || argv.r,
        flags;

    setupConfig();

    suite = suite || '';
    feature = feature || '';
    tags = tags || '';
    browser = browser || '';

    flags = getFlagsForProtractor(suite, feature, tags, browser, {});

    var done = this.async();
    protractorRunner(flags, done);

    if (rerunFlag) {
      grunt.task.run('e2e-rerun:' + browser);
    }
  }

  function e2eRerun (browser) {
    if (!configFile) {
      setupConfig();
    }

    var rerunScenarios,
        mode = {
          rerun: true
        },
        rerunReportFile = path.resolve(outputDir, reportFormat.rerun || 'rerun.txt'),
        flags;

    rerunScenarios = grunt.file.read(rerunReportFile, 'utf8');

    if (rerunScenarios) {
      rerunScenarios = rerunScenarios.trim().split('\n');
      grunt.option('specs', rerunScenarios);
      flags = getFlagsForProtractor(null, null, null, browser, mode);
      this.async();
      protractorRunner(flags, stitchJsonFiles);
    }
  }

  function e2eDryRun (team, file) {
    var mode = {
          dryrun: true
        },
        flags;

    process.env['DRY_RUN'] = true;

    if (!configFile) {
      setupConfig();
    }

    file = file || '';
    flags = getFlagsForProtractor(team, file, null, null, mode);
    var done = this.async();
    protractorRunner(flags, done);
    // grunt.task.run('run:dry-run');
  }

  /////////////////// Private functions

  var protractorRunner = function (flags, done) {
    var ptr = grunt.util.spawn({
      cmd: 'node',
      args: flags
    }, function(error) {
      if (error) {
        grunt.file.write(path.resolve(outputDir, 'error.txt'), error);
      }
      done();
    });

    ptr.stdout.pipe(process.stdout);
    ptr.stderr.pipe(process.stderr);
  };

  var setupConfig = function () {
    // check if all are defined
    configFile = path.resolve(grunt.config.data.protractorCucumber.configFile),
    baseTestDir = path.resolve(grunt.config.data.protractorCucumber.baseTestDir),
    seleniumAddress = grunt.config.data.protractorCucumber.seleniumAddress,
    configuration = require(configFile);
    outputDir = configuration.config.report.output || path.resolve('test', 'output'),
    featuresDir = path.resolve(baseTestDir,  'features');
    reportFormat = configuration.config.report.format;
  };

  var getFlagsForProtractor = function (suite, feature, tags, browser, mode) {

    if (!grunt.file.exists(outputDir)) {
      grunt.file.mkdir(outputDir);
    }

    if (suite) {
      grunt.option('specs', path.resolve(featuresDir, suite, '**/*.feature'));
    }
    if (feature) {
      grunt.option('specs', path.resolve(featuresDir, suite, feature));
    }
    if (tags) {
      tags = tags.split('&&');
    }

    if (argv.browserName) {
{'fraction_non_alphanumeric': 0.15300922737914888, 'fraction_numerical': 0.00495799476656108, 'mean_word_length': 2.8040859088528025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '3369652', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2308, 'n_words': 470}