How do I run postman's newman in CI environment?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 02:39:45

问题


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

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

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 is already configured with environment variables to test endpoints on port localhost:3000.

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

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"

回答1:


You can use wait-on package.

npm install --save-dev wait-on

Then,

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


来源:https://stackoverflow.com/questions/37466757/how-do-i-run-postmans-newman-in-ci-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!