如何在CI环境中运行postman的newman? [英] How do I run postman's newman in CI environment?

查看:174
本文介绍了如何在CI环境中运行postman的newman?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的CI环境(solano-ci)上运行 newman

I'd like to run newman on my CI environment (solano-ci).

newman 是一个运行邮递员集合中请求的工具。

newman is a tool that runs through requests in your postman collection.

我的 package.json 中有一个 newman 脚本,而且我还有 npm start localhost:3000 启动服务器的脚本。

I have a newman script in my package.json, and I also have a npm start script that starts the server at localhost:3000.

newman 已经配置了环境变量来测试端口 localhost:3000 上的端点。

newman is already configured with environment variables to test endpoints on port localhost:3000.

问题是我需要一个启动服务器的脚本( npm start )然后运行 npm run newman 。但是在服务器可用和 newman 运行它的测试之间存在延迟。如果 newman 在服务器可用之前运行,则会导致每个测试出错。

The issue is I need one script that starts the server (npm start) and then runs npm run newman. But there's a delay between when the server is available and when newman runs it's tests. If newman runs before the server is available it results in an error for each test.

Error: connect ECONNREFUSED 127.0.0.1:3000

现在这是我尝试使用的< a href =https://github.com/mysticatea/npm-run-all/blob/master/docs/run-p.md =nofollow> run-p 适用于并行启动两个进程。然后我必须使用 sleep 并设置等待的任意时间以确保服务器准备就绪。

Right now here's what I tried using run-p which works at starting two processes in parallel. Then I have to use sleep and set an arbitrary number of time the wait to ensure that the server is ready.

"newman": "newman -c ./postman/api.postman_collection.json -e ./postman/local.postman_environment.json",
"newman-sleep": "sleep 10 && npm run newman",
"newman-server": "run-p start newman-sleep"


推荐答案

您可以使用等待包。

npm install --save-dev wait-on

然后,

"newman-sleep": "wait-on http://localhost:3000 && npm run newman"

这篇关于如何在CI环境中运行postman的newman?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆