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"
来源:https://stackoverflow.com/questions/37466757/how-do-i-run-postmans-newman-in-ci-environment