UNPKG

@ply-ct/ply

Version:

REST API Automated Testing

112 lines 4.71 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubflowExec = void 0; const util = __importStar(require("../util")); const exec_1 = require("./exec"); const values_1 = require("../values"); const ply_1 = require("../ply"); const runner_1 = require("../runner"); class SubflowExec extends exec_1.StepExec { async run(context) { var _a; const subflowPath = context.getAttribute('subflow', { required: true }); const subflow = await new ply_1.Ply(context.runtime.options, context.logger).loadFlow(subflowPath); // bind subflow values (_a = context.runOptions) === null || _a === void 0 ? true : delete _a.values; const inValues = context.getAttribute('inValues'); if (inValues) { if (!context.runOptions) context.runOptions = {}; if (!context.runOptions.values) context.runOptions.values = {}; const rows = JSON.parse(inValues); for (const row of rows) { let rowVal = row[1]; if (this.isExpression(rowVal)) { rowVal = context.evaluateToString(rowVal); } if (('' + rowVal).trim() === '') { rowVal = undefined; // empty string } else { const numVal = Number(row[1]); if (!isNaN(numVal)) rowVal = numVal; else if (row[1] === 'true' || row[1] === 'false') rowVal = row[1] === 'true'; else if (util.isJson(row[1])) rowVal = JSON.parse(row[1]); } context.runOptions.values[row[0]] = rowVal; } } const plyValues = new values_1.ValuesBuilder(context.runtime.options.valuesFiles, context.logger); let subValues = await plyValues.read(); const substeps = new Map(); substeps.set(subflow, subflow.all().map((step) => { return step.step.id; })); const runner = new runner_1.PlyRunner(context.runtime.options, substeps, subValues, context.logger); await runner.runSuiteTests(subValues, context.runOptions); let outBindings; const outValues = context.getAttribute('outValues'); if (outValues) { outBindings = {}; // flow value name to return value name for (const row of JSON.parse(outValues)) { if (row[1]) { outBindings[row[1]] = row[0]; } } } let status = 'Passed'; const data = []; for (const result of runner.results) { data.push([ subflowPath, result.status, result.start || '', result.end || '', result.message || '' ]); if (result.status !== 'Passed') { status = result.status; } if (outBindings) { const returnValues = result.return; if (returnValues) { for (const flowValName of Object.keys(outBindings)) { context.values[flowValName] = returnValues[outBindings[flowValName]]; } } } } // const dataRes = await this.verifyData(runtime, data, values, runOptions); // if (dataRes.status !== 'Passed' && status === 'Passed') status = dataRes.status return { status, data }; } } exports.SubflowExec = SubflowExec; //# sourceMappingURL=subflow.js.map