From d3cbd02b3d9de6cbfb518c31f9c70472508912c3 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 14:11:16 +0200 Subject: Change line endings from carriage returns to line feeds --- test/getImportGlobalsSrc.test.js | 122 +++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 61 deletions(-) (limited to 'test') diff --git a/test/getImportGlobalsSrc.test.js b/test/getImportGlobalsSrc.test.js index 0c40e5a..b85736c 100644 --- a/test/getImportGlobalsSrc.test.js +++ b/test/getImportGlobalsSrc.test.js @@ -1,61 +1,61 @@ -var expect = require("expect.js"), - vm = require("vm"), - getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js"); - -describe("getImportGlobalsSrc", function () { - it("should declare all globals with a var", function () { - var context = { - global: global - }, - expectedGlobals, - src, - actualGlobals; - - // Temporarily set module-internal variables on the global scope to check if getImportGlobalsSrc() - // ignores them properly - global.module = module; - global.exports = exports; - global.require = require; - - // Also make sure it ignores invalid variable names - global['a-b'] = true; - - src = getImportGlobalsSrc(); - - delete global.module; - delete global.exports; - delete global.require; - delete global['__core-js_shared__']; - delete global['a-b']; - - expectedGlobals = Object.keys(global); - - vm.runInNewContext(src, context); - actualGlobals = Object.keys(context); - actualGlobals.sort(); - expectedGlobals.sort(); - expect(actualGlobals).to.eql(expectedGlobals); - expect(actualGlobals.length).to.be.above(1); - }); - it("should ignore the given variables", function () { - var context = { - global: global - }, - ignore = ["console", "setTimeout"], - src, - actualGlobals, - expectedGlobals = Object.keys(global); - - // 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.sort(); - expectedGlobals.sort(); - expect(actualGlobals).to.eql(expectedGlobals); - expect(actualGlobals.length).to.be.above(1); - }); -}); +var expect = require("expect.js"), + vm = require("vm"), + getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js"); + +describe("getImportGlobalsSrc", function () { + it("should declare all globals with a var", function () { + var context = { + global: global + }, + expectedGlobals, + src, + actualGlobals; + + // Temporarily set module-internal variables on the global scope to check if getImportGlobalsSrc() + // ignores them properly + global.module = module; + global.exports = exports; + global.require = require; + + // Also make sure it ignores invalid variable names + global['a-b'] = true; + + src = getImportGlobalsSrc(); + + delete global.module; + delete global.exports; + delete global.require; + delete global['__core-js_shared__']; + delete global['a-b']; + + expectedGlobals = Object.keys(global); + + vm.runInNewContext(src, context); + actualGlobals = Object.keys(context); + actualGlobals.sort(); + expectedGlobals.sort(); + expect(actualGlobals).to.eql(expectedGlobals); + expect(actualGlobals.length).to.be.above(1); + }); + it("should ignore the given variables", function () { + var context = { + global: global + }, + ignore = ["console", "setTimeout"], + src, + actualGlobals, + expectedGlobals = Object.keys(global); + + // 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.sort(); + expectedGlobals.sort(); + expect(actualGlobals).to.eql(expectedGlobals); + expect(actualGlobals.length).to.be.above(1); + }); +}); -- cgit v1.2.3 From 7bec7f88e01bad4829ee2ac3f90fe5d9d2616888 Mon Sep 17 00:00:00 2001 From: Rens Baardman Date: Tue, 11 Jun 2019 13:41:59 +0200 Subject: Fix #167: non-enumerable globals are now also prefixed with `var` --- test/getImportGlobalsSrc.test.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/getImportGlobalsSrc.test.js b/test/getImportGlobalsSrc.test.js index 0c40e5a..51cecbd 100644 --- a/test/getImportGlobalsSrc.test.js +++ b/test/getImportGlobalsSrc.test.js @@ -3,6 +3,7 @@ var expect = require("expect.js"), getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js"); describe("getImportGlobalsSrc", function () { + it("should declare all globals with a var", function () { var context = { global: global @@ -28,15 +29,20 @@ describe("getImportGlobalsSrc", function () { delete global['__core-js_shared__']; delete global['a-b']; - expectedGlobals = Object.keys(global); + const ignoredGlobals = ["module", "exports", "require", "undefined", "eval", "arguments", "GLOBAL", "root", "NaN", "Infinity"]; + + const globals = Object.getOwnPropertyNames(global); + expectedGlobals = globals.filter((el) => !ignoredGlobals.includes(el)); vm.runInNewContext(src, context); - actualGlobals = Object.keys(context); + actualGlobals = Object.getOwnPropertyNames(context); + actualGlobals.sort(); expectedGlobals.sort(); expect(actualGlobals).to.eql(expectedGlobals); expect(actualGlobals.length).to.be.above(1); }); + it("should ignore the given variables", function () { var context = { global: global @@ -44,18 +50,22 @@ describe("getImportGlobalsSrc", function () { ignore = ["console", "setTimeout"], src, actualGlobals, - expectedGlobals = Object.keys(global); + expectedGlobals = Object.getOwnPropertyNames(global); + + const ignoredGlobals = ["module", "exports", "require", "undefined", "eval", "arguments", "GLOBAL", "root", "NaN", "Infinity"]; + ignore = ignore.concat(ignoredGlobals); // 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; - }); + expectedGlobals = expectedGlobals.filter((el) => !ignore.includes(el)); + vm.runInNewContext(src, context); actualGlobals = Object.keys(context); + actualGlobals.sort(); expectedGlobals.sort(); expect(actualGlobals).to.eql(expectedGlobals); expect(actualGlobals.length).to.be.above(1); }); + }); -- cgit v1.2.3