feat: #287 - Fix App.test.tsx environment variable loading - #374
Merged
ALLEN-AYODEJI merged 2 commits intoAug 30, 2026
Merged
Conversation
…oading Configure vitest to properly load test-specific environment variables from .env.test: - Import loadEnv from vite in vite.config.ts - Configure vitest.env to use variables from .env.test with fallbacks - Mock window.matchMedia in test setup for jsdom compatibility - Install msw as dev dependency for Mock Service Worker support This fixes the issue where App.test.tsx would crash on missing VITE_CONTRACT_ID, VITE_RPC_URL, and VITE_NETWORK_PASSPHRASE environment variables during test runs. Tests now load these variables from .env.test in test mode, ensuring consistent behavior without relying on developer-specific .env files. Fixes: Trellis-Ecosystem#287
|
@Able-faz-system Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Fix App.test.tsx Crashing on Missing Environment Variables
Overview
This PR resolves the issue where
App.test.tsxcrashes due to missing environment variables (CONTRACT_ID,RPC_URL,NETWORK_PASSPHRASE) that arevalidated at the module level in
config.ts. The solution ensures tests run consistently across all environments, including CI/CD pipelines, withoutrelying on developer-specific
.envfiles.Problem Statement
config.tsmodule validates critical Stellar/Soroban configuration at the module levelSolution Implemented
1. Vitest Configuration Enhancement (
frontend/vite.config.ts)2. Test Setup Improvements (
frontend/src/test/setup.ts)3. Dependency Addition (
frontend/package.json)Key Benefits
✅ Deterministic Tests: Tests now run consistently regardless of local environment configuration
✅ CI/CD Ready: No additional setup required for continuous integration pipelines
✅ Developer Friendly: Developers don't need to maintain .env files specifically for tests
✅ Better Error Messages: Environment variables are properly configured before tests run
✅ Backward Compatible: Existing test setup and configuration patterns remain unchanged
✅ Reduces Maintenance: Single source of truth for test environment variables
Files Changed
frontend/vite.config.ts- Enhanced Vite configuration with environment variable loading and vitest setupfrontend/src/test/setup.ts- Added window.matchMedia mock for jsdom compatibilityfrontend/package.json- Added msw dev dependencyfrontend/package-lock.json- Updated lock file with new dependencyTesting
Migration Notes
.env.testfile is respected by the new configuration.envoverrides still work as expected during developmentTechnical Details
loadEnv()function from Vite automatically loads.env,.env.local, and.env.{mode}filesVITE_prefix inloadEnv()ensures only environment variables intended for the browser are loadedtest.envoption injects these variables into the test environmentvi.fn()implementation for window.matchMedia provides all necessary MediaQueryList methodsRelated Issues
Closes #287