agentleFS
RamezHanyRamezHany/payload-cms-skills/skills/payload-testing/SKILL.md

payload-testing

Skill0 starsChanged 13 days agoMITView on GitHub

Tests for a Payload CMS 3 + Next.js 16 site using the official website template's Vitest (tests/int) and Playwright (tests/e2e) setup. Use when adding tests, wiring GitHub Actions, diagnosing a save that hangs, returns 403 or 413, or never appears on the site, or proving that one save revalidates only the routes in the PROJECT.md invalidation map. Covers drafts, WebP uploads, live preview, locale sync, the role access matrix, payment signature vectors, webhook idempotency, and a local SQLite file per run.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 3 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add tests to the Vitest and Playwright setup that ships in the official website template.

    line 11
  2. Distinctive:

    Follow references/template-setup.md.

    line 27
  3. Very specific:

    Do not add transactionOptions to the SQLite adapter.

    line 34
  4. Very specific:

    Keep the template specs (tests/e2e/admin.e2e.spec.ts, tests/e2e/frontend.e2e.spec.ts, tests/int/api.int.spec.ts, tests/helpers/login.ts, …

    line 38
  5. Distinctive:

    Add the specs in references/catalog.md:

    line 40
  6. Very specific:

    Add tests/int/invalidation.int.spec.ts from references/invalidation-trace.md.

    line 56
  7. Distinctive:

    When a save spins, returns an error, or does not show on the site, use references/save-failure-diagnosis.md before changing hooks or access …

    line 69
  8. Very specific:

    Before the first push, confirm the action major versions against the READMEs linked in the workflow comment.

    line 77
  9. Very specific:

    Do not put storage keys, Turso tokens, payment secrets, or the production PAYLOAD_SECRET in the workflow.

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Payload testing

Add tests to the Vitest and Playwright setup that ships in the official website template. Do not create a second runner, config, or tests/ tree.

The template (3.x branch) pins this layout:

ToolConfigFilesScript
Vitestvitest.config.mts, vitest.setup.tstests/int/**/*.int.spec.tspnpm test:int
Playwrightplaywright.config.tstests/e2e/pnpm test:e2e
Bothpnpm test

Read the project's copies of those files before editing. Versions move; the project's package.json wins over any version named in this skill. At the time of writing, the 3.x website template pinned vitest 4.0.18 and @playwright/test 1.63.0 as devDependencies, and its engines.node range started at ^22.23.5.

Step 1: Point every test at a local SQLite file

Tests must never open a Turso or other remote database. A remote URL in .env is how a test run deletes or migrates a client database.

Follow references/template-setup.md. It keeps the template files and only:

  1. Forces DATABASE_URL to a file: URL after dotenv loads, and deletes DATABASE_AUTH_TOKEN.
  2. Uses one file for Vitest (.data/vitest.db) and a different file for Playwright (.data/e2e.db).
  3. Runs Vitest in a single worker so SQLite does not throw SQLITE_BUSY.
  4. Throws if the URL does not start with file:.

Do not add transactionOptions to the SQLite adapter. Payload leaves SQLite transactions off because enabling them locks the database.

Step 2: Add the catalog

Keep the template specs (tests/e2e/admin.e2e.spec.ts, tests/e2e/frontend.e2e.spec.ts, tests/int/api.int.spec.ts, tests/helpers/login.ts, tests/helpers/seedUser.ts). Update frontend.e2e.spec.ts so it expects the project's real home title. Extend seedUser.ts with name once the users collection requires it (payload-auth-rbac skill).

Add the specs in references/catalog.md:

SpecProves
tests/e2e/admin-save.e2e.spec.tsCreate, save draft, reload, value persists, publish, frontend shows it
tests/e2e/media-upload.e2e.spec.tsAdmin upload stores WebP and the media URL is the storage host
tests/e2e/live-preview.e2e.spec.tsEditing the title updates the preview iframe
tests/e2e/locale-sync.e2e.spec.tsContent locale switches admin direction and the preview locale
tests/int/access.int.spec.tsLocal API with overrideAccess: false matches the role matrix
tests/int/payments.int.spec.tsOfficial signature vectors, plus one tampered signature
tests/int/webhooks.int.spec.tsThe same event delivered twice confirms the booking once

Payment and upload specs skip only in the cases the catalog names. A skip must print why. Do not delete a spec to make CI green.

Step 3: Invalidation trace (required before delivery)

Add tests/int/invalidation.int.spec.ts from references/invalidation-trace.md.

The spec mocks next/cache, performs one save per row of the PROJECT.md invalidation map, and fails unless the recorded revalidatePath and revalidateTag calls equal that row. It also fails when:

  • a draft-only save or a new media upload revalidates anything
  • any call uses the 'layout' type except a row whose paths cell is layout
  • any tag is cms-content, all, or site, or the same tag is emitted by two ordinary collections
  • a public collection in the map has no case

Rewrite map cells into the expandable form in that reference. The meaning stays the one defined by the payload-performance skill. Do not weaken the test to match a broad hook.

Step 4: Diagnose save failures

When a save spins, returns an error, or does not show on the site, use references/save-failure-diagnosis.md before changing hooks or access rules. Confirm the row's check, then apply that row's fix.

Step 5: GitHub Actions

Copy assets/ci.yml to .github/workflows/ci.yml.

The workflow installs with pnpm, generates a throwaway PAYLOAD_SECRET (masked, never printed), points DATABASE_URL at a local SQLite file, then runs generate, lint, tsc --noEmit, Vitest, and Playwright. It uploads the Playwright report only when the job fails.

Before the first push, confirm the action major versions against the READMEs linked in the workflow comment. If an example there uses a newer major, use that major. Confirm node-version satisfies the project's engines.node.

Do not put storage keys, Turso tokens, payment secrets, or the production PAYLOAD_SECRET in the workflow. The upload spec skips without storage credentials. Run that spec locally before delivery.

Stop and ask

  • The only available database URL is a remote Turso database. Do not point tests at it.
  • Storage credentials for the upload spec are missing and delivery requires that spec to have run.
  • payload-bookings-payments has no official signature vectors yet. Do not invent signatures; skip the payment spec with that reason and record it in PROJECT.md.
  • The template configs were replaced or the scripts were renamed, so the paths in Step 1 do not exist.

Done when

  • tests/int/invalidation.int.spec.ts lists every public collection and global in the PROJECT.md map, and pnpm test:int passes
  • A draft save and a new media create assert zero revalidatePath and revalidateTag calls
  • pnpm test:e2e passes locally with no other dev server on port 3000
  • The media upload spec has been run against the configured storage provider (not merely skipped)
  • .github/workflows/ci.yml is the copied workflow, and the GitHub Actions run is green
  • No test file contains a libsql:// URL or a DATABASE_AUTH_TOKEN value

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.