Skip to content

Conversation

@danielroe
Copy link
Member

resolves #646

This PR now reads in .env.test when running vitest and allows the user to configure this with environmentOptions.nuxt.dotenv. (It's also possible to pass key/value pairs of environment rather than use .env.test, for example.)

This currently uses a clone of the Nitro logic from https://github.com/unjs/nitro/tree/main/src/runtime/utils.env.ts but it would be nice to avoid duplication by using a normalised nuxt.options.runtimeConfig in place (when nuxt/nuxt#24224 merges) which ideally would also involve exporting the utility from nitro (cc: @pi0).

Note: This also changes the public API of getVitestConfigFromNuxt which is currently only being used (as far as I can tell) by @wattanx in https://github.com/wattanx/nuxt-bridge-vitest - which is, anyway, a clone rather than direct usage.

@danielroe danielroe requested a review from antfu December 16, 2023 22:43
@danielroe danielroe changed the title feat!: read .env.test and allow overriding with nuxt.dotenv options feat!: read .env.test + allow overriding with nuxt.dotenv Dec 18, 2023
@danielroe danielroe merged commit 8cf01bd into main Dec 18, 2023
@danielroe danielroe deleted the feat/env branch December 18, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request vitest-environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handling .ENV files while testing

3 participants