Skip to content

support passing through arguments #6390

Closed as not planned
Closed as not planned

Description

@sombriks

Clear and concise description of the problem

i need this command to be valid:

vitest run --coverage -- --env-file=.env --env-file=.env.test

Suggested solution

add support for it

Alternative

No response

Additional context

No response

Validations

Activity

  1. sheremet-va commented on Aug 24, 2024

    @sheremet-va
    Member

    Vitest doesn't support Node.js arguments and we don't have plans to support them. If you need to use .env file, you can use --mode flag that will use your local .env.{mode} by default. Note that envs need to start with VITE_ by default, but it can be configured with envPrefix.

  2. sombriks commented on Aug 24, 2024

    @sombriks
    Author

    Vitest doesn't support Node.js arguments and we don't have plans to support them. If you need to use .env file, you can use --mode flag that will use your local .env.{mode} by default. Note that envs need to start with VITE_ by default, but it can be configured with envPrefix.

    i had no idea it was intentional, i will try an alternative approach, thanks.

  3. sombriks commented on Aug 24, 2024

    @sombriks
    Author

    My usecase is vitest on backend, testing fastiify running under tsx.

    So the VITE_ prefix could be troublesome, since i only need vitest, not vite.

    this config is my current workaround:

    import {defineConfig} from "vite";
    import {config} from 'dotenv'
    
    export default defineConfig({
        test: {
            env: {
                "NODE_ENV": "test",
                ...config({path: '.env'}).parsed,
                ...config({path: '.env.test'}).parsed,
            }
        },
    })
  4. AriPerkkio commented on Aug 25, 2024

    @AriPerkkio
    Member

    You can also pass NodeJS exec arguments to test runner threads/processes. Note that these won't be available in main thread, e.g. reporters or global setup.

    import { defineConfig } from "vitest/config";
    
    export default defineConfig({
      test: {
        poolOptions: {
          forks: { execArgv: ["--env-file=.env.custom"] },
    
          // or threads if that pool is used
          threads: { execArgv: ["--env-file=.env.custom"] },
        },
      },
    });

    https://vitest.dev/config/#pooloptions-forks-execargv

  5. locked and limited conversation to collaborators on Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions