vitest-dev / vscode

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

vitest.commandLine is gone in 0.5? #306

Closed appcoders closed 5 months ago

appcoders commented 5 months ago

Describe the bug

In my package.json I defined

    "test": "DOTENV_CONFIG_PATH=.env.testing LOG_LEVEL=debug vitest",

and in vscode settings:

"vitest.commandLine": "yarn test --"

This works on vitest vscode 0.4.2 - on newer versions >0.5 the vitest.commandLine is gone and tests cannot be loaded at all because the environment variables are missing.

CleanShot 2024-03-19 at 11 00 27@2x

Reproduction

See above.

System Info

devcontainer on macOS 14.4:

System:
    OS: Linux 6.5 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (10) arm64 unknown
    Memory: 2.66 GB / 11.67 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 20.11.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.4 - /usr/local/bin/npm
    pnpm: 8.15.4 - /usr/local/share/npm-global/bin/pnpm
  IDEs:
    Nano: 5.4 - /bin/nano
    VSCode: 1.87.2 - /vscode/vscode-server/bin/linux-arm64/863d2581ecda6849923a2118d93a088b0745d9d6/bin/remote-cli/code
  npmPackages:
    @vitest/ui: ^1.4.0 => 1.4.0 
    vitest: ^1.4.0 => 1.4.0

Used Package Manager

yarn

Validations

sheremet-va commented 5 months ago

Yes, vitest.commandLine doesn't exists anymore as an option.

appcoders commented 5 months ago

@sheremet-va Thanks - so what is the migration path to inject environment variables?

sheremet-va commented 5 months ago

vitest.nodeEnv is still supported

appcoders commented 5 months ago

@sheremet-va Besides the fact, it would be cumbersome to manage environment variables in two different files, it does not work:

CleanShot 2024-03-19 at 11 00 23@2x

sheremet-va commented 5 months ago

it would be cumbersome to manage environment variables in two different files

The extension doesn't use Vitest CLI, so it is not possible to define a command line. If you have an environment-specific env, the recommended way is to define a .env.{name} file: https://vitejs.dev/guide/env-and-mode.html#env-files

It is picked up automatically.

If your test environment is different, you can have a .env.test file:

VITE_DOLPHIN_URL=url

it does not work

I cannot help you without a reproduction. vitest.nodeEnv works on my side:

https://github.com/vitest-dev/vscode/blob/99f2faf8a84becd42f3fada816ad23ef44a29bd1/samples/basic/test/env.test.ts#L8

mwood23 commented 5 months ago

I use a custom bash script to configure my test environment. Using a command line option would be very valuable to me. It's normal for integration test suites to require advanced configured to run tests. Thanks for the repo, just putting in my two cents!

sheremet-va commented 5 months ago

It's normal for integration test suites to require advanced configured to run tests.

Could you move it to globalSetup? If not, would an option to just run something before tests be enough?

  1. Run external code
  2. Start Vitest watcher
  3. Run teardown when vscode is closed (NOT after each test run)
mwood23 commented 5 months ago

Maybe if I had a before tests thing to set environmental variables. My API integration test suite is pretty complicated to setup so the bash script is definitely preferable compared to spawning child process and doing that sorta stuff in global setup.