fix: load .env file in vitest config and update integration test docs (#26828)
* docs: update integration test commands for Vitest 4.0 Vitest 4.0 no longer supports custom CLI flags like --integrationTestsOnly. Updated documentation to use the new VITEST_MODE=integration environment variable syntax instead. Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: load .env file in vitest config for integration tests Vitest 4.0 doesn't automatically load .env files into process.env. This caused integration tests to fail with ECONNREFUSED errors because DATABASE_URL was not available. Added loadEnv from Vite to load .env file at the start of vitest config. Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * chore: remove unnecessary comment Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * fix: only load .env vars if not already set Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -48,10 +48,10 @@ yarn vitest run path/to/file.test.ts
|
||||
yarn vitest run path/to/file.test.ts --testNamePattern="specific test name"
|
||||
|
||||
# Integration test specific file
|
||||
yarn test path/to/file.integration-test.ts -- --integrationTestsOnly
|
||||
VITEST_MODE=integration yarn test path/to/file.integration-test.ts
|
||||
|
||||
# Integration test specific file + specific test
|
||||
yarn test path/to/file.integration-test.ts --testNamePattern="specific test name" -- --integrationTestsOnly
|
||||
VITEST_MODE=integration yarn test path/to/file.integration-test.ts --testNamePattern="specific test name"
|
||||
|
||||
# E2E test specific file
|
||||
PLAYWRIGHT_HEADLESS=1 yarn e2e path/to/file.e2e.ts
|
||||
|
||||
+4
-4
@@ -34,9 +34,9 @@
|
||||
|
||||
### Integration Tests
|
||||
|
||||
- `yarn test -- --integrationTestsOnly` - Run integration tests (vitest)
|
||||
- `yarn test <filename> -- --integrationTestsOnly` - Run integration tests for specific file
|
||||
- `yarn test <filename> -t "<testName>" -- --integrationTestsOnly` - Run specific integration test by name for specific file
|
||||
- `VITEST_MODE=integration yarn test` - Run integration tests (vitest)
|
||||
- `VITEST_MODE=integration yarn test <filename>` - Run integration tests for specific file
|
||||
- `VITEST_MODE=integration yarn test <filename> -t "<testName>"` - Run specific integration test by name for specific file
|
||||
|
||||
|
||||
### End-to-End Tests
|
||||
@@ -73,7 +73,7 @@
|
||||
yarn vitest run packages/lib/some-file.test.ts
|
||||
|
||||
# Integration test specific file
|
||||
yarn test routing-form-response-denormalized.integration-test.ts -- --integrationTestsOnly
|
||||
VITEST_MODE=integration yarn test routing-form-response-denormalized.integration-test.ts
|
||||
|
||||
# E2E test specific file
|
||||
yarn e2e tests/booking-flow.e2e.ts
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import path from "node:path";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { loadEnv } from "vite";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
const env = loadEnv("", process.cwd(), "");
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (process.env[key] === undefined) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
const vitestMode = process.env.VITEST_MODE;
|
||||
// Support both new VITEST_MODE env var and legacy CLI flags for backwards compatibility
|
||||
// The CLI flags are passed through but Vitest 4.0 doesn't reject them when using yarn test
|
||||
|
||||
Reference in New Issue
Block a user