- Unit tests: 682 passing
- Integration tests: ~70-80 passing, ~90 failing (varies run to run)
When all integration test files run together, many fail. However, when each test file is run individually, most tests pass. This suggests a test isolation issue related to:
- Database state sharing between tests
- Prisma client connection handling
- Cleanup timing between tests
The following integration test files exist:
posts-create.test.ts- POST /api/posts testsposts-update.test.ts- PUT /api/posts/[slug] testsposts-delete.test.ts- DELETE /api/posts/[slug] testsposts-related.test.ts- GET /api/posts/[slug]/related testsuserprofile.test.ts- UserProfile role tests
- FK constraint errors when creating users/profiles
- Assertion errors (wrong status codes returned)
- Tests that create posts directly work, but tests that call API routes fail
- Prisma client sharing: The global Prisma client may not be properly isolated between test files
- Cleanup timing: Database cleanup may be happening at wrong times
- Vitest worker issues: Tests may be running in same worker and interfering
- Sequential test execution: Run each test file in a separate process
- Fresh Prisma client per test: Create new client for each test instead of using global
- Improved cleanup: Ensure database cleanup happens correctly between tests
- Test environment isolation: Use vitest's --isolate option or similar
The unit tests (682) all pass. The integration test failures appear to be environmental/test infrastructure issues rather than bugs in the application code itself.