fix(db): load repo-root .env in the vitest config#44
Open
rmartin93 wants to merge 1 commit into
Open
Conversation
The integration suite read DB config straight from process.env (via createDb), but nothing loaded the repo-root .env for the vitest process — only migrate.ts and test-connection.ts did. So `pnpm db:test` (test-connection) worked while `pnpm test` (vitest) failed with "No DB config: set DATABASE_URL", even though the global-setup migrations applied (the migrate child loads .env itself). Load the root .env at the top of vitest.config.ts so DATABASE_URL / PG_* reach both globalSetup and the test workers. dotenv does not override vars already set, so an inline `DATABASE_URL=… pnpm test` still wins. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
pnpm db:testworked butpnpm testfailed with "No DB config: set DATABASE_URL" — the vitest integration suite never loaded the repo-root.env.migrate.tsandtest-connection.tseach calldotenvConfig({ path: root .env });vitest.config.tsdid not. So the suite only sawDATABASE_URLwhen it was set inline in the shell. Confusingly, global setup's migrations still applied (the migrate child process loads.envitself), then the test workers'createDb()threw because the vitest process had noDATABASE_URL/PG_*.Fix
Load the repo-root
.envat the top ofvitest.config.ts(evaluated in the main process before globalSetup runs and before workers fork, so both inherit it).dotenvdoesn't override already-set variables, so an inlineDATABASE_URL=… pnpm teststill wins.Verification
DB suite not run here, but the env load was verified directly: a key from the root
.envis absent from the shell and present after the config's dotenv load resolves the root.env.Same issue exists in the IIS
app-starter-iisrepo and is fixed there in a parallel PR.🤖 Generated with Claude Code