Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix leak, add test, for #33 #34

Merged
merged 4 commits into from
Oct 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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