# Vitest

> **TL;DR**
> Available only in IntelliJ IDEA with the Ultimate subscription: [download](https://www.jetbrains.com.cn/en-us/idea/download/) to try or [explore the features](https://www.jetbrains.com.cn/en-us/products/compare/?product=idea&product=idea-ult).
>
>
>
>
>
> Required plugins:
>
>
>
> `JavaScript and TypeScript`, `Vite` -    the plugins are bundled with IntelliJ IDEA and enabled by default.

IntelliJ IDEA integrates with [Vitest](https://vitest.dev/), a [Vite](https://vitejs.dev/)-native unit test framework. You can run, debug, do snapshot testing, and measure test coverage both from the editor and via a run/debug configuration.

You can re-run failed tests or turn on the watch mode. When you launch a test session in this mode, IntelliJ IDEA monitors changes in your project source code. As soon as any changes are made to a test or to its subject, IntelliJ IDEA re-runs the affected test, you do not even have to re-start the run/debug configuration.

## Before you start

Procedure:

1. Download and install [Node.js](http://nodejs.org/#download).

2. Make sure the JavaScript and TypeScript and Vite required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to [Managing plugins](managing-plugins.html).

## Install Vitest

Procedure:

* In your command-line shell or in the embedded Terminal (`Alt+F12` (Windows), `⌥ F12` (macOS), `⌥ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ T` (macOS System Shortcuts), `Alt+F12` (XWin), `Alt+F12` (GNOME), `Alt+F12` (KDE), `Alt+F12` (Emacs), `Alt+F12` (Sublime Text), `⌥ F12` (Sublime Text (macOS)), `Alt+F12` (NetBeans), `Ctrl+Alt+1` (Visual Studio), `⌘ ⌃ 1` (Visual Studio (macOS)), `Alt+F12` (Eclipse), `⌥ F12` (Eclipse (macOS))) , type:

`npm install --save-dev vitest`

Learn more from [Getting Started](https://vitest.dev/guide/) and [Configuring Vitest](https://vitest.dev/guide/#configuring-vitest) on the Vitest official website.

## Run and debug tests

With IntelliJ IDEA, you can quickly run or debug a single Vitest test right from the editor or create a run/debug configuration to run or debug some or all of your tests.

For more information about creating Vitest tests for JavaScript and TypeScript code, refer to [Vitest features](https://vitest.dev/guide/features.html) on the Vitest official website.

Procedure: Run or debug a single test from the editor

* Click ![the Run icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.run.svg) or ![the Rerun icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Run <test_name> from the list.

![Run one Vitest test from the editor](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_run_test.png)

View the results of running your tests in the Run tool window. For failed tests, information on where an error occurred and what caused it is displayed.

![Details error information](https://resources.jetbrains.com.cn/help/img/idea/2026.2/vitest_run_single_test_error_info.png)

You can also see whether a test has passed or failed right in the editor, thanks to the test status  icons ![Test passed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.green2.svg) and ![Test failed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.red2.svg) in the gutter.

![Gutter icons for tests](https://resources.jetbrains.com.cn/help/img/idea/2026.2/vitest_run_single_test_gutter_icons.png)

* To debug a test, [set a breakpoint](using-breakpoints.html) inside it, click ![the Run icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.run.svg) or ![the Rerun icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Debug <test_name> from the list.

![Debug one Vitest test from the editor](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_debug_test.png)

In the Debug tool window, [examine the suspended test](examining-suspended-program.html) and [step through it](stepping-through-the-program.html).

![A Vitest debugging session](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_debug_tool_window.png)

Procedure: Create a Vitest run configuration

1. Open the [Run/Debug Configuration](run-debug-configurations-dialog.html) dialog (`Run | Edit Configurations` in the main menu), click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg) in the left-hand pane, and select Vitest from the list.  The Run/Debug Configuration: Vitest dialog opens.

> **Tip:**
> Alternatively,   select a test file in the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)))  and select Create <filename> from the context menu.

2. Specify the Node.js runtime to use.

If you choose the Project alias, IntelliJ IDEA will automatically use the project default interpreter from the Node runtime field on the [JavaScript Runtime](javascript-runtime.html) page . In most cases, IntelliJ IDEA detects the project default runtime and fills in the field itself.

You can also choose another configured local or remote interpreter or click ![the Browse button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and configure a new one.

Optionally specify the [Node.js-specific option parameters](run-debug-configuration-node-js.html#node_parameters) and the [environment variables](https://www.w3schools.com/nodejs/nodejs_environment.asp) to be passed to Node.js.

The definitions of variables are displayed in the Environment variables field with semicolons (`;`) as separators, for example:

* `NODE_PATH` A list of additional directories to search when resolving modules. To separate directories in a list, use colon (`:`) on macOS or Linux, use semicolon (`;`) on Windows.

* `NODE_MODULE_CONTEXTS` Set to 1 to load modules in their own global contexts.

* `NODE_DISABLE_COLORS` Set to 1 to disable colors in the REPL.

![Environment variables](https://resources.jetbrains.com.cn/help/img/idea/2026.2/nodeEnvironmentVariables.png)

Alternatively, click Browse ![the Edit environment variables](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.inline.variables.svg) to the right of the field and configure a list of variables in the Environment Variables dialog, that opens:

* Use ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg), ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.remove.svg), ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.copy.svg) and ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.paste.svg) buttons to manage the list of custom variables.

* The dialog also shows a list of available system environment variables. Clear the Include system environment variables checkbox if you don't want to use the system environment variables for the current configuration.

* Click OK, when ready.

3. Specify the location of the `vitest` package.

4. Specify the  working directory of the application. By default, the Working directory field shows the project root folder. To change this predefined setting, specify the path to the desired folder.

5. Specify the tests to run. This can be a specific test or suite, an entire test file, or a folder with test files.

6. By default, `vite.config.ts` is used. If `vite.config.ts` is missing, or you want to use a custom configuration, specify the `vitest.config.ts` to use. Learn more from the [Vitest official website](https://vitest.dev/guide/#configuring-vitest).

7. Optionally:

Configure rerunning tests automatically on changes in them or in the related source files. To do that, add the `--watch` flag in the Vitest options field.

You can also add other Vitest options. For more information, refer to the [Vitest official website](https://vitest.dev/guide/cli.html#options).

8. Optionally:

In the Node options field, type the Node.js-specific command-line options to be passed to the Node.js executable file. The acceptable options are:

* Use `--require coffeescript/register` to have CoffeeScript files compiled into JavaScript on the fly during run. This mode requires that the `register.js` file, which is a part of the `coffeescript` package, is located inside your project. Therefore, make sure you have the `coffeescript` package installed locally as described in [Install the CoffeeScript compiler](coffeescript.html#ws_coffee_installation).

* Use `--inspect` or `--inspect-brk` parameter for [Chrome Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) support.

Procedure: Run tests via a run configuration

1. Select the Vitest run/debug configuration from the list of configurations and click ![the Run icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.run.run.svg) in the list or on the toolbar.

2. Monitor test execution and analyze test results in the Test Runner tab of the Run tool window. For more information, refer to [Explore test results](viewing-and-exploring-test-results.html).

To debug tests, [set breakpoints](using-breakpoints.html) where necessary, select the run/debug  configuration, and click ![the Debug button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.run.debug.svg).

![Vitest: test results](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_test_results.png)

## Rerun tests

You can rerun all the tests in the specified scope `Alt+Shift+R` (Windows), `⌘ ⌃ R` (macOS), `⌘ ⌃ R` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ R` (macOS System Shortcuts), `Alt+Shift+R` (XWin), `Alt+Shift+R` (GNOME), `Alt+Shift+R` (KDE), `Alt+Shift+R` (Emacs), `Alt+Shift+R` (Sublime Text), `⌘ ⌃ R` (Sublime Text (macOS)), `Alt+Shift+R` (NetBeans), `Alt+Shift+R` (Visual Studio), `Alt+Shift+R` (Visual Studio (macOS)), `Alt+Shift+G` (Eclipse), `⌘ ⌃ R` (Eclipse (macOS)) or rerun only the tests that failed.

You can also launch tests in the [--watch mode](https://vitest.dev/guide/features.html#watch-mode). In this mode, IntelliJ IDEA monitors saved changes to tests and related test subjects. As soon as a change is detected, IntelliJ IDEA reruns the affected test without stopping the current test session.

> **Note:**
> IntelliJ IDEA only detects updated that are saved manually, with `Ctrl+S` (Windows), `⌘ S` (macOS), `⌘ S` (IntelliJ IDEA Classic (macOS)), `⌘ S` (macOS System Shortcuts), `Ctrl+S` (XWin), `Ctrl+S` (GNOME), `Ctrl+S` (KDE), `Ctrl+X, Ctrl+S` (Emacs), `Ctrl+S` (Sublime Text), `⌘ S` (Sublime Text (macOS)), `Ctrl+S` (NetBeans), `Ctrl+Shift+S` (Visual Studio), `⌘ ⇧ S` (Visual Studio (macOS)), `Ctrl+S` (Eclipse), `⌘ S` (Eclipse (macOS)), or automatically, for example, on changing the focus. Learn more from [Configure autosave
> behavior](saving-and-reverting-changes.html#configure-autosave).

Procedure: Rerun failed tests

* Click ![the Rerun Failed Tests icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.restartFailedTests.svg) on the test results toolbar. IntelliJ IDEA will execute all the tests that failed during the previous session.

![Vitest: Rerunning all failed tests](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_rerun_failed_test.png)

* To rerun a specific failed test, select `Run <test name>` on its context menu.

Procedure: Rerun updated tests automatically (--watch mode)

1. Open a Vitest run/debug configuration or create a new one [as described above](#createRunConfigVitest).

2. In the Vitest options field, type `--watch`. In the autogenerated All tests configuration, the `--watch` option is already specified.

3. Launch the run/debug configuration. If some tests fail, you can update them or related test subjects without stopping the test session. As soon as your changes are saved, IntelliJ IDEA detects them and reruns the affected tests.

In the example below, the test at line `29` of `vue.test.ts` fails. With the `--watch` option, the test is rerun after you replace `'4 x 4 = 18'` with `'4 x 4 = 16'` in `vue.test.ts` an save the changes with `Ctrl+S` (Windows), `⌘ S` (macOS), `⌘ S` (IntelliJ IDEA Classic (macOS)), `⌘ S` (macOS System Shortcuts), `Ctrl+S` (XWin), `Ctrl+S` (GNOME), `Ctrl+S` (KDE), `Ctrl+X, Ctrl+S` (Emacs), `Ctrl+S` (Sublime Text), `⌘ S` (Sublime Text (macOS)), `Ctrl+S` (NetBeans), `Ctrl+Shift+S` (Visual Studio), `⌘ ⇧ S` (Visual Studio (macOS)), `Ctrl+S` (Eclipse), `⌘ S` (Eclipse (macOS)) or move the focus from IntelliJ IDEA.

![Rerun updated test in the --watch mode](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_watch_mode.animated.gif)

## Snapshot testing

IntelliJ IDEA also supports [Vitest snapshot
testing](https://vitest.dev/guide/snapshot.html#snapshot). When IntelliJ IDEA runs a test with the `toMatchSnapshot()` method for the first time, a snapshot file is created and a ![Snapshot](https://resources.jetbrains.com.cn/help/img/idea/2026.2/javascript-impl.icons.jest.snapshotGutter.svg) icon appears in the gutter next to `toMatchSnapshot ()`. Click ![the Snapshot icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/javascript-impl.icons.jest.snapshotGutter.svg) to open the generated snapshot.

![Snapshot](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_snapshot.png)

## Monitor code coverage

With IntelliJ IDEA,    you can also monitor how much of your code is [covered with Vitest tests](https://vitest.dev/guide/coverage.html#coverage). IntelliJ IDEA displays this statistics in a dedicated Coverage tool window and marks covered and uncovered lines visually in the editor and in the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) .

![Vitest Coverage report](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_coverage_report.png)

Procedure: Enable code coverage for Vitest

Install [@vitest/coverage-v8](https://www.npmjs.com/package/@vitest/coverage-v8) or [istanbul](https://istanbul.js.org/). To do that, open the built-in Terminal `Alt+F12` (Windows), `⌥ F12` (macOS), `⌥ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ T` (macOS System Shortcuts), `Alt+F12` (XWin), `Alt+F12` (GNOME), `Alt+F12` (KDE), `Alt+F12` (Emacs), `Alt+F12` (Sublime Text), `⌥ F12` (Sublime Text (macOS)), `Alt+F12` (NetBeans), `Ctrl+Alt+1` (Visual Studio), `⌘ ⌃ 1` (Visual Studio (macOS)), `Alt+F12` (Eclipse), `⌥ F12` (Eclipse (macOS)) and type one of the following:

* `npm install --save-dev @vitest/coverage-v8`

* `npm install --save-dev @vitest/coverage-istanbul`.

Learn more from [Coverage](https://vitest.dev/guide/coverage.html#coverage) on the Vitest official website.

Procedure: Run tests with coverage

1. Run a specific suite or a test with coverage from the editor: click ![the Run button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.run.run.svg) or ![the Rerun button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Run <test_name> with Coverage from the list.

![Run Vitest tests with coverage from the editor](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_vitest_run_with_coverage_editor.png)

Alternatively:

Create a Vitest run/debug configuration [as described above](#createRunConfigVitest). Select the Vitest run/debug configuration from the list on the main toolbar and click ![Run with Coverage icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.runWithCoverage.svg)  to the right of the list.

2. Monitor the code coverage in the [Coverage](code-coverage.html) tool window. The report shows how many files were covered with tests and the percentage of covered lines in them. From the report you can jump to the file and see what lines were covered – marked green – and what lines were not covered – marked red:

