Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4551fd8

Browse files
committed
Added fix for node 0.11.x tests
1 parent5560d14 commit4551fd8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

‎lib/getImportGlobalsSrc.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ function getImportGlobalsSrc(ignore) {
1414
globalObj=typeofglobal==="undefined"?window:global;
1515

1616
ignore=ignore||[];
17+
// global itself can't be overridden because it's the only reference to our real global objects
18+
ignore.push("global");
1719

18-
for(keyinglobalObj){
19-
if(key!=="global"&&ignore.indexOf(key)===-1){// we don't use hasOwnProperty here because in some browsers not all global objects will be enumerated
20-
value=globalObj[key];
21-
src+="var "+key+" = global."+key+"; ";
20+
for(keyinglobalObj){/* jshint forin: false */
21+
if(ignore.indexOf(key)!==-1){
22+
continue;
2223
}
24+
value=globalObj[key];
25+
src+="var "+key+" = global."+key+"; ";
2326
}
2427

25-
2628
returnsrc;
2729
}
2830

‎test/getImportGlobalsSrc.test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ describe("getImportGlobalsSrc", function () {
1313

1414
src=getImportGlobalsSrc();
1515
vm.runInNewContext(src,context);
16-
actualGlobals=Object.keys(context);
16+
actualGlobals=Object.keys(context).filter(function(key){
17+
// node v0.10 does not set a constructor property on the context
18+
// node v0.11 does set a constructor property
19+
// so just lets filter it, because it doesn't make sense to mock it anyway
20+
returnkey!=="constructor";
21+
});
1722
actualGlobals.sort();
1823
expectedGlobals.sort();
1924
expect(actualGlobals).to.eql(expectedGlobals);
@@ -28,12 +33,18 @@ describe("getImportGlobalsSrc", function () {
2833
actualGlobals,
2934
expectedGlobals=Object.keys(global);
3035

31-
src=getImportGlobalsSrc(ignore);
36+
// getImportGlobalsSrc modifies the ignore array, so let's create a copy
37+
src=getImportGlobalsSrc(ignore.slice(0));
3238
expectedGlobals=expectedGlobals.filter(functionfilterIgnoredVars(value){
3339
returnignore.indexOf(value)===-1;
3440
});
3541
vm.runInNewContext(src,context);
36-
actualGlobals=Object.keys(context);
42+
actualGlobals=Object.keys(context).filter(function(key){
43+
// node v0.10 does not set a constructor property on the context
44+
// node v0.11 does set a constructor property
45+
// so just lets filter it, because it doesn't make sense to mock it anyway
46+
returnkey!=="constructor";
47+
});
3748
actualGlobals.sort();
3849
expectedGlobals.sort();
3950
expect(actualGlobals).to.eql(expectedGlobals);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp