<commit_before>require('mocha-as-promised')();

var extend = require('util')._extend;
var path = require('path');
var debug = require('debug')('registry-validator');
var fs = require('fs-extra');
var config = require('./lib/config');
var Promise = require('bluebird');

/**
 * @param {Promise} registryUrlPromise A promise that is resolved with
 * the URL of the registry to validate.
 * @param {{userCredentials,userEmail}} options Options.
 * `userCredentials` is `login:password` or null
 */
module.exports = function validate(registryUrlPromise, options) {
  before(function() {
    return registryUrlPromise
      .bind(this)
      .then(function(url) {
        extend(config, options);
        config.registryUrl = url;
        debug('config: %j', config);
      });
  });

  beforeEach(function() {
    fs.removeSync(config.sandbox);
    fs.mkdirsSync(config.sandbox);
  });

  describe('end-to-end', function() {
    requireDir('./lib/end-to-end');
  });
};

function requireDir(dir) {
  dir = path.resolve(dir);
  fs.readdirSync(dir).forEach(function(name) {
    if (!/\.js$/.test(name)) return;
    require(path.join(dir, name));
  });
}

// Enable long stack traces to simplify trouble shooting
Promise.longStackTraces();

// `npm` reports failures as strings (not errors)
// Bluebird does not reject the promise in such case
Promise.onPossiblyUnhandledRejection(function(e, promise){
  throw e;
});<commit_msg>Fix requireDir to resolve relative to this module<commit_after>require('mocha-as-promised')();

var extend = require('util')._extend;
var path = require('path');
var debug = require('debug')('registry-validator');
var fs = require('fs-extra');
var config = require('./lib/config');
var Promise = require('bluebird');

/**
 * @param {Promise} registryUrlPromise A promise that is resolved with
 * the URL of the registry to validate.
 * @param {{userCredentials,userEmail}} options Options.
 * `userCredentials` is `<PASSWORD>:password` or null
 */
module.exports = function validate(registryUrlPromise, options) {
  before(function() {
    return registryUrlPromise
      .bind(this)
      .then(function(url) {
        extend(config, options);
        config.registryUrl = url;
        debug('config: %j', config);
      });
  });

  beforeEach(function() {
    fs.removeSync(config.sandbox);
    fs.mkdirsSync(config.sandbox);
  });

  describe('end-to-end', function() {
    requireDir('./lib/end-to-end');
  });
};

function requireDir(dir) {
  dir = path.resolve(__dirname, dir);
  fs.readdirSync(dir).forEach(function(name) {
    if (!/\.js$/.test(name)) return;
    require(path.join(dir, name));
  });
}

// Enable long stack traces to simplify trouble shooting
Promise.longStackTraces();

// `npm` reports failures as strings (not errors)
// Bluebird does not reject the promise in such case
Promise.onPossiblyUnhandledRejection(function(e, promise){
  throw e;
});
{'fraction_non_alphanumeric': 0.15711325966850828, 'fraction_numerical': 0.0, 'mean_word_length': 4.109347442680776, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '3324920', 'n_tokens_mistral': 879, 'n_tokens_neox': 866, 'n_words': 218}