【发布时间】:2018-10-24 02:03:04
【问题描述】:
我有一个可以运行的 newman 脚本:
var fs = require('fs'),
newman = require('newman'),
results = [];
newman.run({
reporters: 'cli',
collection: require('.temp.json'),
iterationData: './data.jsp',
reporters: ['cli', 'html'],
reporter: {
html: {
export: './newman/htmlResults.html', // If not specified, the file will be written to `newman/` in the current working directory.
}
}
})
.on('request', function (err, args) {
if (!err) {
// here, args.response represents the entire response object
var rawBody = args.response.stream, // this is a buffer
body = rawBody.toString(); // stringified JSON
results.push(JSON.parse(body)); // this is just to aggregate all responses into one object
}
})
// a second argument is also passed to this handler, if more details are needed.
.on('done', function (err, summary) {
// write the details to any file of your choice. The format may vary depending on your use case
fs.writeFileSync('migration-report.json', JSON.stringify(results, null, 4));
if(summary.run.failures.length !== 0){
console.log("\\rThere are test failures")
//here I can exit but the Newman summary isn't showed
}
});
此脚本有效,但即使测试失败,它也成功完成。显示了测试失败,但我想以退出代码 1 之类的内容结束脚本,因为我将在 Jenkins 中运行它,并且我不想根据 buildresult 颜色检查测试是否有效。如何在节点中执行此操作?
【问题讨论】: