@@ -3,6 +3,7 @@ var expect = require("expect.js"),
3
3
getImportGlobalsSrc = require ( "../lib/getImportGlobalsSrc.js" ) ;
4
4
5
5
describe ( "getImportGlobalsSrc" , function ( ) {
6
+
6
7
it ( "should declare all globals with a var" , function ( ) {
7
8
var context = {
8
9
global : global
@@ -28,34 +29,43 @@ describe("getImportGlobalsSrc", function () {
28
29
delete global [ '__core-js_shared__' ] ;
29
30
delete global [ 'a-b' ] ;
30
31
31
- expectedGlobals = Object . keys ( global ) ;
32
+ const ignoredGlobals = [ "module" , "exports" , "require" , "undefined" , "eval" , "arguments" , "GLOBAL" , "root" , "NaN" , "Infinity" ] ;
33
+
34
+ const globals = Object . getOwnPropertyNames ( global ) ;
35
+ expectedGlobals = globals . filter ( ( el ) => ! ignoredGlobals . includes ( el ) ) ;
32
36
33
37
vm . runInNewContext ( src , context ) ;
34
- actualGlobals = Object . keys ( context ) ;
38
+ actualGlobals = Object . getOwnPropertyNames ( context ) ;
39
+
35
40
actualGlobals . sort ( ) ;
36
41
expectedGlobals . sort ( ) ;
37
42
expect ( actualGlobals ) . to . eql ( expectedGlobals ) ;
38
43
expect ( actualGlobals . length ) . to . be . above ( 1 ) ;
39
44
} ) ;
45
+
40
46
it ( "should ignore the given variables" , function ( ) {
41
47
var context = {
42
48
global : global
43
49
} ,
44
50
ignore = [ "console" , "setTimeout" ] ,
45
51
src ,
46
52
actualGlobals ,
47
- expectedGlobals = Object . keys ( global ) ;
53
+ expectedGlobals = Object . getOwnPropertyNames ( global ) ;
54
+
55
+ const ignoredGlobals = [ "module" , "exports" , "require" , "undefined" , "eval" , "arguments" , "GLOBAL" , "root" , "NaN" , "Infinity" ] ;
56
+ ignore = ignore . concat ( ignoredGlobals ) ;
48
57
49
58
// getImportGlobalsSrc modifies the ignore array, so let's create a copy
50
59
src = getImportGlobalsSrc ( ignore . slice ( 0 ) ) ;
51
- expectedGlobals = expectedGlobals . filter ( function filterIgnoredVars ( value ) {
52
- return ignore . indexOf ( value ) === - 1 ;
53
- } ) ;
60
+ expectedGlobals = expectedGlobals . filter ( ( el ) => ! ignore . includes ( el ) ) ;
61
+
54
62
vm . runInNewContext ( src , context ) ;
55
63
actualGlobals = Object . keys ( context ) ;
64
+
56
65
actualGlobals . sort ( ) ;
57
66
expectedGlobals . sort ( ) ;
58
67
expect ( actualGlobals ) . to . eql ( expectedGlobals ) ;
59
68
expect ( actualGlobals . length ) . to . be . above ( 1 ) ;
60
69
} ) ;
70
+
61
71
} ) ;
0 commit comments