mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
The workflowui Next.js app uses basePath: '/workflowui', so its API routes are served at /workflowui/api/setup, not /api/setup. The global setup was calling the wrong path, resulting in a 404 and aborting the entire E2E test suite. https://claude.ai/code/session_019xbfXDfsSMKjWoH6BkaPx6
57 lines
2.4 KiB
TypeScript
57 lines
2.4 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 ────────────────────────────────────────────────────
|
|
// workflowui uses basePath: '/workflowui', so the setup route is at /workflowui/api/setup
|
|
const setupUrl = process.env.PLAYWRIGHT_BASE_URL
|
|
? new URL('/workflowui/api/setup', process.env.PLAYWRIGHT_BASE_URL.replace(/\/workflowui\/?$/, '')).href
|
|
: 'http://localhost:3000/workflowui/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
|