Skip to Content
Octopus Energy Packages

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:

lib/playwright/test.ts
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 setTest fixtureAdditional packages
withGlobalConfigglobalConfig@vercel/global-config
withGlobalConfigFlagsglobalConfigFlags@octopus-energy/flags, @vercel/global-config, flags
withVercelFlagsvercelFlags@flags-sdk/vercel, flags
withBlueprintAuthblueprintAuth@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:

On this page