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

Support Different Modes #511

Open
4 tasks done
Eraph opened this issue Oct 25, 2024 · 5 comments
Open
4 tasks done

Support Different Modes #511

Eraph opened this issue Oct 25, 2024 · 5 comments

Comments

@Eraph
Copy link

Eraph commented Oct 25, 2024

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
Copy link
Member

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

@Eraph
Copy link
Author

Eraph commented Oct 31, 2024

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
Copy link
Member

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

export default defineConfig({
  mode: 'vitest',
})

@Eraph
Copy link
Author

Eraph commented Nov 6, 2024

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.

@mglickVA
Copy link

I'm also facing this problem. I've tried both the nodeEnv approach and setting my vite.config.ts to set the mode. Neither seems to work. Also, it is not clear to me how the extension knows where the vite.config.ts file is located. Can someone who has this sorted out provide an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants