vitest-dev / vscode

VS Code extension for Vitest
https://vitest.dev/vscode
MIT License
765 stars 87 forks source link

Support Different Modes #511

Open Eraph opened 1 month ago

Eraph commented 1 month ago

Clear and concise description of the problem

I have joined a project where the Mode expected for running Vitest is vitest, for example, this NPM script from package.json:

vitest * --mode vitest

In this case, Vitest will look for the environment variable file .env.vitest. I would prefer not to have to rename this file as its use is already well established.

I can see that process.env.MODE is present and set to test, but overriding it in settings has no effect; perhaps it is being set after reading settings?

"vitest.nodeEnv": {
  "MODE": "vitest"
}

I can confirm that changing the filename to .env.test does allow it to be loaded.

Please provide a means to specify the mode used by the Vitest extension.

Suggested solution

Support a setting like the following:

"vitest.mode": "vitest"

Apply this value to the environment variable MODE, or continue to use the value test if not set.

Alternative

No response

Additional context

No response

Validations

sheremet-va commented 1 month ago

You can assign a NODE_ENV env in vitest.nodeEnv or define the mode property in your config.

Eraph commented 4 weeks ago

Thanks for the response, @sheremet-va. Unfortunately as I mentioned in the original post, I already tried to set MODE in vitest.nodeEnv, it looks like it is being ignored by the extension.

Which config are you referring to with regards to defining the mode property?

sheremet-va commented 3 weeks ago

Is there any reason why you won't just set mode in the config?

export default defineConfig({
  mode: 'vitest',
})
Eraph commented 3 weeks ago

Yeah, we're passing in the mode like this:

export default defineConfig(({ mode }) => {
  // Load env file based on `mode` in the current working directory.
  const env = loadEnv(mode, process.cwd());

So test could be a valid value, I would prefer not to overwrite it here.