Running Tests
Test Structure
Unit and Integration Tests
Unit and integration tests are written using Vitest and live in thetests/ directory.
tests/*.test.ts. When adding new functionality, always add corresponding test cases.
E2E Tests
Browser-level tests are written using Playwright and live in thetests/e2e/ directory.
- Pages Router (dev + production)
- App Router (dev)
- Both routers on Cloudflare Workers via
wrangler dev
tests/e2e/. These are essential for catching subtle browser issues that unit tests miss — rendered output, client-side navigation, hydration behavior, etc.
Test Fixtures
Test fixtures are minimal Next.js applications used for integration testing:tests/fixtures/pages-basic/— Pages Router test apptests/fixtures/app-basic/— App Router test appexamples/app-router-cloudflare/— App Router on Workersexamples/pages-router-cloudflare/— Pages Router on Workers
Add new test pages to fixtures, not to examples. Examples are for user-facing demos.
Integration Tests
The Vercel App Router Playground runs on vinext as an integration test. See it live at app-router-playground.vinext.workers.dev.Test Coverage
The test suite includes:- 1,700+ Vitest tests covering unit and integration scenarios
- 380+ Playwright E2E tests covering browser behavior
- Tests ported directly from the Next.js test suite
- Tests from OpenNext’s Cloudflare conformance suite
- Routing (file-system routing, dynamic routes, catch-all, route groups)
- SSR and RSC rendering
- Server actions
- Caching (ISR,
"use cache", fetch cache) - Metadata generation
- Middleware execution
- Streaming SSR
- Client-side navigation and hydration
tests/nextjs-compat/TRACKING.md for detailed compatibility tracking.
Debugging Tests
For browser-level debugging, we recommend agent-browser. It’s effective at verifying:- Rendered output
- Client-side navigation
- Hydration behavior
- Interactive component behavior
Writing Tests
When adding new functionality:- Add tests first — put test cases in the appropriate
tests/*.test.tsfile - Add fixture pages if needed — create test pages in
tests/fixtures/for integration testing - Run the full test suite before committing — ensure all tests pass
- Add E2E tests for UI behavior — if the feature affects browser behavior, add Playwright tests
Smoke Tests
scripts/smoke-test.sh is a lightweight post-deploy check that curls every deployed example and verifies HTTP 200 + expected content. It runs automatically in CI after the deploy job completes.
expected-text is a case-insensitive string that must appear in the response body.