An elegant, in-process Axios tester for Payload CMS. Say goodbye to slow Next.js dev server starts, network overhead, and flaky port conflicts.
Everything you need to test Payload CMS endpoint integrations completely in-memory.
Intercept requests locally and resolve them directly using Payload's sanitized configurations, cutting network overhead entirely.
Pass standard JWT auth headers. The adapter resolves the payload user session and
populates req.user automatically.
Ensures real SQLite or PostgreSQL transaction states flow properly into collection hooks, exactly like production environments.
Use the requestPatcher hook to modify, inject headers, or mock session
parameters right before they reach route handlers.
Built native in TypeScript. Autocomplete, interface definitions, and IDE hints make test setup clean and straightforward.
Configure timeout, headers, retry interceptors, and default status validations directly on a standard Axios client instance.
Setting up tests is as easy as wrapping your standard config with
createTesterAxios. It feels just like writing HTTP tests, minus the latency.
pnpm add -D payload-test-api-route-handler
import { describe, it, expect, beforeAll } from 'vitest';
import { getPayload } from 'payload';
import { buildConfig } from 'payload';
import { createTesterAxios } from 'payload-test-api-route-handler';
describe('API Routes', () => {
let config;
beforeAll(async () => {
config = await buildConfig({
// Standard configuration settings...
db: sqliteAdapter({ client: { url: 'file::memory:' } }),
secret: 'test-secret-at-least-32-chars-long',
});
await getPayload({ config });
});
it('performs fast in-memory get requests', async () => {
// 1. Create client instance mapped to your config
const client = createTesterAxios(config);
// 2. Call local endpoints directly
const res = await client.get('/api/posts/featured');
// 3. Make assertions in milliseconds!
expect(res.status).toBe(200);
expect(res.data.featured).toBe(true);
});
});
Run your integration suites at the speed of unit tests today.