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
+70
View File
@@ -0,0 +1,70 @@
#!/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 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.
* 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 } 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)
}
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 and the published-files check`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'smoke', '--grep', 'late staff collection|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.)`)