You can re-run failed tests or turn on the watch mode. When you launch a test session in this mode, GoLand monitors changes in your project source code. As soon as any changes are made to a test or to its subject, GoLand re-runs the affected test, you do not even have to re-start the run/debug configuration.
Before you start
In the embedded Terminal (Alt+F12) , type:
npm install --save-dev vitest
Run and debug tests
With GoLand, 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.
Run or debug a single test from the editor
Click or in the gutter and select Run <test_name> from the list.
You can also see whether a test has passed or failed right in the editor, thanks to the test status icons and in the gutter.
To debug a test, set a breakpoint inside it, click or in the gutter and select Debug <test_name> from the list.
Create a Vitest run configuration
Open the Run/Debug Configuration dialog ( on the main menu), click in the left-hand pane, and select Vitest from the list. The Run/Debug Configuration: Vitest dialog opens.
Specify the Node.js interpreter to use.
If you choose the Project alias, GoLand will automatically use the project default interpreter from the Node interpreter field . In most cases, GoLand detects the project default interpreter and fills in the field itself.
You can also choose another configured local interpreter or click and configure a new one.
Specify the location of the
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.
Specify the tests to run. This can be a specific test or suite, an entire test file, or a folder with test files.
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.
Configure rerunning tests automatically on changes in them or in the related source files. To do that, add the
--watchflag in the Vitest options field.
You can also add other Vitest options, see the Vitest official website for details.
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:
This mode requires that the register.js file, which is a part of the
coffeescriptpackage, is located inside your project.
Run tests via a run configuration
Select the Vitest run/debug configuration from the list on the main toolbar and click to the right of the list.
Monitor test execution and analyze test results in the Test Runner tab of the Run tool window, see Explore test results for details.
To debug tests, select the run/debug configuration and click .
You can rerun all the tests in the specified scope Alt+Shift+R or rerun only the tests that failed.
You can also launch tests in the --watch mode. In this mode, GoLand monitors saved changes to tests and related test subjects. As soon as a change is detected, GoLand reruns the affected test without stopping the current test session.
Rerun failed tests
In the Test Runner tab, click on the toolbar. GoLand will execute all the tests that failed during the previous session.
To rerun a specific failed test, selecton its context menu.
See Rerunning tests for details.
Rerun updated tests automatically (--watch mode)
Open a Vitest run/debug configuration or create a new one as described above.
In the Vitest options field, type
--watch. In the autogenerated All tests configuration, the
--watchoption is already specified.
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, GoLand detects them and reruns the affected tests.
In the example below, the test at line
29of vue.test.ts fails. With the
--watchoption, 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 or move the focus from GoLand.
GoLand also supports Vitest snapshot testing. When GoLand runs a test with the
toMatchSnapshot() method for the first time, a snapshot file is created and a icon appears in the gutter next to
toMatchSnapshot (). Click to open the generated snapshot.
Monitor code coverage
With GoLand, you can also monitor how much of your code is covered with Vitest tests. GoLand 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.
Run tests with coverage
Run a specific suite or a test with coverage from the editor: click or in the gutter and select Run <test_name> with Coverage from the list.
Create a Vitest run/debug configuration as described above. Select the Vitest run/debug configuration from the list on the main toolbar and click to the right of the list.
Monitor the code coverage in the Coverage 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: