UNPKG

@apideck/portman

Version:

Port OpenAPI Spec to Postman Collection, with contract & variation tests included

32 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeOperationTestScript = void 0; var postman_collection_1 = require("postman-collection"); var writeOperationTestScript = function (pmOperation, testScript, overwrite, append) { var _a; if (overwrite === void 0) { overwrite = false; } if (append === void 0) { append = true; } var pmTestEvent = pmOperation.item.events.find(function (e) { return (e === null || e === void 0 ? void 0 : e.listen) === 'test'; }, null); if (pmTestEvent === undefined) { pmOperation.item.events.add(new postman_collection_1.Event({ listen: 'test', script: { exec: [testScript], type: 'text/javascript' } })); return pmOperation; } if (!((_a = pmTestEvent === null || pmTestEvent === void 0 ? void 0 : pmTestEvent.script) === null || _a === void 0 ? void 0 : _a.exec) || overwrite) { pmTestEvent.script.exec = []; } if (append) { pmTestEvent.script.exec.push(testScript); } else { pmTestEvent.script.exec.unshift(testScript); } return pmOperation; }; exports.writeOperationTestScript = writeOperationTestScript; //# sourceMappingURL=writeOperationTestScript.js.map