vitest
vitest copied to clipboard
Vite Environment Variables are not the correct type
Describe the bug
Vite exposes several environment variables, 3 of which should be boolean import.meta.env.[DEV | PROD | SSR]. These variables are evaluating as strings while running tests.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-maqvfr?file=test/basic.test.ts
System Info
All systems
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Yes, it is mentioned in the documentation: https://vitest.dev/api/vi.html#vi-stubenv
Vitest transforms all import.meta.env into process.env, which is always a string.