简体   繁体   中英

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

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"

You can use wait-on package.

npm install --save-dev wait-on

Then,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM