When running Vitest in continuous watch mode using the VS Code Vitest extension, the process unexpectedly exits with an error related to envalid. This issue does not occur when running Vitest directly via the command line (vitest dev). The error indicates that process.exit is called unexpectedly due to missing environment variables, even though they are correctly loaded using dotenv.config() in a setup file.
Run Vitest in watch mode using the VS Code extension:
Open the Testing sidebar in VS Code.
Click on the "Continuous Run" icon
Make a change to a test file like src/api/user/__tests__/userRouter.test.ts and save it
Output
================================
Missing environment variables:
FOO: undefined
================================
Exiting with error code 1
~~~~~~~~~~~~ AND ~~~~~~~~~~~~
Error: process.exit unexpectedly called with "1"
at process.exit (file:///path/to/node_modules/vitest/dist/vendor/execute.js:401:11)
at defaultReporter (/path/to/node_modules/envalid/src/reporter.ts:81:13)
at getSanitizedEnv (/path/to/node_modules/envalid/src/core.ts:104:3)
at Proxy.cleanEnv (/path/to/node_modules/envalid/src/envalid.ts:18:34)
at /path/to/project/src/common/utils/env-config.ts:7:20
at VitestExecutor.runModule (file:///path/to/node_modules/vite-node/dist/client.mjs:362:5)
at VitestExecutor.directRequest (file:///path/to/node_modules/vite-node/dist/client.mjs:346:5)
at VitestExecutor.cachedRequest (file:///path/to/node_modules/vite-node/dist/client.mjs:189:14)
at VitestExecutor.dependencyRequest (file:///path/to/node_modules/vite-node/dist/client.mjs:233:12)
at /path/to/project/src/api/area/area-repository.ts:2:31
Version
0.10.7
Validations
[X] Check that you are using the latest version of the extension
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Describe the bug
When running Vitest in continuous watch mode using the VS Code Vitest extension, the process unexpectedly exits with an error related to envalid. This issue does not occur when running Vitest directly via the command line (vitest dev). The error indicates that process.exit is called unexpectedly due to missing environment variables, even though they are correctly loaded using dotenv.config() in a setup file.
Reproduction
npm install
in the directoryFOO
environment variable to theenvConfig.ts
file:src/api/user/__tests__/userRouter.test.ts
and save itOutput
Version
0.10.7
Validations