<commit_before># test.me.js

Simple nodejs module loader capable of mocking `require`d dependencies

[![Build Status](https://travis-ci.org/nyrkovalex/test.me.js.svg?branch=master)](https://travis-ci.org/nyrkovalex/test.me.js)

## Usage

As simple as that

`myModule.js` file:

```javascript
'use strict';

var fs = require('fs');

// Yes, you don't even need to export this in order to test
function readStuff(cb) {
  fs.readFile('someStuff', cb);
}
```

`myModule.spec.js` test file (let's assume we're using [mocha](http://mochajs.org/)
with [chai](http://chaijs.com/) assertions):

```javascript
'use strict';

var testMe = require('test.me');
var expect = require('chai').expect;

var mockFs = {
  readFile: function (path, cb) {
    cb(null, 'stuff');
  }
};

describe('test.me usage example', function () {
  // we load our module with out mock instead of required `fs`
  var myModule = testMe('./myModule', {
    fs: mockFs
  });

  it('should read some stuff', function (done) {
    // every top-level function defined in the file is accessible via loaded object
    myModule.readStuff(function (err, stuff) {
      // mocked fs always returns 'stuff' string
      expect(stuff).to.be.equal('stuff');
      done();
    });<commit_msg>Readme about globals<commit_after># test.me.js

Simple nodejs module loader capable of mocking `require`d dependencies

[![Build Status](https://travis-ci.org/nyrkovalex/test.me.js.svg?branch=master)](https://travis-ci.org/nyrkovalex/test.me.js)

## Usage

As simple as that

`myModule.js` file:

```javascript
'use strict';

var fs = require('fs');

// Yes, you don't even need to export this in order to test
function readStuff(cb) {
  fs.readFile(__dirname + '/someStuff', cb);
}
```

`myModule.spec.js` test file (let's assume we're using [mocha](http://mochajs.org/)
with [chai](http://chaijs.com/) assertions):

```javascript
'use strict';

var testMe = require('test.me');
var expect = require('chai').expect;

var mockFs = {
  readFile: function (path, cb) {
    cb(null, 'stuff');
  }
};

describe('test.me usage example', function () {
  // we load our module with out mock instead of required `fs`
  var myModule = testMe('./myModule', {
    fs: mockFs
  }, {
    __dirname: '/my/dir' // will be used as `__dirname` global by your script
  });

  it('should read some stuff', function (done) {
    // every top-level function defined in the file is accessible via loaded object
    myModule.readStuff(function (err, stuff) {
      // mocked fs always returns 'stuff' string
      expect(stuff).to.be.equal('stuff');
      done();
    });
{'fraction_non_alphanumeric': 0.15746815901196448, 'fraction_numerical': 0.0, 'mean_word_length': 3.764705882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5463644', 'n_tokens_mistral': 891, 'n_tokens_neox': 852, 'n_words': 252}