<commit_before>'use strict';

/**
 * Creates the list of test suites for end to end tests.
 *
 * @example
 *
 *     // Usage (from projet's root directory)
 *     node -r ./processRequire.js ./tests/client/e2eTests/scripts/createTestSuites.js
 */

var fs = require('fs');
var util = require('util');
var path = require('path');
var openVeoAPI = require('@openveo/api');
var pluginLoader = process.require('app/server/loaders/pluginLoader.js');
var suites = process.require('tests/client/protractorSuites.json');

// Path to the test suites files to load
var suiteFilePath = 'tests/client/protractorSuites.json';
var aggregatedSuiteFilePath = path.join(process.root, 'tests/client/e2eTests/suites/suites.json');

/**
 * Transforms all suites relatve path to absolute path.
 *
 * By default all suites are relative to protractorSuites.json.
 *
 * @param {Object} suites Suites description object
 * @param {String} basePath Base absolute path for these suites
 */
function setSuitesAbsolutePath(suites, basePath) {
  for (var suiteName in suites) {
    var suite = suites[suiteName];

    if (util.isArray(suite)) {
      for (var i = 0; i < suite.length; i++) {
        suite[i] = path.join(basePath, suite[i]);
      }
    } else
      suites[suiteName] = path.join(basePath, suite);
  }
}

setSuitesAbsolutePath(suites, path.join(process.root, 'tests/client'));

// Get plugins paths
pluginLoader.getPluginPaths(process.root, function(error, pluginPaths) {
  if (pluginPaths) {
    for (var i = 0; i < pluginPaths.length; i++) {
      var pluginPath = pluginPaths[i];

      try {
        var pluginSuites = require(path.join(pluginPath, suiteFilePath));
        setSuitesAbsolutePath(pluginSuites, path.join(pluginPath, 'tests/client'));
        openVeoAPI.util.merge(suites, pluginSuites);
      } catch (e) {
        process.stdout.write('Can\'t load file ' + path.join(pluginPath, suiteFilePath) + '\n');
      }
    }
    fs.writeFile(aggregatedSuiteFilePath, JSON.stringify(suites), {encoding: 'utf8'});
  }
});
<commit_msg>Automatically create directory for compiled end to end test suites file<commit_after>'use strict';

/**
 * Creates the list of test suites for end to end tests.
 *
 * @example
 *
 *     // Usage (from projet's root directory)
 *     node -r ./processRequire.js ./tests/client/e2eTests/scripts/createTestSuites.js
 */

var fs = require('fs');
var util = require('util');
var path = require('path');
var openVeoAPI = require('@openveo/api');
var pluginLoader = process.require('app/server/loaders/pluginLoader.js');
var suites = process.require('tests/client/protractorSuites.json');

// Path to the test suites files to load
var suiteFilePath = 'tests/client/protractorSuites.json';
var aggregatedSuiteFilePath = path.join(process.root, 'tests/client/e2eTests/suites/suites.json');

/**
 * Transforms all suites relatve path to absolute path.
 *
 * By default all suites are relative to protractorSuites.json.
 *
 * @param {Object} suites Suites description object
 * @param {String} basePath Base absolute path for these suites
 */
function setSuitesAbsolutePath(suites, basePath) {
  for (var suiteName in suites) {
    var suite = suites[suiteName];

    if (util.isArray(suite)) {
      for (var i = 0; i < suite.length; i++) {
        suite[i] = path.join(basePath, suite[i]);
      }
    } else
      suites[suiteName] = path.join(basePath, suite);
  }
}

setSuitesAbsolutePath(suites, path.join(process.root, 'tests/client'));

// Get plugins paths
pluginLoader.getPluginPaths(process.root, function(error, pluginPaths) {
  if (pluginPaths) {
    for (var i = 0; i < pluginPaths.length; i++) {
      var pluginPath = pluginPaths[i];

      try {
        var pluginSuites = require(path.join(pluginPath, suiteFilePath));
        setSuitesAbsolutePath(pluginSuites, path.join(pluginPath, 'tests/client'));
        openVeoAPI.util.merge(suites, pluginSuites);
      } catch (e) {
        process.stdout.write('Can\'t load file ' + path.join(pluginPath, suiteFilePath) + '\n');
      }
    }
    openVeoAPI.fileSystem.mkdir(path.dirname(aggregatedSuiteFilePath), function(error) {
      if (!error)
        fs.writeFile(aggregatedSuiteFilePath, JSON.stringify(suites), {encoding: 'utf8'});
    });
  }
});

{'fraction_non_alphanumeric': 0.13635291342297712, 'fraction_numerical': 0.0023590469450342063, 'mean_word_length': 3.774774774774775, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7385144', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1326, 'n_words': 328}