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

89 lines
12 KiB
JavaScript

"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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlY3V0aW9uLWNvbnRleHQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBpL3Rlc3QtY29udHJvbGxlci9leGVjdXRpb24tY29udGV4dC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSwyQkFBbUM7QUFDbkMsb0RBQTRCO0FBQzVCLGdEQUF3QjtBQUN4Qix1RUFBOEM7QUFDOUMsb0dBQWdFO0FBRWhFLE1BQU0sV0FBVyxHQUFHLE1BQU0sQ0FBQyxTQUFTLENBQUMsQ0FBQztBQUV6QixRQUFBLHVCQUF1QixHQUFHO0lBQ25DLG1CQUFtQixFQUFFLEtBQUs7SUFDMUIsY0FBYyxFQUFPLEtBQUs7Q0FDN0IsQ0FBQztBQUVGLFNBQVMsa0JBQWtCLENBQUUsV0FBVztJQUNwQyxNQUFNLFNBQVMsR0FBRyxFQUFFLENBQUM7SUFDckIsSUFBSSxTQUFTLEdBQUssY0FBSSxDQUFDLE9BQU8sQ0FBQyxX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