Skip to content
Vitest 1
Main Navigation GuideAPIConfigAdvanced
1.6.1
0.34.6

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

Guide

Why Vitest

Getting Started

Features

Workspace

CLI

Test Filtering

Reporters

Coverage

Snapshot

Mocking

Testing Types

Vitest UI

Browser Mode

In-source Testing

Test Context

Environment

Extending Matchers

IDE Integration

Debugging

Comparisons

Migration Guide

Common Errors

Improving Performance

API

Test API Reference

Mock Functions

Vi Utility

Expect

ExpectTypeOf

assert

assertType

Config

Config File

Config Reference

On this page

Debugging ​

TIP

When debugging tests you might want to use --test-timeout CLI argument to prevent tests from timing out when stopping at breakpoints.

VSCode ​

Quick way to debug tests in VSCode is via JavaScript Debug Terminal. Open a new JavaScript Debug Terminal and run npm run test or vitest directly. this works with any code ran in Node, so will work with most JS testing frameworks

image

You can also add a dedicated launch configuration to debug a test file in VSCode:

json
{
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Current Test File",
      "autoAttachChildProcesses": true,
      "skipFiles": ["<node_internals>/**", "**/node_modules/**"],
      "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
      "args": ["run", "${relativeFile}"],
      "smartStep": true,
      "console": "integratedTerminal"
    }
  ]
}

Then in the debug tab, ensure 'Debug Current Test File' is selected. You can then open the test file you want to debug and press F5 to start debugging.

IntelliJ IDEA ​

Create a 'Node.js' run configuration. Use the following settings to run all tests in debug mode:

SettingValue
Working directory/path/to/your-project-root
JavaScript file./node_modules/vitest/vitest.mjs
Application parametersrun --pool forks

Then run this configuration in debug mode. The IDE will stop at JS/TS breakpoints set in the editor.

Node Inspector, e.g. Chrome DevTools ​

Vitest also supports debugging tests without IDEs. However this requires that tests are not run parallel. Use one of the following commands to launch Vitest.

sh
# To run in a single worker
vitest --inspect-brk --pool threads --poolOptions.threads.singleThread

# To run in a single child process
vitest --inspect-brk --pool forks --poolOptions.forks.singleFork

If you are using Vitest 1.1 or higher, you can also just provide --no-file-parallelism flag:

sh
# If pool is unknown
vitest --inspect-brk --no-file-parallelism

Once Vitest starts it will stop execution and wait for you to open developer tools that can connect to Node.js inspector. You can use Chrome DevTools for this by opening chrome://inspect on browser.

In watch mode you can keep the debugger open during test re-runs by using the --poolOptions.threads.isolate false options.

Pager
Previous pageIDE Integration
Next pageComparisons

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team

https://v1.vitest.dev/guide/debugging

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team