Global Config flags
Define a Global Config-backed flag and override it in a test
Define a feature flag with the Global Config adapter for the Flags software development kit (SDK). Override its value in a test without connecting to your flag service.
Install the SDK
Add the SDK packages to your runtime dependencies:
npm i @octopus-energy/flags @vercel/global-config flagsConfigure the app server
Merge these SDK settings into webServer.env, preserving its other values:
env: {
GLOBAL_CONFIG: "https://global-config.vercel.com/test?token=test_config",
GLOBAL_CONFIG_DISABLE_DEVELOPMENT_SWR: "1",
OE_FLAGS_GLOBAL_CONFIG_KEY: "checkout-flags",
},The connection string uses a dummy token, not real credentials. Disabling the development stale-while-revalidate (SWR) cache prevents tests from sharing cached values. See application configuration for client-specific cache settings.
Define the flag
Create a flag module using the Global Config adapter. The adapter reads the item key from OE_FLAGS_GLOBAL_CONFIG_KEY:
import { createGlobalConfigAdapter } from "@octopus-energy/flags/global-config";
import { flag } from "flags/next";
const globalConfigAdapter = createGlobalConfigAdapter();
export const checkoutRedesign = flag<boolean>({
key: "checkoutRedesign",
adapter: globalConfigAdapter(),
});Create the checkout page
Choose the page for your router. Both variants evaluate the flag and render the corresponding heading:
Evaluate the flag in a server component:
import { checkoutRedesign } from "../../lib/flags";
export default async function CheckoutPage() {
const redesigned = await checkoutRedesign();
return <h1>{redesigned ? "New checkout" : "Original checkout"}</h1>;
}Set shared defaults
This example uses MSW 2. With MSW 3, import the factory from @octopus-energy/playwright/msw/v3 instead; the shared fixture composes with either factory. See version selection.
Extend your helper with a default flag value and the matching item key:
import { createPlaywrightHelpers } from "@octopus-energy/playwright/msw/v2";
import { withGlobalConfigFlags } from "@octopus-energy/playwright/flags/global-config";
const { test: base, expect } = createPlaywrightHelpers();
const test = base.extend(
withGlobalConfigFlags({ checkoutRedesign: false }, { key: "checkout-flags" }),
);
export { expect, test };The app and Playwright runner must agree on the item key. Passing { key: "checkout-flags" } to the fixture matches the app’s OE_FLAGS_GLOBAL_CONFIG_KEY setting. See the Global Config flags API for other options.
Enable the flag and assert checkout
Override the flag before navigation so the page reads the test’s value:
import { expect, test } from "../../lib/playwright/test";
test("shows redesigned checkout", async ({ globalConfigFlags, page }) => {
globalConfigFlags.use({ checkoutRedesign: true });
await page.goto("/checkout");
const heading = page.getByRole("heading", { name: "New checkout" });
await expect(heading).toBeVisible();
});Run the test from your app root:
npm exec -- playwright test tests/playwright/checkout.spec.tsThe override applies only to this test. The next test starts with checkoutRedesign: false.