Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[, mockRequest.action] = action.name.match(MOCK_REQUEST_ACTION_REGEX);
}
let [url, options] = astObject.arguments;
if (url && options) {
// We escape parts of the RegExp when we save it, so we need to un-escape
// it before it goes back into the UI:
mockRequest.url = url.regex.pattern.replace(/\\\?/g, '?');
let [passThrough] = match(options, MOCK_REQUEST_PASSTHROUGH_QUERY);
if (passThrough) {
mockRequest.passThrough = passThrough.value;
return;
}
let [data] = match(options, MOCK_REQUEST_DATA_QUERY);
if (data) {
mockRequest.data = mockRequest.test.spec.availableMockRequests.find(mockRequest => mockRequest.variableName === data.name);
}
let [status] = match(options, MOCK_REQUEST_STATUS_QUERY);
if (status) {
mockRequest.status = status.value;
}
let headers = match(options, MOCK_REQUEST_HEADERS_QUERY);
headers.forEach(headerASTObject => {
let header = headerParserService.parse(mockRequest, headerASTObject);
mockRequest.headers.push(header);
});
}
}
if (!selector) {
step.addSelector();
selector = step.selectors[step.selectors.length - 1];
}
const [groupSelector] = match(astObject, GROUP_SELECTOR_QUERY);
if (groupSelector) {
selector.element = selector.parentElement.elements.find(element => {
return element.variableName === groupSelector.callee.property.name;
});
const [selectorArgument] = groupSelector.arguments;
selector.value = selectorArgument.value;
return;
}
const [elementSelector] = match(astObject, ELEMENT_SELECTOR_QUERY);
if (elementSelector) {
selector.element = selector.parentElement.elements.find(element => {
return element.variableName === elementSelector.property.name;
});
}
}
extractCode(AST) {
let me = this;
let esquery = require('esquery');
const validDefines = `[expression.callee.object.name = 'Ext'][expression.callee.property.name = define][expression.arguments.0.value!='null']`;
let matches = esquery.match(AST, esquery.parse(validDefines));
if (matches && matches[0] && matches[0].expression.arguments) {
me.addName(matches[0].expression.arguments[0].value);
}
matches = esquery.match(AST, esquery.parse(`${validDefines} ObjectExpression > Property[key.name=alternateClassName]`));
if (matches && matches[0] && matches[0].value) {
let node = matches[0].value;
if (node.type === "Literal") {
me.addName(node.value);
} else if (node.type === "ArrayExpression") {
node.elements.forEach((element) => {
me.addName(element.value);
});
}
}
matches = esquery.match(AST, esquery.parse(`${validDefines} ObjectExpression > Property[key.name=requires]`));
function parse (pageObject, astObject, meta = {}) {
let action = new ActionModel(pageObject);
action.name = meta.name;
let [actionFunction] = match(astObject, ACTION_FUNCTION_QUERY);
actionFunction.params.forEach(param => {
let parameterMeta = meta.parameters[action.parameters.length];
let parameter = new ValueModel(parameterMeta);
if (!parameterMeta) {
parameter.isUnparseable = param;
}
action.parameters.push(parameter);
});
let interactions = match(astObject, INTERACTION_QUERY);
if (interactions.length) {
interactions.forEach(interactionASTObject => {
let interaction = interactionParserService.parse(action, interactionASTObject);
action.interactions.push(interaction);
});
}
function _elementParser (pageObject, astObject) {
let { elements } = pageObject;
let [elementMemberExpression] = match(astObject, ELEMENT_MEMBER_EXPRESSION_QUERY);
return elementMemberExpression && elements.find(element => element.variableName === elementMemberExpression.property.name);
}
function getImports(ast) {
//var selector = esquery.parse("[type=ImportSpecifier]");
var selector = esquery.parse(":matches(ImportDefaultSpecifier,ImportSpecifier, ImportNamespaceSpecifier)"),
res = esquery.match(ast, selector);
return res.map(_boundaries);
}
Object.keys(QUERY_SELECTOR).find(key => {
let [result] = match(astObject, QUERY_SELECTOR[key]);
if (result) {
QUERY_HANDLER[key](interaction, result);
return interaction;
}
});
if (!pageObject) {
return step;
}
let selectors = match(astObject, SELECTOR_QUERY);
let [assertion] = match(astObject, ASSERTION_QUERY);
if (assertion) {
step = assertionParserService.parse(test, astObject);
_parseStepPageObject(step, pageObject);
selectors.forEach((selector, i) => _parseSelector(step, selector, i));
_parseStepAction(step, assertion);
return step;
}
let [interaction] = match(astObject, INTERACTION_QUERY);
if (interaction) {
step = new SpecInteractionModel(test);
_parseStepPageObject(step, pageObject);
selectors.forEach((selector, i) => _parseSelector(step, selector, i));
_parseStepAction(step, interaction);
return step;
}
return step;
}
function _parseAssertion (assertion, astObject) {
let [argument] = match(astObject, ASSERTION_ARGUMENT_QUERY);
assertion.expectedResult.value = argument && argument.value != null ? argument.value.toString() : null;
let [condition] = match(astObject, ASSERTION_CONDITION_QUERY);
assertion.condition = condition && condition.name;
}
}
function _actionParser (pageObject, astObject) {
let { actions } = pageObject;
let [actionMemberExpression] = match(astObject, ACTION_MEMBER_EXPRESSION_QUERY);
return actionMemberExpression && actions.find(action => action.variableName === actionMemberExpression.property.name);
}