1 | var expect = require("expect.js"),
|
2 | vm = require("vm"),
|
3 | getImportGlobalsSrc = require("../lib/getImportGlobalsSrc.js");
|
4 |
|
5 | describe("getImportGlobalsSrc", function () {
|
6 | it("should declare all globals with a var", function () {
|
7 | var context = {
|
8 | global: global
|
9 | },
|
10 | expectedGlobals,
|
11 | src,
|
12 | actualGlobals;
|
13 |
|
14 |
|
15 |
|
16 | global.module = module;
|
17 | global.exports = exports;
|
18 | global.require = require;
|
19 |
|
20 |
|
21 | global['a-b'] = true;
|
22 |
|
23 | src = getImportGlobalsSrc();
|
24 |
|
25 | delete global.module;
|
26 | delete global.exports;
|
27 | delete global.require;
|
28 | delete global['__core-js_shared__'];
|
29 | delete global['a-b'];
|
30 |
|
31 | expectedGlobals = Object.keys(global);
|
32 |
|
33 | vm.runInNewContext(src, context);
|
34 | actualGlobals = Object.keys(context);
|
35 | actualGlobals.sort();
|
36 | expectedGlobals.sort();
|
37 | expect(actualGlobals).to.eql(expectedGlobals);
|
38 | expect(actualGlobals.length).to.be.above(1);
|
39 | });
|
40 | it("should ignore the given variables", function () {
|
41 | var context = {
|
42 | global: global
|
43 | },
|
44 | ignore = ["console", "setTimeout"],
|
45 | src,
|
46 | actualGlobals,
|
47 | expectedGlobals = Object.keys(global);
|
48 |
|
49 |
|
50 | src = getImportGlobalsSrc(ignore.slice(0));
|
51 | expectedGlobals = expectedGlobals.filter(function filterIgnoredVars(value) {
|
52 | return ignore.indexOf(value) === -1;
|
53 | });
|
54 | vm.runInNewContext(src, context);
|
55 | actualGlobals = Object.keys(context);
|
56 | actualGlobals.sort();
|
57 | expectedGlobals.sort();
|
58 | expect(actualGlobals).to.eql(expectedGlobals);
|
59 | expect(actualGlobals.length).to.be.above(1);
|
60 | });
|
61 | });
|