<commit_before>/*jslint node: true, plusplus: true, stupid: true, nomen: true, indent: 4, maxlen: 80 */
/*global afterEach: false,
    beforeEach: false,
    describe: false,
    it: false,
    should: false */

"use strict";

var expect = require("expect.js"),
    fs = require('fs'),
	injectr = require("../lib/injectr");

describe("basic injectr", function () {
    beforeEach(function (done) {
        var fileContent,
            self = this;
        this.testFileDirectory = __dirname + '/test-scripts/';
        this.testFile = this.testFileDirectory + 'test-file.js';
        this.testRequire = 'test-require.js';
        this.injectr = require('../lib/injectr');
        fileContent = 'module.exports = {' +
            '    a : "result",' +
            '    b : function () {' +
            '        return require("fs");' +
            '    },' +
            '    c : function () {' +
            '        return require("./' + this.testRequire + '");' +
            '    }' +
            '};';
        fs.exists(this.testFileDirectory, function (exists) {
            var testFileDone = false,
                testRequireDone = false,
                write;
            write = function () {
                fs.writeFile(
                    self.testFile,
                    fileContent,
                    function () {
                        if (testRequireDone) {
                            return done();
                        }
                        testFileDone = true;
                    }
                );
                fs.writeFile(
                    self.testFileDirectory + self.testRequire,
                    'module.exports = 4;',
                    function () {
                        if (testFileDone) {
                            return done();
                        }
                        testRequireDone = true;
                    }
                );
            };
            if (!exists) {
                fs.mkdir(self.testFileDirectory, write);
            } else {
                write();
            }
        });
    });
    afterEach(function (done) {
        var self = this;
        fs.unlink(this.testFile, function () {
            fs.unlink(self.testFileDirectory + self.testRequire, function () {
                fs.rmdir(self.testFileDirectory, done);
            });
        });
    });
    it("should load and run scripts, and return the result", function () {
        var mod = this.injectr(this.testFile);
        expect(mod).to.have.property('a', 'result');
    });
    it("should run scripts replacing mocks with passed objects", function () {
        var mod,
            mockFs = {};
        mod = this.injectr(this.testFile, {
            fs : mockFs
        });
        expect(mod.b()).to.equal(mockFs);
    });
    it("should successfully resolve dirs to the mocking file", function () {
        var mod,
            mockFs = {};
        mod = this.injectr(this.testFile, {
        });
        expect(mod.c()).to.equal(4);
    });
});<commit_msg>added test for `require`s beginning with ../<commit_after>/*jslint node: true, plusplus: true, stupid: true, nomen: true, indent: 4, maxlen: 80 */
/*global afterEach: false,
    beforeEach: false,
    describe: false,
    it: false,
    should: false */

"use strict";

var expect = require("expect.js"),
    fs = require('fs'),
	injectr = require("../lib/injectr");

describe("basic injectr", function () {
    beforeEach(function (done) {
        var fileContent,
            self = this;
        this.testFileDirectory = __dirname + '/test-scripts/';
        this.testFile = this.testFileDirectory + 'test-file.js';
        this.testRequire = 'test-require.js';
        this.testRequire2 = '../test-require2.js';
        this.injectr = require('../lib/injectr');
        fileContent = 'module.exports = {' +
            '    a : "result",' +
            '    b : function () {' +
            '        return require("fs");' +
            '    },' +
            '    c : function () {' +
            '        return require("./' + this.testRequire + '");' +
            '    },' +
            '    d : function () {' +
            '        return require("' + this.testRequire2 + '");' +
            '    }' +
            '};';
        fs.exists(this.testFileDirectory, function (exists) {
            var testFilesToDo = 3,
                write;
            write = function () {
                var complete = function () {
                    if (!--testFilesToDo) {
                        done();
                    }
                };
                fs.writeFile(
                    self.testFile,
                    fileContent,
                    complete
                );
                fs.writeFile(
                    self.testFileDirectory + self.testRequire,
                    'module.exports = 4;',
                    complete
                );
                fs.writeFile(
                    self.testFileDirectory + self.testRequire2,
                    'module.exports = 5;',
                    complete
                );
            };
            if (!exists) {
                fs.mkdir(self.testFileDirectory, write);
            } else {
                write();
            }
        });
    });
    afterEach(function (done) {
        var self = this,
            testFilesToDo = 2,
            complete = function () {
                if (!--testFilesToDo) {
                    fs.rmdir(self.testFileDirectory, done);
                }
            };
        fs.unlink(this.testFile, complete);
        fs.unlink(self.testFileDirectory + self.testRequire, complete);
        fs.unlink(self.testFileDirectory + self.testRequire2, complete);
    });
    it("should load and run scripts, and return the result", function () {
        var mod = this.injectr(this.testFile);
        expect(mod).to.have.property('a', 'result');
    });
    it("should run scripts replacing mocks with passed objects", function () {
        var mod,
            mockFs = {};
        mod = this.injectr(this.testFile, {
            fs : mockFs
        });
        expect(mod.b()).to.equal(mockFs);
    });
    it("should successfully resolve dirs to the mocking file", function () {
        var mod,
            mockFs = {};
        mod = this.injectr(this.testFile, {
        });
        expect(mod.c()).to.equal(4);
    });
    it("should successfully resolve dirs to a ../ file", function () {
        var mod,
            mockFs = {};
        mod = this.injectr(this.testFile, {
        });
        expect(mod.d()).to.equal(5);
    });
});
{'fraction_non_alphanumeric': 0.1348689195332626, 'fraction_numerical': 0.0028792241248674043, 'mean_word_length': 1.3141654978962132, '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': '4781811', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1720, 'n_words': 360}