如何解决newman运行的文件夹中的断言总数
我正在使用newman来运行邮递员收藏。由于存在多个集合,因此我使用newman运行整个文件夹。我遇到的问题是,纽曼为每个集合分别显示断言计数,因此我必须手动将它们加起来以获得断言的总数。
无论如何,我可以获得整个文件夹的断言总数吗?
解决方法
如果您指的是在文件夹中运行所有集合的npm脚本,则类似的方法将起作用。这是一个非常原始的解决方案,但我认为别无选择,因为我们多次调用newman.run
。
#!/usr/bin/env node
var newman = require('newman'),fs = require('fs');
fs.readdir('./collections',function (err,files) {
if (err) { throw err; }
files = files.filter(function (file) {
return (/^((?!(package(-lock)?))|.+)\.json/).test(file);
});
console.log(files);
var failedTests = 0;
var completed = 0;
files.forEach(function (file) {
newman.run({
collection: require(`./collections/${file}`),reporters: 'cli',},function (err) {
if (err) { throw err; }
}).on('done',summary) {
var collectionName = summary.collection.name;
summary.run.failures.forEach(failure=>{
failedTests++;
});
completed++;
if(completed == files.length){
if(failedTests != 0){
console.log("Run completed!");
console.log("Tests failed: "+ numFailedTests);
}else{
console.log("No failed tests");
}
}
});
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。