---
title: Add regression tests for a critical user flow
description: Protect a key Next.js user journey with isolated tests for visible outcomes, failure recovery, and relevant access boundaries.
url: "https://vercel.com/kb/prompts/add-critical-flow-regression-tests"
last_updated: 2026-11-07
related_resources:
  "[Playwright testing practices](https://playwright.dev/docs/best-practices)": "Write isolated tests that check user-visible behavior and control external dependencies."
  "[Use Playwright with Next.js](https://nextjs.org/docs/app/guides/testing/playwright)": "Connect browser tests to a Next.js application and its local server."
---

# Add regression tests for a critical user flow

Protect a key Next.js user journey with isolated tests for visible outcomes, failure recovery, and relevant access boundaries.

Protect a user journey that would be costly to break, such as creating a record or completing onboarding. This prompt focuses testing effort on observable behavior and a plausible regression.

Open or import your Next.js project and describe the flow, its expected outcome, and any known failure. Provide local setup and test accounts separately; choosing an agent passes the prompt without the repository.

Your agent will extend the existing test setup, exercise recovery where relevant, and explain what the tests catch. Expect repeatable local checks and explicit gaps where external integrations remain mocked or unavailable.

## Agent prompt

```text
Add focused regression coverage for one critical user flow in my existing Next.js app.

If no project is available, ask me to open or import it first. Read repository instructions and identify the installed framework version, package manager, test runner, fixtures, and local server setup. Ask which user journey and failure matter if I have not specified them. Describe the starting state, user actions, and observable success or failure before implementing tests. Reuse existing coverage and helpers rather than adding a parallel suite.

Choose the lowest test boundary that can expose the actual regression. Use browser coverage when navigation, forms, hydration, or multiple UI steps matter, and keep the relevant application behavior real. If browser tooling is absent, propose a compatible minimal setup and implement it within the repository's conventions. Do not upgrade the framework or replace the test stack to complete this task.

Create independent synthetic fixtures and isolated test sessions. Keep credentials out of committed data and logs. Mock uncontrolled external services at their boundary, including payments or messages, and document the integration that remains untested. If required credentials or services are unavailable, use local fixtures and mark the real integration checks as blocked. Do not mock away the application behavior the test is meant to protect.

Cover the successful journey and its most consequential failure or recovery path. Include rejected input, unauthorized access, or cross-account isolation when relevant to this flow. For interactive UI, use accessible roles or labels, check meaningful loading or error feedback, and exercise keyboard submission or focus recovery where applicable. Prefer condition-based assertions to arbitrary sleeps, CSS selectors, or snapshots of internal structure.

Demonstrate that the regression test detects the known bug when practical, or introduce a temporary targeted fault in an isolated working copy and verify that the assertion fails for the intended reason. Restore the correct implementation without disturbing unrelated edits. Setup failures do not count as detecting a bug. Repeat the focused suite enough to check fixture isolation and run relevant lint and type checks.

Do not submit real transactions, send messages, modify live accounts, or deploy without my approval. Report the covered behavior, actual commands and results, local run steps, required configuration, and untested integrations. Explain any reason a failure-detection check could not run.
```

## Related resources

- [Playwright testing practices](https://playwright.dev/docs/best-practices): Write isolated tests that check user-visible behavior and control external dependencies.

- [Use Playwright with Next.js](https://nextjs.org/docs/app/guides/testing/playwright): Connect browser tests to a Next.js application and its local server.

## Try other prompts

- [Reduce the JavaScript your app sends to browsers](/kb/prompts/reduce-client-javascript): Trim client JavaScript on one Next.js route, measure the difference, and preserve the interactions your users need.

- [Improve your app’s accessibility](/kb/prompts/improve-app-accessibility): Find and fix reproducible accessibility barriers in a key user journey, combining automated checks with keyboard and focus testing.

## Reference Architecture

Choose a stack and work through the decisions behind it, with curated documentation, guides, templates, and courses to help you build.

- [Agent stack](/kb/architecture/agents): Build and operate agents with models, tools, and durable workflows.
- [Web applications](/kb/architecture/web): Choose rendering, data, authentication, and caching approaches.
- [Backends](/kb/architecture/backends): Choose a runtime, connect services, and run background work.

[Browse all stacks](/kb/architecture)

## Build with prompts

Build an app, extend an agent, or improve your project with ready-to-use prompts for your coding agent.

[Browse the prompt library](/kb/prompts) · [Read the Markdown index](/kb/prompts.md)
