Replace DATABASE_URL_TEST with testcontainers for isolated E2E tests#149
Draft
Replace DATABASE_URL_TEST with testcontainers for isolated E2E tests#149
Conversation
Replace DATABASE_URL_TEST with testcontainers for e2e tests, following the same pattern used in vitest integration tests. Changes: - Add e2e/testcontainer.ts with utilities for PostgreSQL container - Add e2e/global-teardown.ts to stop container after tests - Add e2e/start-server.ts to read container URL and start preview server - Update global-setup.ts to start testcontainer and run migrations - Update playwright.config.ts to use globalTeardown and new server script - Update all test files to use getDatabaseUrl() from testcontainer utils - Update fixtures/db.ts to read URL from container state - Remove DATABASE_URL_TEST from CI workflow (no longer needed) - Update PLAYWRIGHT.md documentation This makes e2e tests fully self-contained and eliminates the need for a pre-existing PostgreSQL server. https://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6
Increase globalTimeout in CI to allow testcontainers more time to start the PostgreSQL container, run migrations, and seed the database. https://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6
Add try-catch wrapper and initial logging to help diagnose why global-setup might be failing in CI without creating the state file. https://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6
Add console.log at module load time to verify if the globalSetup module is being loaded by Playwright at all. https://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6
Instead of failing immediately when state file doesn't exist, the webServer now polls for the file with a 2-minute timeout. This will help diagnose whether globalSetup is running at all or just slow. https://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the static
DATABASE_URL_TESTenvironment variable with a dynamic PostgreSQL testcontainer approach, providing completely isolated and reproducible test databases for each test run.Key Changes
Testcontainer Integration: Added
e2e/testcontainer.tsmodule that manages PostgreSQL container lifecycle using@testcontainers/postgresqlcreateTestDatabase(): Starts a container and runs migrationsgetDatabaseUrl(): Retrieves connection URI from state filestopTestDatabase(): Cleans up container and connectionsGlobal Setup/Teardown: Refactored test lifecycle management
global-setup.ts: Now starts the container, runs migrations, seeds data, and saves container stateglobal-teardown.ts: New file that stops the container and cleans up stateServer Startup: Created
e2e/start-server.tsscript that reads database URL from testcontainer state and starts the preview server with proper environment variablesTest Files: Updated all E2E test files to use
getDatabaseUrl()instead ofprocess.env.DATABASE_URL_TESTbulk-actions.test.tscsv-import.test.tsemails.test.tspasskeys.test.tsuser-merge.test.tsfixtures/db.tsConfiguration: Updated
playwright.config.tsto use the new server startup script and added global teardown configurationCI/CD: Removed
DATABASE_URL_TESTfrom GitHub Actions workflow since it's now dynamically createdGitignore: Added
e2e/.testcontainer-state.jsonto track container state during test runsImplementation Details
e2e/.testcontainer-state.jsonduring setup and read by fixtures and the server startup scriptmigrate()functiondocker stopdirectly since testcontainers doesn't provide a direct stop method after the process endshttps://claude.ai/code/session_01TrZ8pg34hfW2ndRK4oXpn6