admin管理员组文章数量:1122846
I wanted to be able to create a package library, and make it available for usage without having to import it into each and every script.
QUESTION: I figured out a way, but I was hoping there was a cleaner way. Is anyone aware of a way that would make pm.require
global?
The method I figured out:
The package library:
function HelloWorld() {
console.log('Hello World');
}
function GoodMorning(name) {
return `Good morning ${name}`;
}
module.exports = {
HelloWorld,
GoodMorning
}
The collection level script:
const myUtils = pm.require('@myteam/utils');
// wrap the library functions as a global so we dont have to import the library into every request.
utils = {
HelloWorld: function() {
myUtils.HelloWorld();
},
GoodMorning: function(name) {
console.log(myUtils.GoodMorning(name));
}
};
// now any scripts under this collection can use these functions without having to import the package;
本文标签:
版权声明:本文标题:How do I make a postman package script globally available without importing it into each script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284775a1927322.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论