Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb5b841

Browse files
committed
Use mocha to check for global leaks
1 parent b4af5ba commit fb5b841

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"mocha": "^2.1.0"
3434
},
3535
"scripts": {
36-
"test": "node node_modules/mocha/bin/mocha -R spec",
36+
"test": "mocha -R spec --check-leaks",
3737
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha"
3838
}
3939
}

test/rewire.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ describe("rewire", function () {
1616
fs.renameSync(fakeNodeModules, path.resolve(__dirname, "testModules/node_modules"));
1717
}
1818
});
19-
it("should keep not leak globals", function () {
20-
// This test should run first, as the global space may be already polluted if
21-
// require("../") is run before this test.
22-
var originalGlobalKeys = Object.keys(global),
23-
rewire = require("../"),
24-
emptyModule = rewire("./testModules/emptyModule.js");
25-
expect(Object.keys(global)).to.eql(originalGlobalKeys);
26-
});
2719
it("should pass all shared test cases", function () {
2820
require("./testModules/sharedTestCases.js");
2921
});

test/testModules/sharedTestCases.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
256256
// setting implicit global vars will change them globally instead of locally.
257257
// that's a shortcoming of the current implementation which can't be solved easily.
258258
//expect(implicitGlobal).to.be.a("string");
259+
260+
// Cleaning up...
261+
delete global.implicitGlobal;
259262
});
260263

261264
it("should throw a TypeError if the path is not a string", function () {

0 commit comments

Comments
 (0)