@pixpilot/next-test-utils
v1.1.2
Published
Utilities for testing Next.js applications.
Readme
@pixpilot/next-test-utils
Test helpers for Next.js App Router projects. Requires Node.js 20.1 or later.
analyzeAppRoutes scans an app directory for page.ts, page.tsx,
route.ts, and route.tsx. Route groups do not add URL segments. A dynamic
segment and its children are represented by their static prefix, so a route
such as /resume/[resumeId]/edit is checked as /resume.
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { analyzeAppRoutes } from '@pixpilot/next-test-utils';
import { expect, it } from 'vitest';
import { matchRoute } from './site-routes';
const appDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../src/app');
it('classifies every app route', () => {
const { routes, unclassifiedRoutes } = analyzeAppRoutes({ appDir, matchRoute });
expect(routes.length).toBeGreaterThan(0); // Ensure the scan found the intended app.
expect(unclassifiedRoutes).toEqual([]);
});The matcher receives each URL prefix and must return undefined for an
unclassified route. The helper has no dependency on Next.js, React, or Vitest;
callers can use any test runner and their own route manifest.
