Debug a single Vitest test in VS Code
Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.
Console logging in a failing test is slow. A launch configuration starts Vitest under the debugger, on the file you have open.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug current Vitest file",
"autoAttachPort": 0,
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}Open the test file, set a breakpoint in it or in the code it imports, and start the configuration. The run argument disables watch mode so the process exits when the tests end, and ${relativeFile} limits it to the open file. This setup follows the Vitest debugging guide.
To run a single test in the file, add the name filter to the arguments: "-t", "adds two numbers".
Vitest may run test files in worker threads, which the debugger cannot always follow. The Vitest guide recommends the options for a single worker when breakpoints are not hit.