How to Override Vercel Feature Flags in Playwright e2e?
Manually I can install Vercel toolbar and set a feature flag there. This action will add vercel-flag-overrides cookie, but it only works if I have _vercel_session and __vercel_live_token set.
So, the question is how to do this programmatically? Is there a way to enable a feature flag with a cookie/header or some Vercel SDK?
Great question, and I actually wanted to write a more detailed article about this. Until I get around to that, the steps are outlined below:
You can use the encryptOverrides function (see docs) to programmatically create an override for the feature flags you need. You can then make playwright forward this override as the vercel-flag-overrides cookie from tests.
These overrides will be respected by the Flags SDK even without the _vercel_session and __vercel_live_token cookies. Note that if you are testing a preview deployment you will need to bypass deployment protection (docs).
Here is a snippet of what this could look like roughly:
It is a slightly cumbersome having to set a cookie in Playwright and we are considering extending the Flags SDK to also accept overrides as a regular header, which will make it even easier to override.