Skip to content
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

Merged
merged 6 commits into from Feb 9, 2022
Merged

Conversation

sheremet-va
Copy link
Member

No description provided.

@netlify
Copy link

netlify bot commented Feb 9, 2022

✔️ 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 sheremet-va changed the title feat: allow change import.meta.env feat: allow changing import.meta.env Feb 9, 2022
@@ -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
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member

@antfu antfu left a 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

@antfu antfu merged commit 5f00788 into main Feb 9, 2022
@antfu antfu deleted the sheremet-va/allow-change-env branch February 9, 2022 16:52
chaii3 pushed a commit to chaii3/vitest that referenced this pull request May 13, 2022
Co-authored-by: junjianlin <junjianlin@xiaoman.cn>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants