UNPKG

@gatling.io/postman

Version:

Gatling Postman adds support for loading Postman collections in the [Gatling load testing tool](https://gatling.io/).

40 lines (39 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listItems = exports.findItem = exports.findItemGroup = exports.parseCollection = exports.readEnvironmentFromResource = void 0; const core_1 = require("@gatling.io/core"); const readEnvironmentFromResource = (filePath) => { // TODO generate ids so it's "easier" to get items later on? const env = JSON.parse((0, core_1.readResourceAsString)(filePath)); // TODO validate format return Object.fromEntries(env.values.filter((v) => v.enabled).map((v) => [v.key, v.value])); }; exports.readEnvironmentFromResource = readEnvironmentFromResource; const parseCollection = (json) => JSON.parse(json); exports.parseCollection = parseCollection; const findItemGroup = (parent, name) => { const index = parent.item.findIndex((i) => isItemGroup(i) && i.name === name); return index >= 0 ? [parent.item[index], index] : undefined; }; exports.findItemGroup = findItemGroup; const findItem = (parent, name) => { const index = parent.item.findIndex((i) => isItem(i) && i.name === name); return index >= 0 ? [parent.item[index], index] : undefined; }; exports.findItem = findItem; const listItems = (parent, currentPath, recursive) => parent.item.flatMap((i, index) => { if (isItem(i)) { return [[i, [...currentPath, index]]]; } else { // i is an ItemGroup if (recursive) { return (0, exports.listItems)(i, [...currentPath, index], true); } else { return []; } } }); exports.listItems = listItems; const isItemGroup = (i) => i.item !== undefined; const isItem = (i) => !isItemGroup(i);