<commit_before>var path = require("path");
var fs = require("fs");
var assert = require("assert");

var makeModule = require("..");

var code = fs.readFileSync(joinHere("./example/calc.js")).toString();

function joinHere (where) {
  return path.join(__dirname, where);
}

describe("makeModule()", function () {
  it("example works as expected normally", function () {
    var calc = require("./example/calc");
    assert(typeof calc.add === "function");
    assert(typeof calc.subtract === "function");
  });

  it("creates modules from arbitrary code", function () {
    var code = "module.exports = {works: true};"
    var result = makeModule(code);
    assert(result.exports.works === true);
  });

  it("example is able to properly require dependencies given a good absolute path", function () {
    var result = makeModule(code, joinHere("./example/calc"));
    assert(typeof result.exports.add === "function");
    assert(typeof result.exports.subtract === "function");
  });

  it("joins path to process.cwd() if path not absolute", function () {
    var result = makeModule(code, "test/example/calc");
    assert(typeof result.exports.add === "function");
    assert(typeof result.exports.subtract === "function");
  });

  it("returns instances of the node core `Module` constructor", function () {
    var Module = require("module");
    var result = makeModule("");
    assert((result instanceof Module) === true);
  });

  it("has the expected properties", function () {
    var result = makeModule(code, "test/example/calc");
    assert(result.hasOwnProperty("exports"));
    assert(result.hasOwnProperty("id"));
    assert(result.hasOwnProperty("parent"));
    assert(result.hasOwnProperty("filename"));
    assert(result.hasOwnProperty("loaded"));
    assert(result.hasOwnProperty("children"));
    assert(result.hasOwnProperty("paths"));
  })

  it("throws as expected", function () {
    var badCode = "module.exports = {a: 1 b: 1};";
    var err1;
    try {
      makeModule(badCode);
    } catch (e) {
      err1 = e;
    }
    assert(/unexpected identifier/i.test(err1.message) === true);

    var badRequire = "require('./asdf')";
    var err2;
    try {
      makeModule(badRequire);
    } catch (e) {
      err2 = e;
    }
    assert(/cannot find module/i.test(err2.message) === true);
  });
});<commit_msg>more tests<commit_after>var path = require("path");
var fs = require("fs");
var assert = require("assert");

var makeModule = require("..");


function returnError (func) {
  try {
    func();
  } catch (err) {
    return err;
  }
}

function joinHere (where) {
  return path.join(__dirname, where);
}

describe("makeModule()", function () {
  var code = fs.readFileSync(joinHere("./example/calc.js")).toString();

  it("example works as expected normally", function () {
    var calc = require("./example/calc");
    assert(typeof calc.add === "function");
    assert(typeof calc.subtract === "function");
  });

  it("creates modules from arbitrary code", function () {
    var code = "module.exports = {works: true};"
    var result = makeModule(code);
    assert(result.exports.works === true);
  });

  it("example is able to properly require dependencies given a good absolute path", function () {
    var result = makeModule(code, joinHere("./example/calc"));
    assert(typeof result.exports.add === "function");
    assert(typeof result.exports.subtract === "function");
  });

  it("joins path to process.cwd() if path not absolute", function () {
    var result = makeModule(code, "test/example/calc");
    assert(typeof result.exports.add === "function");
    assert(typeof result.exports.subtract === "function");
  });

  it("returns instances of the node core `Module` constructor", function () {
    var Module = require("module");
    var result = makeModule("");
    assert((result instanceof Module) === true);
  });

  it("has the expected properties", function () {
    var result = makeModule(code, "test/example/calc");
    assert(result.hasOwnProperty("exports"));
    assert(result.hasOwnProperty("id"));
    assert(result.hasOwnProperty("parent"));
    assert(result.hasOwnProperty("filename"));
    assert(result.hasOwnProperty("loaded"));
    assert(result.hasOwnProperty("children"));
    assert(result.hasOwnProperty("paths"));
  });

  it("throws as expected", function () {
    var badCode = "module.exports = {a: 1 b: 1};";
    var err1 = returnError(function () { makeModule(badCode); });
    assert(/unexpected identifier/i.test(err1.message) === true);

    var badRequire = "require('./asdf')";
    var err2 = returnError(function () { makeModule(badRequire); });
    assert(/cannot find module/i.test(err2.message) === true);
  });
});
{'fraction_non_alphanumeric': 0.17410714285714285, 'fraction_numerical': 0.002976190476190476, 'mean_word_length': 3.957850368809273, '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': '6762647', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1346, 'n_words': 338}