Files
ipal-kit/scripts/e2e-built.mjs
T
Radosław SmolińskiandClaude Fable 5.2 2cceceffd0 Mail relay: state block without an import-map entry, e2e on the reference site, sharper failure reports
- the state block is rendered by IntegrationStatusBanner (no new admin component: generate:importmap gives no diff)
- reference site: e2e/mail-relay.spec.ts with a fixture and setup script; e2e:built runs it with both bundlers
- a failed enrolment is reported as what it was; the service's own refusal after a fresh enrolment
- a message keeps its key after any failure that is not final
- a local site is shown as refused in the panel before any e-mail

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-25 21:14:47 +01:00

88 lines
5.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);
* 3. Playwright against `next start`: 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 test "no package.json is published".
*
* 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)
}
// 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 and the published-files check`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'smoke', '--grep', 'late staff collection|the mail service|no package.json is published'], 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.)`)