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

[Feature]: webserver: add option for custom health check #34833

Open
jansepke opened this issue Feb 17, 2025 · 6 comments
Open

[Feature]: webserver: add option for custom health check #34833

jansepke opened this issue Feb 17, 2025 · 6 comments

Comments

@jansepke
Copy link
Contributor

🚀 Feature Request

add a new option to the playwright config webServer.healthcheck as an alternative to the existing webServer.url. this new config would be executed as a shell comand and retried until it either exits with exit code 0 or webServer.timeout is over.

the healthcheck could also be a JS function that returns true/false instead of passing a path to a shell script.

Example

export default defineConfig({
  webServer: {
    command: 'npm run start',
    healthcheck: './is-server-ready.sh',
  },
});

Motivation

Sometimes deciding if a webserver is ready for a test is more complex then just calling a healthcheck endpoint and expecting a status code 200. for example when running tests against a dockerized web application in CI we are using some complex data preseeding where the webserver itself does not know when the data is completely preseeded. but we could write a small script that returns if the preseeding is finished.

@jansepke
Copy link
Contributor Author

I took a look at the code and it should be enough if one would be able to pass isAvailableCallback as an option to the webServer config and then make it used here

this._isAvailableCallback = this._options.url ? getIsAvailableFunction(this._options.url, this._checkPortOnly, !!this._options.ignoreHTTPSErrors, this._reporter.onStdErr?.bind(this._reporter)) : undefined;

@Skn0tt
Copy link
Member

Skn0tt commented Feb 18, 2025

Hi Jan! Have you tried embedding your healthcheck in the command script? Copilot told me that something like npm run start && while ! ./is-server-ready.sh; do sleep 1 done should work.

@jansepke
Copy link
Contributor Author

This will not work as the start command does not exist so the second part of the && never gets executed

@Skn0tt
Copy link
Member

Skn0tt commented Feb 19, 2025

Of course, you're right. I've marked this as P3 to collect feedback on how big the need for this feature is amongst the userbase. If you read this, please upvote the issue if you'd like us to ship it.

@jansepke
Copy link
Contributor Author

jansepke commented Feb 19, 2025

would you also accept a PR to make the _isAvailableCallback available through the config without waiting for enough upvotes?

@Skn0tt
Copy link
Member

Skn0tt commented Feb 19, 2025

We're careful about extending our public API, so we always take community need into account. So let's wait for upvotes first. I'm sure you can find a workaround for your needs, feel free to post that for anybody else coming across this issue.

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

No branches or pull requests

2 participants