<commit_before>/**
 * Created by <NAME> on 11/14/14.
 */

'use strict';

var should = require('chai').should();

var butt = require('butt');

function noop () {}

describe('replacing Module.prototype.require()', function() {

  it('attaches and detaches as expected', function() {
    var requireHook = require("../");

    var Module = require("module");
    var oldRequire = Module.prototype.require;

    Module.prototype.require.should.equal(oldRequire);
    requireHook.attach();
    Module.prototype.require.should.not.equal(oldRequire);
    requireHook.detach();
    Module.prototype.require.should.equal(oldRequire);
  });

});



describe('intercepting require()', function () {
  var requireHook = require("..");

  beforeEach(butt(requireHook.attach, 0));
  afterEach(butt(requireHook.detach, 0));

  it('invokes the listener when `require()` is invoked', function () {
    var called = false;
    function listener () {
      called = true;
    }
    requireHook.setListener(listener);
    require("./calculator");
    called.should.equal(true);
  });

  it('passes the result and some info to the listener', function () {
    var calculator, result, info;
    function listener (r, i) {
      result = r;
      info = i;
    }
    requireHook.setListener(listener);
    calculator = require("./calculator");
    calculator.should.equal(result);
    info.should.eql({ 
      require: './calculator',
      callingFile: '/Users/nickbottomley/Documents/nb/require-hook/test/index.js',
      native: false,
      json: false,
      absPath: '/Users/nickbottomley/Documents/nb/require-hook/test/calculator.js',
      absPathResolvedCorrectly: true,
      testOnly: true,
      thirdParty: false,
      localToProject: true 
    });
  });

  it('allows the listener to pass back a value', function () {
    function listener () {
      return true;
    }
    requireHook.setListener(listener);
    var calculator = require("./calculator");
    calculator.should.equal(true);
  });

  it('passes an error in the result spot if one occurs', function () {
    function listener1 (err, info) {
      (err instanceof Error).should.equal(true);
      should.exist(info);
      /unexpected identifier/i.test(err.message).should.equal(true);
      return true;
    }

    function listener2 (err, info) {<commit_msg>remove system specific test for now<commit_after>/**
 * Created by <NAME> on 11/14/14.
 */

'use strict';

var should = require('chai').should();

var butt = require('butt');

function noop () {}

describe('replacing Module.prototype.require()', function() {

  it('attaches and detaches as expected', function() {
    var requireHook = require("../");

    var Module = require("module");
    var oldRequire = Module.prototype.require;

    Module.prototype.require.should.equal(oldRequire);
    requireHook.attach();
    Module.prototype.require.should.not.equal(oldRequire);
    requireHook.detach();
    Module.prototype.require.should.equal(oldRequire);
  });

});



describe('intercepting require()', function () {
  var requireHook = require("..");

  beforeEach(butt(requireHook.attach, 0));
  afterEach(butt(requireHook.detach, 0));

  it('invokes the listener when `require()` is invoked', function () {
    var called = false;
    function listener () {
      called = true;
    }
    requireHook.setListener(listener);
    require("./calculator");
    called.should.equal(true);
  });

  it('passes the result and some info to the listener', function () {
    var calculator, result, info;
    function listener (r, i) {
      result = r;
      info = i;
    }
    requireHook.setListener(listener);
    calculator = require("./calculator");
    calculator.should.equal(result);
  });

  it('allows the listener to pass back a value', function () {
    function listener () {
      return true;
    }
    requireHook.setListener(listener);
    var calculator = require("./calculator");
    calculator.should.equal(true);
  });

  it('passes an error in the result spot if one occurs', function () {
    function listener1 (err, info) {
      (err instanceof Error).should.equal(true);
      should.exist(info);
      /unexpected identifier/i.test(err.message).should.equal(true);
      return true;
    }

    function listener2 (err, info) {
{'fraction_non_alphanumeric': 0.14660421545667449, 'fraction_numerical': 0.00468384074941452, 'mean_word_length': 3.2967806841046277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7435348', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1237, 'n_words': 300}