Skip to content
jshacks.dev
Debugging

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.

1 min read
Summarize in AI

Console logging in a failing test is slow. A launch configuration starts Vitest under the debugger, on the file you have open.

.vscode/launch.jsonJSON
{
  "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.

Also inTesting
Share

More snippets

Testing

Group tests with describe in node test

Group related tests with describe and it from node:test, nest suites, and run setup with beforeEach, all without installing a framework.

1 min read
Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.