Global Config
Set test defaults and per-test Global Config values without sharing development caches
Set shared defaults and per-test overrides for the Vercel Global Config software development kit (SDK). Test a maintenance notice without connecting to a real configuration store.
Application configuration
Set a test-only connection string and disable the development stale-while-revalidate (SWR) cache. 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",
},The URL contains a dummy token, not real credentials. Disabling the development cache prevents tests from sharing cached values.
Create the SDK client
Read the connection string from the app server’s environment:
import { createClient } from "@vercel/global-config";
export const globalConfig = createClient(process.env.GLOBAL_CONFIG);To disable caching per client instead, pass { disableDevelopmentCache: true } as the second createClient argument. Keep GLOBAL_CONFIG set. Use the environment setting when libraries create additional clients, including the Global Config flag adapter.
Create the maintenance page
Choose the page for your router. Both variants read maintenanceMode and render the corresponding heading:
Read the value in a server component:
import { globalConfig } from "../../lib/global-config";
export default async function MaintenancePage() {
const maintenanceMode = await globalConfig.get<boolean>("maintenanceMode");
if (maintenanceMode) return <h1>Temporarily unavailable</h1>;
return <h1>Service available</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 the helper with the configuration values your tests need:
import { createPlaywrightHelpers } from "@octopus-energy/playwright/msw/v2";
import { withGlobalConfig } from "@octopus-energy/playwright/global-config";
const { test: base, expect } = createPlaywrightHelpers();
const test = base.extend(withGlobalConfig({ maintenanceMode: false }));
export { expect, test };Override a value and assert the notice
Set maintenanceMode before navigating so the first server render reads the override:
import { expect, test } from "../../lib/playwright/test";
test("shows the maintenance notice", async ({ globalConfig, page }) => {
globalConfig.use({ maintenanceMode: true });
await page.goto("/maintenance");
const heading = page.getByRole("heading", {
name: "Temporarily unavailable",
});
await expect(heading).toBeVisible();
});Run the test from your app root:
npm exec -- playwright test tests/playwright/maintenance.spec.tsOverrides merge with the defaults for this test only. Use the Global Config flags guide for flags stored under a custom Global Config item key, rather than mocking their storage format yourself. See the Global Config fixture API for its signature.