diff --git a/lib/rewire.js b/lib/rewire.js index e0b56f1..167d7b3 100644 --- a/lib/rewire.js +++ b/lib/rewire.js @@ -19,7 +19,8 @@ var srcs = { function internalRewire(parentModulePath, targetPath) { var targetModule, prelude, - appendix; + appendix, + src; // Checking params if (typeof targetPath !== "string") { diff --git a/test/rewire.test.js b/test/rewire.test.js index 1ac0129..0524a36 100644 --- a/test/rewire.test.js +++ b/test/rewire.test.js @@ -16,6 +16,14 @@ describe("rewire", function () { fs.renameSync(fakeNodeModules, path.resolve(__dirname, "testModules/node_modules")); } }); + it("should keep not leak globals", function () { + // This test should run first, as the global space may be already polluted if + // require("../") is run before this test. + var originalGlobalKeys = Object.keys(global), + rewire = require("../"), + emptyModule = rewire("./testModules/emptyModule.js"); + expect(Object.keys(global)).to.eql(originalGlobalKeys); + }); it("should pass all shared test cases", function () { require("./testModules/sharedTestCases.js"); });