New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow changing import.meta.env #714
Conversation
✔️ Deploy Preview for vitest-dev ready! 🔨 Explore the source changes: 859e4cd 🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/6203c5acbafda700079e9e6c 😎 Browse the preview: https://deploy-preview-714--vitest-dev.netlify.app |
…sheremet-va/allow-change-env
@@ -47,6 +48,23 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest()) | |||
// viteConfig.test is final now, merge it for real | |||
options = deepMerge(options, viteConfig.test as any || {}) | |||
options.api = resolveApiConfig(options) | |||
|
|||
process.env.BASE_URL ??= viteConfig.base | |||
process.env.MODE ??= viteConfig.mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure about the MODE
convention here, it feels too general to me. Do we have any references for other tools using it? or we better use VITEST_MODE
or VITE_MODE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what Vite uses on import.meta.env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these variables are default values on import.meta.env
that always exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we are allowing people to reassign them by making import.meta.env
= process.env
we can assign them to process.metaEnv
if you don't want to collaps with other tools, but I know this approach is wildly used now to support testing Vite in jest (using process.env
that is)
process.metaEnv
can even allow booleans
we can hide implementation on some helper like vi.mockEnv(env, value)
, but people may get confused when process.env
will stay the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have it and see if that works for everyone
Co-authored-by: junjianlin <junjianlin@xiaoman.cn> Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
No description provided.