Introduction
Compose fixtures and choose a guide for your Next.js tests
Combine fixtures in your shared test helper, then choose a guide for the behavior you want to test.
Choose your MSW version
Use @octopus-energy/playwright/msw/v2 with msw@2, or /msw/v3 with msw@3 and graphql. The version tabs share your selection with getting started and the API reference.
The root API entry point has been removed. Move factory and version-specific type imports to the matching MSW entry point; import shared helpers and options types from their domain entry points, not /msw/v2 or /msw/v3. Shared configuration and flag helpers compose with either factory, with unchanged signatures and behavior. Migrating existing MSW 2 imports does not require upgrading to MSW 3.
Compose fixtures
Chain .extend(...) calls to combine fixtures in one shared helper. This example mocks application configuration and Global Config-backed feature flags:
import { withGlobalConfigFlags } from "@octopus-energy/playwright/flags/global-config";
import { withGlobalConfig } from "@octopus-energy/playwright/global-config";
import { createPlaywrightHelpers } from "@octopus-energy/playwright/msw/v2";
const { test: base, expect } = createPlaywrightHelpers();
const flagDefaults = { checkoutRedesign: false };
const test = base
.extend(withGlobalConfig({ maintenanceMode: false }))
.extend(withGlobalConfigFlags(flagDefaults, { key: "checkout-flags" }));
export { expect, test };| Fixture set | Test fixture | Additional packages |
|---|---|---|
withGlobalConfig | globalConfig | @vercel/global-config |
withGlobalConfigFlags | globalConfigFlags | @octopus-energy/flags, @vercel/global-config, flags |
withVercelFlags | vercelFlags | @flags-sdk/vercel, flags |
withBlueprintAuth | blueprintAuth | @krakentech/blueprint-auth ^45.1.0 |
Configure GLOBAL_CONFIG for Global Config fixtures or FLAGS for Vercel Flags in the application server. Follow the Global Config cache settings to prevent cached values from leaking between tests. For Vercel's caching limits, see the Vercel flags guide.
Tests importing this helper can use msw, globalConfig, and globalConfigFlags together. Follow the Global Config guide and Global Config flags guide to configure the application.
Register request handlers or call a configuration fixture’s .use(...) before navigation or the action that reads those values. Each test gets its own overrides, and shared defaults apply again in the next test. Blueprint authentication instead requires global setup before issuing tokens.
Use the API reference for fixture signatures and options.
Next steps
Choose the integration you want to mock:
Mock HTTP or GraphQL responses
Requests made with fetch or a GraphQL client.
Override Global Config values
Configuration read with @vercel/global-config.
Override Global Config feature flags
Flags evaluated with @octopus-energy/flags/global-config.
Override Vercel feature flags
Flags evaluated with @flags-sdk/vercel.
Test signed-in Blueprint users
Set up the auth fixture and start a test with an existing session.
Test Blueprint user sessions
Exercise email sign-in, rejected credentials, and session refresh.
Test Blueprint OAuth redirects
Run sign-in through the application’s OAuth start and callback routes.
Test scoped and masquerade access
Exercise credential-based entry routes and authentication failures.
Test organization authentication
Supply a cached organization token through mocked Global Config.