| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | import 'reflect-metadata';import format from 'string-template';import { assert } from 'chai';import { GlobalVariableNoEvalTemplate } from '../../../../../src/custom-code-helpers/common/templates/GlobalVariableNoEvalTemplate';describe('GlobalVariableNoEvalTemplate', () => {    describe('Variant #1: simple', () => {        const expectedGlobalObject: NodeJS.Global = global;        let globalObject: NodeJS.Global;        before(() => {            const globalVariableNoEvalTemplate: string = format(GlobalVariableNoEvalTemplate());            globalObject = Function(`                ${globalVariableNoEvalTemplate}                                return that;            `)();        });        it('should correctly return global object', () => {            assert.deepEqual(globalObject, expectedGlobalObject);        });    });    describe('Variant #2: call inside function', () => {        const expectedGlobalObject: NodeJS.Global = global;        let globalObject: NodeJS.Global;        before(() => {            const globalVariableNoEvalTemplate: string = format(GlobalVariableNoEvalTemplate());            globalObject = Function(`                return (function () {                    ${globalVariableNoEvalTemplate}                                        return that;                })();            `)();        });        it('should correctly return global object', () => {            assert.deepEqual(globalObject, expectedGlobalObject);        });    });    describe('Variant #3: return `window`', () => {        const expectedGlobalObject: {} = {            document: {}        };        let globalObject: NodeJS.Global;        before(() => {            const globalVariableNoEvalTemplate: string = format(GlobalVariableNoEvalTemplate());            globalObject = Function(`                this.window = {                    document: {}                };                            ${globalVariableNoEvalTemplate}                                return that;            `)();            // for some reason it couldn't correctly compare global objects without JSON.stringify/JSON.parse            globalObject = JSON.parse(JSON.stringify(globalObject));        });        it('should correctly return `window` object', () => {            assert.deepEqual(globalObject, expectedGlobalObject);        });    });});
 |