How to load .env file into the test environment? #3989
Unanswered
datsenkoboos
asked this question in
Q&A
Replies: 1 comment
-
If anyone still stumbles into this problem, I have done the following: I'm using the I'm using the Vitest configuration import swc from "unplugin-swc";
import { defineConfig } from "vitest/config";
export default defineConfig({
// ...
test: {
// ...
setupFiles: ["./test/setup.ts"],
},
// ...
}); And in the import { loadEnvFile } from "node:process";
// We need to load the local .env file to access some variables needed when
// testing.
loadEnvFile(); I understand you could set the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to use variables from .env.public file in my test environment, so i've added
setupFiles: '.env.public'
to vitest.config.ts:.env.public and vite.config.ts are both in the root of my project:
Tests are failing with error:
ctrl + click on the url from the error successfully opens .env.public file
How can i fix the issue?
Beta Was this translation helpful? Give feedback.
All reactions