From f5e35d56a5fad50584dd3608b08817e8b62b2e3b Mon Sep 17 00:00:00 2001 From: Alanoll Date: Fri, 12 Dec 2025 22:56:16 -0600 Subject: [PATCH 1/2] feat: add the ability to define debug env variables --- README.md | 1 + package.json | 9 +++++++++ packages/extension/src/config.ts | 1 + packages/extension/src/debug.ts | 2 ++ samples/basic-v4/test/env.test.ts | 11 +++++++++-- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c93bbab..27b3c77f 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ These options are resolved relative to the [workspace file](https://code.visuals - `vitest.vitestPackagePath`: The path to a `package.json` file of a Vitest executable (it's usually inside `node_modules`) in case the extension cannot find it. It will be used to resolve Vitest API paths. This should be used as a last resort fix. - `vitest.nodeEnv`: Environment passed to the runner process in addition to `process.env` +- `vitest.debugNodeEnv`: Environment passed to the runner process in addition to `process.env` and `vitest.nodeEnv` when debugging tests - `vitest.debugExclude`: Excludes files matching specified glob patterns from debugging. Default: `["/**"]` - `vitest.debugOutFiles`: If source maps are enabled, these glob patterns specify the generated JavaScript files. If a pattern starts with `!` the files are excluded. If not specified, the generated code is expected in the same directory as its source. Default: `["${workspaceFolder}/**/*.(m|c|)js", "!**/node_modules/**"]` diff --git a/package.json b/package.json index ac00fae7..e60e7535 100644 --- a/package.json +++ b/package.json @@ -207,6 +207,15 @@ "type": "array", "scope": "resource" }, + "vitest.debugNodeEnv": { + "markdownDescription": "The env passed to runner process in addition to `process.env` and `vitest.nodeEnv` when debugging tests", + "type": [ + "object", + "null" + ], + "default": null, + "scope": "window" + }, "vitest.nodeEnv": { "markdownDescription": "The env passed to runner process in addition to `process.env`", "type": [ diff --git a/packages/extension/src/config.ts b/packages/extension/src/config.ts index b04944dc..0a4e9aed 100644 --- a/packages/extension/src/config.ts +++ b/packages/extension/src/config.ts @@ -75,6 +75,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) { return { env: get>('nodeEnv', null), + debugEnv: get>('debugNodeEnv', null), debugExclude: get('debugExclude'), debugOutFiles, filesWatcherInclude, diff --git a/packages/extension/src/debug.ts b/packages/extension/src/debug.ts index 2d2809f4..7ceddd82 100644 --- a/packages/extension/src/debug.ts +++ b/packages/extension/src/debug.ts @@ -43,6 +43,7 @@ export async function debugTests( const { runtimeArgs, runtimeExecutable } = await getRuntimeOptions(pkg) const env = config.env || {} + const debugEnv = config.debugEnv || {} const logLevel = config.logLevel log.info('[DEBUG]', 'Starting debugging session', runtimeExecutable, ...(runtimeArgs || [])) @@ -84,6 +85,7 @@ export async function debugTests( env: { ...process.env, ...env, + ...debugEnv, VITEST_VSCODE_LOG: env.VITEST_VSCODE_LOG ?? process.env.VITEST_VSCODE_LOG ?? logLevel, VITEST_VSCODE: 'true', VITEST_WS_ADDRESS: wsAddress, diff --git a/samples/basic-v4/test/env.test.ts b/samples/basic-v4/test/env.test.ts index 07b88808..64f168f6 100644 --- a/samples/basic-v4/test/env.test.ts +++ b/samples/basic-v4/test/env.test.ts @@ -1,9 +1,16 @@ -import { test, expect } from "vitest"; +import { expect, test } from "vitest"; test('process.env', () => { expect(process.env.TEST).toBe('true'); expect(process.env.VITEST).toBe('true'); expect(process.env.NODE_ENV).toBe('test'); expect(process.env.VITEST_VSCODE).toBe('true'); - expect(process.env.TEST_CUSTOM_ENV).toBe('hello'); + + if(process.env.TEST_CUSTOM_ENV_2 === undefined) { + expect(process.env.TEST_CUSTOM_ENV).toBe('hello'); + } + else { + expect(process.env.TEST_CUSTOM_ENV).toBe('hello new'); + expect(process.env.TEST_CUSTOM_ENV_2).toBe('world'); + } }); From b2caeb68295a2095759c1f5581b63ad055abc061 Mon Sep 17 00:00:00 2001 From: Alanoll Date: Sat, 13 Dec 2025 12:39:18 -0600 Subject: [PATCH 2/2] fix: missing updated settings.json for test --- samples/basic-v4/.vscode/settings.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/basic-v4/.vscode/settings.json b/samples/basic-v4/.vscode/settings.json index 0842d6a8..4d78eaed 100644 --- a/samples/basic-v4/.vscode/settings.json +++ b/samples/basic-v4/.vscode/settings.json @@ -5,5 +5,9 @@ "vitest.experimentalStaticAstCollect": true, "[typescript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" + }, + "vitest.debugNodeEnv": { + "TEST_CUSTOM_ENV": "hello new", + "TEST_CUSTOM_ENV_2": "world" } }