Wisdom wokeW
Convex Community6mo ago
3 replies
Wisdom woke

Environment Variables Not Loading During Testing in Convex Application

I'm currently working on adding automated tests to my Convex application. While everything functions correctly in the production environment, I'm encountering an issue during testing: environment variables are not being loaded as expected.

My backend functions rely on environment variables (e.g., API keys, secrets, config values), and these are accessible and work fine when deployed. However, when I run tests using tools like convex-test and Vitest, it seems that the test environment doesn't automatically load or recognize the .env variables.

This is blocking me from properly testing critical parts of the application, especially those dependent on third-party services or configuration.

What I need:

A proper way to load environment variables during testing in a Convex application.

Preferably a solution that works within the Convex runtime context (not the Node.js runtime), since using Node to inject process.env breaks the Convex-specific environment expectations.

Any guidance or best practices for setting up environment-aware tests with Convex would be greatly appreciated.
Was this page helpful?