<commit_before>/*jshint -W030, mocha:true */
'use strict';

var path = require('path');
var fs = require('fs-extra');
var async = require('async');
var childProcess = require('child_process');
var should = require('chai').should();
var _ = require('lodash');


var GRUNT_EXEC = 'node ' + path.resolve('node_modules/grunt-cli/bin/grunt');



/**
 * Executes a Scenario given by tests.
 *
 * A Scenario can contain:
 *    repo - the folder to contain the repository
 *    repo/gruntfile.js - the gruntfile to be tested
 *    remote - (optional) can contain a setup cloud repository
 *    validate - (will be overwritten) it is cloned from remote (used to validate a push)
 *
 **
 * NOTE: this function DOES change the process's working directory to the `scenario` so that
 * validations are easier access.
 */
var execScenario = function(cb) {
  var mockRepoDir = path.normalize(__dirname + '/mock');

  var distDir = path.join(mockRepoDir, 'repo');
  var remoteDir = path.join(mockRepoDir, 'remote');
  var verifyDir = path.join(mockRepoDir, 'validate');


  var tasks = [];


  tasks.push(function createRemote(next) {
    fs.ensureDirSync(remoteDir);
    childProcess.exec('git init --bare', {cwd: remoteDir}, function(err) {
      if (err) throw new Error(err);
      next(err);
    });
  });


  tasks.push(function executeGruntCommand(next) {
    //options
    GRUNT_EXEC += ' --no-color';

    childProcess.exec(GRUNT_EXEC, {cwd: distDir}, function(err, stdout, stderr) {
      next(err, {stdout: stdout, stderr: stderr});
    });
  });


  tasks.push(function createVerifyFromRemote(next) {
    fs.removeSync(verifyDir); // since we're cloning from `remote/` we'll just remove the folder if it exists
    childProcess.exec('git clone remote validate', {cwd: mockRepoDir}, function(err) {
      if (err) throw new Error(err);
      next(err);
    });
  });


  async.series(tasks, function returnCallbackStatus(err, results) {
    // return results from executeGruntCommand
    cb(err, results[1].stdout, results[1].stderr);
  });
};



/**
 * Tests
 *
 * Each test is using the perspective as a "user", take a look at the "basic deploy" suite.
 *
 * `describe` suite's title should have the same name as the scenario folder.
 *
 * Assumptions:
 *    - each tests' current working directory has been set to `test/mock`
 */
describe('buildcontrol', function() {
  this.timeout(10000);


  beforeEach(function(done) {
    var scenarioPath = this.currentTest.parent.title;

    // ensure that we reset to `test/` dir
    process.chdir(__dirname);

    // clean testing folder `test/mock`
    fs.removeSync('mock');
    fs.ensureDirSync('mock');

    try {
    // copy scenario to `test/mock`
      fs.copySync('scenarios/' + scenarioPath, 'mock');

      // ensure all tests are are using the working directory: `test/mock`
    process.chdir('mock');<commit_msg>(tests) increased timeout<commit_after>/*jshint -W030, mocha:true */
'use strict';

var path = require('path');
var fs = require('fs-extra');
var async = require('async');
var childProcess = require('child_process');
var should = require('chai').should();
var _ = require('lodash');


var GRUNT_EXEC = 'node ' + path.resolve('node_modules/grunt-cli/bin/grunt');



/**
 * Executes a Scenario given by tests.
 *
 * A Scenario can contain:
 *    repo - the folder to contain the repository
 *    repo/gruntfile.js - the gruntfile to be tested
 *    remote - (optional) can contain a setup cloud repository
 *    validate - (will be overwritten) it is cloned from remote (used to validate a push)
 *
 **
 * NOTE: this function DOES change the process's working directory to the `scenario` so that
 * validations are easier access.
 */
var execScenario = function(cb) {
  var mockRepoDir = path.normalize(__dirname + '/mock');

  var distDir = path.join(mockRepoDir, 'repo');
  var remoteDir = path.join(mockRepoDir, 'remote');
  var verifyDir = path.join(mockRepoDir, 'validate');


  var tasks = [];


  tasks.push(function createRemote(next) {
    fs.ensureDirSync(remoteDir);
    childProcess.exec('git init --bare', {cwd: remoteDir}, function(err) {
      if (err) throw new Error(err);
      next(err);
    });
  });


  tasks.push(function executeGruntCommand(next) {
    //options
    GRUNT_EXEC += ' --no-color';

    childProcess.exec(GRUNT_EXEC, {cwd: distDir}, function(err, stdout, stderr) {
      next(err, {stdout: stdout, stderr: stderr});
    });
  });


  tasks.push(function createVerifyFromRemote(next) {
    fs.removeSync(verifyDir); // since we're cloning from `remote/` we'll just remove the folder if it exists
    childProcess.exec('git clone remote validate', {cwd: mockRepoDir}, function(err) {
      if (err) throw new Error(err);
      next(err);
    });
  });


  async.series(tasks, function returnCallbackStatus(err, results) {
    // return results from executeGruntCommand
    cb(err, results[1].stdout, results[1].stderr);
  });
};



/**
 * Tests
 *
 * Each test is using the perspective as a "user", take a look at the "basic deploy" suite.
 *
 * `describe` suite's title should have the same name as the scenario folder.
 *
 * Assumptions:
 *    - each tests' current working directory has been set to `test/mock`
 */
describe('buildcontrol', function() {
  this.timeout(20000);


  beforeEach(function(done) {
    var scenarioPath = this.currentTest.parent.title;

    // ensure that we reset to `test/` dir
    process.chdir(__dirname);

    // clean testing folder `test/mock`
    fs.removeSync('mock');
    fs.ensureDirSync('mock');

    try {
    // copy scenario to `test/mock`
      fs.copySync('scenarios/' + scenarioPath, 'mock');

      // ensure all tests are are using the working directory: `test/mock`
    process.chdir('mock');
{'fraction_non_alphanumeric': 0.13763066202090593, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 3.5311760063141278, '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': '4574244', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1746, 'n_words': 525}