Skip to content

Commit

Permalink
Merge pull request #34 from Trott/fix-leak
Browse files Browse the repository at this point in the history
Fix leak, add test, for #33
  • Loading branch information
jhnns committed Oct 29, 2014
2 parents 93d3907 + 7e25ede commit 6040c0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var srcs = {
function internalRewire(parentModulePath, targetPath) {
var targetModule,
prelude,
appendix;
appendix,
src;

// Checking params
if (typeof targetPath !== "string") {
Expand Down
8 changes: 8 additions & 0 deletions test/rewire.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down

0 comments on commit 6040c0c

Please sign in to comment.