Files
metabuilder/e2e/global.setup.ts
Claude 8b0924ed65 fix(e2e): add /api/setup route to workflowui and fail fast on seed error
The E2E global setup calls POST /api/setup on localhost:3000, but port
3000 is the workflowui dev server which had no such route — it only
existed in the nextjs workspace. This caused a 404, leaving the DB
empty and making all data-dependent tests (workflowui-auth,
workflowui-templates) time out waiting for content that was never seeded.

- Add /api/setup/route.ts to workflowui that seeds InstalledPackage and
  PageConfig records via the DBAL REST API
- Make global setup throw on seed failure instead of logging and
  continuing, so the suite fails fast rather than running 250 tests
  against an empty database

https://claude.ai/code/session_01ChKf8wbKQLBcNbBCtqCwT6
2026-03-11 20:55:17 +00:00

56 lines
2.3 KiB
TypeScript

/**
* Playwright global setup
*
* 1. Starts the smoke-stack Docker containers via Testcontainers
* (nginx gateway + MySQL + MongoDB + Redis + admin tools)
* 2. Seeds the database via the /api/setup endpoint
*/
import { DockerComposeEnvironment, Wait } from 'testcontainers'
import { resolve, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
let environment: Awaited<ReturnType<DockerComposeEnvironment['up']>> | undefined
async function globalSetup() {
// ── 1. Start smoke stack via Testcontainers ──────────────────────────────
console.log('[setup] Starting smoke stack via Testcontainers...')
const composeDir = resolve(__dirname, '../deployment')
environment = await new DockerComposeEnvironment(composeDir, 'docker-compose.smoke.yml')
.withWaitStrategy('nginx', Wait.forHealthCheck())
.withWaitStrategy('phpmyadmin', Wait.forHealthCheck())
.withWaitStrategy('mongo-express', Wait.forHealthCheck())
.withWaitStrategy('redisinsight', Wait.forHealthCheck())
.withStartupTimeout(180_000)
.up()
console.log('[setup] Smoke stack healthy')
// Store ref for teardown
;(globalThis as Record<string, unknown>).__TESTCONTAINERS_ENV__ = environment
// ── 2. Wait for dev servers (started by Playwright webServer config) ─────
await new Promise(resolve => setTimeout(resolve, 2000))
// ── 3. Seed database ────────────────────────────────────────────────────
const setupUrl = process.env.PLAYWRIGHT_BASE_URL
? new URL('/api/setup', process.env.PLAYWRIGHT_BASE_URL.replace(/\/workflowui\/?$/, '')).href
: 'http://localhost:3000/api/setup'
try {
const response = await fetch(setupUrl, { method: 'POST' })
if (!response.ok) {
throw new Error(`Seed endpoint returned ${response.status} ${response.statusText}`)
}
console.log('[setup] Database seeded successfully')
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
console.error('[setup] Failed to seed database:', message)
throw new Error(`[setup] Seeding failed — aborting test suite. ${message}`)
}
}
export default globalSetup