R4-3: pnpm e2e:built (webpack and Turbopack); Playwright runs reset the test admins first

The command builds the reference site with both bundlers, checks the public files for a package manifest and runs
the late-staff spec and the published-files check against each built site. A global setup resets the test admins
and their stored 2FA attempt counts before every run, so a spec no longer depends on what ran before it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 02:53:41 +01:00
co-authored by Claude Fable 5.2
parent 9a648b0498
commit e77c607bca
5 changed files with 101 additions and 8 deletions
+10 -5
View File
@@ -21,13 +21,18 @@ Production check: `pnpm build && pnpm payload run e2e/create-test-admin.ts && AL
(Playwright starts the built site on port 3100 itself; another port: `E2E_BASE_URL=http://localhost:3200`, built with
the same `NEXT_PUBLIC_SERVER_URL`; a server you started yourself: `E2E_REUSE_SERVER=1`).
Access rules on a built site, both bundlers (a staff collection that a plugin listed after ipalKit adds — unit tests
run unminified code and cannot see what a bundle renames):
Every Playwright run first resets the test admins and clears their stored 2FA attempt counts (`e2e/global-setup.ts`),
so a spec does not fail because of what ran before it. The fresh-site spec needs an EMPTY database:
`E2E_SKIP_ADMIN_SETUP=1 DATABASE_URI=<empty local database> pnpm exec playwright test two-factor-setup`.
What only a built site shows, with both bundlers — from the plugin repository's root, part of the release gate:
```bash
E2E_LATE_STAFF=1 pnpm build && pnpm payload run e2e/create-test-admin.ts && E2E_LATE_STAFF=1 ALLOW_LOCAL_MEDIA=1 pnpm exec playwright test late-staff
E2E_LATE_STAFF=1 pnpm exec next build --turbopack && pnpm payload run e2e/create-test-admin.ts && E2E_LATE_STAFF=1 ALLOW_LOCAL_MEDIA=1 pnpm exec playwright test late-staff
pnpm e2e:built # webpack, then Turbopack: build with the late-staff fixture, check the public files, run the specs
```
Without `E2E_LATE_STAFF=1` the fixture adds nothing and the spec is skipped.
It checks the account rules of a staff collection that a plugin listed after ipalKit adds or copies
(`e2e/late-staff-fixture.ts`, on only with `E2E_LATE_STAFF=1`; `e2e/late-staff.spec.ts`) and that no package manifest
is among the public files. Unit tests run unminified code and cannot see what a bundle renames or publishes.
Without `E2E_LATE_STAFF=1` the fixture adds nothing and the spec is skipped. Rebuild with `pnpm build` afterwards.
## What is where
| Convention | Files |
+14
View File
@@ -0,0 +1,14 @@
import { execFileSync } from 'node:child_process'
/**
* Before every Playwright run: the test admins are made (or reset) and their stored 2FA attempt counts cleared
* (e2e/create-test-admin.ts). The count is kept in the database — 5 verify attempts per account in 10 minutes —
* so without this a second run within ten minutes, or one spec run after the whole suite, would find the test
* admin locked out: the result would depend on what ran before. Skipped when the test admin is not configured
* (the specs that need it skip themselves) or with E2E_SKIP_ADMIN_SETUP=1.
*/
export default function globalSetup(): void {
const { E2E_ADMIN_EMAIL, E2E_ADMIN_PASSWORD, E2E_SKIP_ADMIN_SETUP, E2E_TOTP_SECRET } = process.env
if (E2E_SKIP_ADMIN_SETUP === '1' || !E2E_ADMIN_EMAIL || !E2E_ADMIN_PASSWORD || !E2E_TOTP_SECRET) {return}
execFileSync('pnpm', ['payload', 'run', 'e2e/create-test-admin.ts'], { env: { ...process.env, NODE_ENV: 'development' }, stdio: 'inherit' })
}
+6 -3
View File
@@ -8,9 +8,10 @@ try {
}
/**
* Smoke tests against a built, seeded site: pnpm build && pnpm seed && pnpm payload run e2e/create-test-admin.ts.
* Run create-test-admin.ts again before repeating the tests within ten minutes: the 2FA verify limit (5 attempts per
* account in 10 minutes) is stored in the database, and that script clears the test admins' counts.
* Smoke tests against a built, seeded site: pnpm seed && pnpm build.
* The 2FA verify limit (5 attempts per account in 10 minutes) is stored in the database; the global setup resets the
* test admins and clears their counts before every run (e2e/global-setup.ts; E2E_SKIP_ADMIN_SETUP=1 for a run that
* needs an EMPTY database, the fresh-site spec).
* E2E_BASE_URL picks the port (default 3100). Playwright starts its own server there and fails when the port is
* taken, so another project's dev server is never tested by mistake; E2E_REUSE_SERVER=1 uses a server you started.
*/
@@ -18,6 +19,8 @@ const baseURL = process.env.E2E_BASE_URL ?? 'http://localhost:3100'
export default defineConfig({
forbidOnly: !!process.env.CI,
// makes every run independent of the one before: test admins reset, stored 2FA attempt counts cleared
globalSetup: './e2e/global-setup.ts',
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
reporter: process.env.CI ? 'line' : 'list',
retries: process.env.CI ? 1 : 0,