The way I run tests locally is normally npm start and then, once the server is running, in a different terminal tab I run npm test. This is because my test scripts make multiple HTTP calls to the web server started in npm start.
No, this won’t work because I need to wait for the port to be opened / the server to be started before running the tests. I could do a sleep 10 etc but this seems hacky
What about following it with a curl request using --connect-timeout and --max-time? That way your build script would stall (I think) until your server is up. Otherwise, wrap that call in a loop?
Did you ever get this figured out? We use a similar workflow, but I can’t seem to get my node server to start in the background, and still get my tests to hit the local urls
I setup separate run commands to get a graphql server running and listening so I could execute tests against it. https://circleci.com/docs/2.0/configuration-reference/#run explained how to override the shell to ignore a failed exit code.
# get server up and running in the background
- run:
command: yarn test-server
background: true
# wait for the server to start responding. We expect Bad Request 400 once it starts listening.
# so override the shell and have the last command be the : { null } command to force exit code 0.
- run:
shell: /bin/sh
command: |
wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 10 http://localhost:3032/graphql
:
- run:
command: yarn test