Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
`["<node_internals>/**"]`
- `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/**"]`
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function getConfig(workspaceFolder?: WorkspaceFolder) {

return {
env: get<null | Record<string, string>>('nodeEnv', null),
debugEnv: get<null | Record<string, string>>('debugNodeEnv', null),
debugExclude: get<string[]>('debugExclude'),
debugOutFiles,
filesWatcherInclude,
Expand Down
2 changes: 2 additions & 0 deletions packages/extension/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || []))
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions samples/basic-v4/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 9 additions & 2 deletions samples/basic-v4/test/env.test.ts
Original file line number Diff line number Diff line change
@@ -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');
}
});