Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: Start server only if it is not running. #379

Open
FDiskas opened this issue Mar 14, 2024 · 2 comments
Open

request: Start server only if it is not running. #379

FDiskas opened this issue Mar 14, 2024 · 2 comments

Comments

@FDiskas
Copy link

FDiskas commented Mar 14, 2024

If I already have running local server on port 1234
I was sure that start-server-and-test :1234 'cypress open --e2e --browser chrome' first will check if it is not running already before starting the local server.

Why this is not the case?

@benzado
Copy link

benzado commented Apr 24, 2024

How can it know if a server is already running? It could try connecting to the port, but that only confirms that something is listening... it could be a server from a different project!

I like that start-server-and-test will take ownership of the test server and terminates it when the tests are done. If it becomes too clever about using already running servers, it becomes too complex.

If your test server and development server are frequently fighting over the same port, may I suggest using a different port number for testing? You can even use a random port each time with a script like this:

#!/bin/bash

export PORT=$RANDOM
export CYPRESS_BASE_URL="http://localhost:$PORT"
npm exec -c "start-server-and-test start :$PORT 'cypress open'"

@adrianbienias
Copy link

Using curl and grep you can check if the URL, that you expect dev server to be running on, responds with 200 code.
And if not, then you can start dev server.

With npm script it can be something like the following:

"dev": "node server.js",
"cy:run": "cypress run",
"check-server": "curl -s -o /dev/null -w '%{http_code}' http://localhost:3000 | grep 200 || npm run dev",
"test": "start-server-and-test check-server 3000 cy:run",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants