Files
metabuilder/e2e/global.setup.ts
rmac 01de695619 Set up database seeding architecture and E2E testing infrastructure
- Add CLAUDE.md: AI assistant instructions for MetaBuilder project architecture
- Add TESTING.md: Comprehensive E2E testing guide and troubleshooting

Core changes:
- Create Playwright global.setup.ts to seed database before E2E tests
- Add /api/setup endpoint to trigger database seeding via HTTP
- Implement seed-home-page.ts module loaded from ui_home package metadata
- Create ui_home/seed/metadata.json defining home page PageConfig seed data

Architecture established:
- Packages define seed data in seed/metadata.json
- Seed functions are idempotent (check before creating)
- Global setup calls /api/setup before running tests
- Database schema must be created via 'npm run db:push' before seeding

Test flow:
1. Playwright starts webServer (generates Prisma client, starts Next.js)
2. Global setup waits for server, calls POST /api/setup
3. Seeding creates default data from packages
4. E2E tests run against seeded database

This establishes proper separation of concerns:
- DBAL adapter for database access (not raw Prisma)
- Package-driven seed data (not hardcoded in code)
- HTTP endpoint for explicit database initialization
- Idempotent seeds (safe to rerun)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-01-14 18:15:46 +00:00

27 lines
669 B
TypeScript

/**
* Playwright global setup
* Runs before all tests to seed the database with package data
*/
async function globalSetup() {
// Wait a bit for the server to start
await new Promise(resolve => setTimeout(resolve, 2000))
try {
// Seed database with package data
const response = await fetch('http://localhost:3000/api/setup', {
method: 'POST',
})
if (!response.ok) {
console.error('Failed to seed database:', response.status, response.statusText)
} else {
console.log('Database seeded successfully')
}
} catch (error) {
console.error('Failed to call setup endpoint:', error)
}
}
export default globalSetup