Innovenergy_trunk/frontend/node_modules/testcafe/lib/api/test-controller/execution-context.js

89 lines
12 KiB
JavaScript
Raw Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExecutionContext = exports.setContextOptions = exports.DEFAULT_CONTEXT_OPTIONS = void 0;
const vm_1 = require("vm");
const module_1 = __importDefault(require("module"));
const path_1 = __importDefault(require("path"));
const exportable_lib_1 = __importDefault(require("../exportable-lib"));
const node_modules_folder_name_1 = __importDefault(require("../../utils/node-modules-folder-name"));
const OPTIONS_KEY = Symbol('options');
exports.DEFAULT_CONTEXT_OPTIONS = {
skipVisibilityCheck: false,
collectionMode: false,
};
function getModuleBasePaths(currentPath) {
const nodePaths = [];
let parentDir = path_1.default.dirname(currentPath);
while (currentPath !== parentDir) {
currentPath = parentDir;
parentDir = path_1.default.dirname(currentPath);
nodePaths.push(path_1.default.join(currentPath, node_modules_folder_name_1.default));
}
return nodePaths;
}
function createRequire(filename) {
//Deprecated since: Node v12.2.0
if (module_1.default.createRequireFromPath)
return module_1.default.createRequireFromPath(filename);
if (module_1.default.createRequire)
return module_1.default.createRequire(filename);
const dummyModule = new module_1.default(filename, module);
const localModulesPaths = getModuleBasePaths(filename);
dummyModule.filename = filename;
dummyModule.paths = localModulesPaths.concat(module.paths);
return id => dummyModule.require(id);
}
function createSelectorDefinition(testRun) {
return (fn, options = {}) => {
const { skipVisibilityCheck, collectionMode } = testRun.controller.getExecutionContext()[OPTIONS_KEY];
if (skipVisibilityCheck)
options.visibilityCheck = false;
if (testRun && testRun.id)
options.boundTestRun = testRun;
if (collectionMode)
options.collectionMode = collectionMode;
return exportable_lib_1.default.Selector(fn, options);
};
}
function createClientFunctionDefinition(testRun) {
return (fn, options = {}) => {
if (testRun && testRun.id)
options.boundTestRun = testRun;
return exportable_lib_1.default.ClientFunction(fn, options);
};
}
function setContextOptions(context, options) {
context[OPTIONS_KEY] = options;
}
exports.setContextOptions = setContextOptions;
function createExecutionContext(testRun) {
const filename = testRun.test.testFile.filename;
const replacers = {
require: createRequire(filename),
__filename: filename,
__dirname: path_1.default.dirname(filename),
t: testRun.controller,
Selector: createSelectorDefinition(testRun),
ClientFunction: createClientFunctionDefinition(testRun),
Role: exportable_lib_1.default.Role,
RequestLogger: exportable_lib_1.default.RequestLogger,
RequestMock: exportable_lib_1.default.RequestMock,
RequestHook: exportable_lib_1.default.RequestHook,
[OPTIONS_KEY]: exports.DEFAULT_CONTEXT_OPTIONS,
userVariables: exportable_lib_1.default.userVariables,
};
return (0, vm_1.createContext)(new Proxy(replacers, {
get: (target, property) => {
if (replacers.hasOwnProperty(property))
return replacers[property];
if (global.hasOwnProperty(property))
return global[property];
throw new Error(`${property} is not defined`);
},
}));
}
exports.createExecutionContext = createExecutionContext;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlY3V0aW9uLWNvbnRleHQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBpL3Rlc3QtY29udHJvbGxlci9leGVjdXRpb24tY29udGV4dC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSwyQkFBbUM7QUFDbkMsb0RBQTRCO0FBQzVCLGdEQUF3QjtBQUN4Qix1RUFBOEM7QUFDOUMsb0dBQWdFO0FBRWhFLE1BQU0sV0FBVyxHQUFHLE1BQU0sQ0FBQyxTQUFTLENBQUMsQ0FBQztBQUV6QixRQUFBLHVCQUF1QixHQUFHO0lBQ25DLG1CQUFtQixFQUFFLEtBQUs7SUFDMUIsY0FBYyxFQUFPLEtBQUs7Q0FDN0IsQ0FBQztBQUVGLFNBQVMsa0JBQWtCLENBQUUsV0FBVztJQUNwQyxNQUFNLFNBQVMsR0FBRyxFQUFFLENBQUM7SUFDckIsSUFBSSxTQUFTLEdBQUssY0FBSSxDQUFDLE9BQU8s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