Files
ipal-kit/scripts/e2e-built.mjs
T
Radosław SmolińskiandClaude Opus 5.5 7159ec25de Merge claude/login-page-whitelabel-616f3d: the panel's sign-in look (whiteLabel.signIn), the client's logo, hardened brand image fetch
Conflicts kept both sides: the 2FA texts (twoFactorBusy from A, twoFactorCodeDigit here), the reference index rows,
and the e2e:built line (closed doors from C and the sign-in look here). routes.snapshot.json judges the new public
GET /api/ipal/admin-language.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-26 22:04:30 +01:00

96 lines
6.5 KiB
JavaScript

#!/usr/bin/env node
/**
* pnpm e2e:built — the checks that only a BUILT site can make, with BOTH bundlers.
*
* Unit tests run unminified code. A production bundle renames every function and decides what becomes a public
* asset; two defects of 1.16.7's review lived only there (a rule that told Payload's default by its name; the
* plugin's package.json among a Turbopack build's static files). So for the reference site, once with webpack and
* once with Turbopack:
* 1. production build with the late-staff fixture (E2E_LATE_STAFF=1, reference/e2e/late-staff-fixture.ts);
* 2. no package manifest under .next/static (checked on disk, before anything is started);
* 0. (once, before the builds) every public route is judged: `pnpm routes:check` (reference/e2e/routes.snapshot.json);
* 3. Playwright against `next start`: e2e/closed-doors.spec.ts (every door of e2e/closed-doors.ts asked as an anonymous
* visitor, a customer and an editor), e2e/late-staff.spec.ts, e2e/mail-relay.spec.ts (the mail service: the confirm
* route under Next, the state block in the panel's production bundle) and the smoke tests "no package.json is published",
* "client hints" (Payload's colour-scheme headers on the admin only; a public page is requested once), every
* "consent" test (banner at first paint, Global Privacy Control, equal prominence, withdrawal, the consent log)
* and e2e/sign-in-look.spec.ts (the sign-in panel in the first HTML, on a phone, the language links, the 2FA screen).
*
* Needs what the reference site's "Production check" needs (reference/README.md): reference/.env with a local,
* seeded database and the E2E_* test admin. The test admins are reset by Playwright's global setup.
* Port: E2E_BASE_URL (default http://localhost:3100), the same value as NEXT_PUBLIC_SERVER_URL in reference/.env.
* The reference site's generated files (payload-types.ts, the import map) are put back as they were at the end,
* also when a step fails: the working tree is the same after the run.
* Options: --only=webpack | --only=turbopack; --skip-plugin-build (dist and the injected copy are current).
*/
import { spawnSync } from 'node:child_process'
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const site = path.join(root, 'reference')
const args = process.argv.slice(2)
const only = args.find((a) => a.startsWith('--only='))?.slice('--only='.length)
const bundlers = ['webpack', 'turbopack'].filter((b) => !only || b === only)
if (!bundlers.length) {throw new Error(`--only must be webpack or turbopack, got "${only}"`)}
const run = (label, command, commandArgs, cwd, env = {}) => {
console.log(`\n[e2e:built] ${label}`)
const result = spawnSync(command, commandArgs, { cwd, env: { ...process.env, ...env }, stdio: 'inherit' })
if (result.status !== 0) {
console.error(`\n[e2e:built] ✗ FAILED: ${label}`)
process.exit(result.status ?? 1)
}
}
const walk = (dir) => (existsSync(dir) ? readdirSync(dir).flatMap((name) => {
const file = path.join(dir, name)
return statSync(file).isDirectory() ? walk(file) : [file]
}) : [])
if (!existsSync(path.join(site, '.env'))) {
console.error('[e2e:built] reference/.env is missing: cp reference/.env.example reference/.env, fill it (local database, E2E_* test admin), seed (reference/README.md).')
process.exit(1)
}
if (!args.includes('--skip-plugin-build')) {
run('build the plugin', 'pnpm', ['build'], root)
run('refresh the plugin copy in the reference site', 'pnpm', ['install', '--ignore-workspace'], site)
}
// Every public route judged (IAWL idea 34): from the config only, without the test fixtures, before any build.
run('every public route of the reference site is judged (pnpm routes:check)', 'node', ['scripts/routes-check.mjs'], root)
// The run starts Payload with the fixture's collections, and Payload rewrites the site's generated types then. The
// tree must be as it was after a required release step: the file is put back at the end — also when a step fails.
const generated = ['src/payload-types.ts', 'src/app/(payload)/admin/importMap.js'].map((rel) => path.join(site, rel)).filter((file) => existsSync(file)).map((file) => ({ before: readFileSync(file), file }))
const restore = () => {
for (const { before, file } of generated) {
if (!existsSync(file) || !readFileSync(file).equals(before)) {
writeFileSync(file, before)
console.log(`[e2e:built] restored ${path.relative(root, file)} (rewritten with the fixture's collections during the run)`)
}
}
}
process.on('exit', restore)
for (const signal of ['SIGINT', 'SIGTERM']) {process.on(signal, () => process.exit(130))}
const fixture = { E2E_LATE_STAFF: '1', NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ''} --max-old-space-size=3072`.trim() }
const passed = []
for (const bundler of bundlers) {
run(`${bundler}: production build with the late-staff fixture`, 'pnpm', ['exec', 'next', 'build', `--${bundler}`], site, fixture)
const statics = path.join(site, '.next', 'static')
const files = walk(statics)
if (!files.length) {
console.error(`[e2e:built] ✗ ${bundler}: .next/static is empty — the build did not produce a site`)
process.exit(1)
}
const manifests = files.filter((file) => /package[^/]*\.json$/.test(file) || (file.endsWith('.json') && /"(?:devDependencies|peerDependencies|publishConfig)"\s*:/.test(readFileSync(file, 'utf8'))))
if (manifests.length) {
console.error(`[e2e:built] ✗ ${bundler}: a package manifest is among the PUBLIC files of the build:\n${manifests.map((f) => ` /_next/static/${path.relative(statics, f)}`).join('\n')}`)
process.exit(1)
}
console.log(`[e2e:built] ✓ ${bundler}: no package manifest among ${files.length} public files`)
run(`${bundler}: the built site — late-staff spec, the mail service, closed doors, the published-files check, the client hints, consent and the sign-in look`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'smoke', 'sign-in-look', '--grep', 'late staff collection|the mail service|closed doors|no package.json is published|client hints|consent|sign-in look'], site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', E2E_LATE_STAFF: '1' })
passed.push(bundler)
}
console.log(`\n[e2e:built] passed: ${passed.join(' and ')}. (The reference site's .next now holds the ${passed.at(-1)} build WITH the fixture: rebuild with \`pnpm build\` there before other checks.)`)