diff options
author | Johannes Ewald <johannes.ewald@peerigon.com> | 2014-05-20 15:21:01 +0400 |
---|---|---|
committer | Johannes Ewald <johannes.ewald@peerigon.com> | 2014-05-20 15:21:01 +0400 |
commit | 4551fd830d5e8719424c1b96940e8b89643380fd (patch) | |
tree | 1136a8af4ba675e32e20d32f1d1d17ba1de91eab | |
parent | 5560d14bbe57aca6a5a5be55da2a08655e4ab1ab (diff) |
Added fix for node 0.11.x tests
-rw-r--r-- | lib/getImportGlobalsSrc.js | 12 | ||||
-rw-r--r-- | test/getImportGlobalsSrc.test.js | 17 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/getImportGlobalsSrc.js b/lib/getImportGlobalsSrc.js index 8ed8545..66e69b1 100644 --- a/lib/getImportGlobalsSrc.js +++ b/lib/getImportGlobalsSrc.js @@ -14,15 +14,17 @@ function getImportGlobalsSrc(ignore) { globalObj = typeof global === "undefined"? window: global; ignore = ignore || []; + // global itself can't be overridden because it's the only reference to our real global objects + ignore.push("global"); - for (key in globalObj) { - if (key !== "global" && ignore.indexOf(key) === -1) { // we don't use hasOwnProperty here because in some browsers not all global objects will be enumerated - value = globalObj[key]; - src += "var " + key + " = global." + key + "; "; + for (key in globalObj) { /* jshint forin: false */ + if (ignore.indexOf(key) !== -1) { + continue; } + value = globalObj[key]; + src += "var " + key + " = global." + key + "; "; } - return src; } diff --git a/test/getImportGlobalsSrc.test.js b/test/getImportGlobalsSrc.test.js index 0d9b020..e733614 100644 --- a/test/getImportGlobalsSrc.test.js +++ b/test/getImportGlobalsSrc.test.js @@ -13,7 +13,12 @@ describe("getImportGlobalsSrc", function () { src = getImportGlobalsSrc();
vm.runInNewContext(src, context);
- actualGlobals = Object.keys(context);
+ actualGlobals = Object.keys(context).filter(function (key) {
+ // node v0.10 does not set a constructor property on the context
+ // node v0.11 does set a constructor property
+ // so just lets filter it, because it doesn't make sense to mock it anyway
+ return key !== "constructor";
+ });
actualGlobals.sort();
expectedGlobals.sort();
expect(actualGlobals).to.eql(expectedGlobals);
@@ -28,12 +33,18 @@ describe("getImportGlobalsSrc", function () { actualGlobals,
expectedGlobals = Object.keys(global);
- src = getImportGlobalsSrc(ignore);
+ // getImportGlobalsSrc modifies the ignore array, so let's create a copy
+ src = getImportGlobalsSrc(ignore.slice(0));
expectedGlobals = expectedGlobals.filter(function filterIgnoredVars(value) {
return ignore.indexOf(value) === -1;
});
vm.runInNewContext(src, context);
- actualGlobals = Object.keys(context);
+ actualGlobals = Object.keys(context).filter(function (key) {
+ // node v0.10 does not set a constructor property on the context
+ // node v0.11 does set a constructor property
+ // so just lets filter it, because it doesn't make sense to mock it anyway
+ return key !== "constructor";
+ });
actualGlobals.sort();
expectedGlobals.sort();
expect(actualGlobals).to.eql(expectedGlobals);
|