theeranitp
theeranitp

Reputation: 1235

Completely disable auto run of Jest test runner in Visual Studio Code editor

I have some sets of Jest test cases that run Puppeteer browser tests.

I have tried these test runners

To me, I like Jest Test Explorer the most but it always auto-start running test cases. As you can imagine, a lot of Chrome browser instances get launched when I open a project with VS Code.

I found some configurations but they cannot prevent auto-run test cases.

FYI, an example UI of Jest Test Explorer enter image description here

Jest (vscode-jest) is a good runner but I can't stop auto-run with these settings as well.

Therefore, right now Jest Runner (vscode-jest-runner) is the only runner that does not auto-start unit tests.

In addition, if you have any other test runners to suggest, please let me know.

Thank you so much.

Upvotes: 100

Views: 85172

Answers (13)

Tiavina MIchael
Tiavina MIchael

Reputation: 371

as of 2024

"jest.autoRun": "off",
"jest.autoRevealOutput": "off"

are deprecated, use instead:

"jest.runMode": "on-demand"

you can change the global settings.json or per project .vscode/settings.json

Upvotes: 5

Lucas Mgana
Lucas Mgana

Reputation: 101

"jest.autoRun": "off",
"jest.autoRevealOutput": "off",

These are deprecated add the line below

"jest.runMode": "on-demand",

Upvotes: 7

Dhanushka
Dhanushka

Reputation: 359

Just put this in settings.json (User)

"jest.runMode": "on-demand",

Upvotes: 27

laszlo-horvath
laszlo-horvath

Reputation: 2139

2024 update: jest.autoRun became deprecated, use "jest.runMode": "on-demand" instead.

Source

Upvotes: 23

Zingg
Zingg

Reputation: 11

Add this to settings.json:

"jest.autoRun": "off",
"jest.autoRevealOutput": "off",

Source: https://github.com/jest-community/vscode-jest/blob/master/README.md#settings

Upvotes: 0

Daniel Muñoz
Daniel Muñoz

Reputation: 1782

For orta.vscode-jest extension, I added the configuration below in settings.json. You can open settings.json by doing Command + Shift + P (Ctrl + Shift + P on Windows), typing settings JSON and selecting Preferences: Open User Settings (JSON).

"jest.autoRun": {
    "onStartup": []
}

Or you can simply add:

"jest.autoRun": {}

If you want to run all tests on startup, add all-tests to the onStartup array:

"jest.autoRun": {
    "onStartup": ["all-tests"]
}

Upvotes: 81

Ignacio Irurzun
Ignacio Irurzun

Reputation: 61

What it worked for me was:

File -> preferences -> settings. Then under the panel user (in workspace is as well but I am not sure if you need to modify it there as well), go to extensions -> jest.

There you will have a section jest: auto run and you will find a link "edit in settings.json" and modify what is there for this

"jest.autoRun": {
  "watch": false
}

Upvotes: 6

gmg13
gmg13

Reputation: 281

At the time of writing (Dec 22) the new way to do this (as per https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-trigger-the-test-run) is to have the following in the VS Code settings.json. Note I had previously tried the other answers but none worked.

  "jest.autoRun": { "watch": false }

Upvotes: 28

Nemeton
Nemeton

Reputation: 745

Go to vscode setting.json

You can either add

"jest.autoRun": "off"

or

"jest.autoRun": false

both are valid options. You can checkout the official recommended settings here.

https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-trigger-the-test-run

"jest.autoEnable": false

is deprecated.

Upvotes: 8

user17864108
user17864108

Reputation:

First open the jest extension settings.json in the vs code. In the json script add "jest.autoRun": "off" to disable test autorun. Below, I add other options as well.
Source: Documentation

  • fully manual there will be no automatic test run, users will trigger test run by either command or context-menu. Example: "jest.autoRun": "off"
  • automatically run tests when test file changed the extension will trigger test run for the given test file upon save. Example: "jest.autoRun": {"watch": false, "onSave": "test-file"}
  • automatically run tests when either test or source file changed: the extension will trigger test run for the given test or source file upon save. Example: "jest.autoRun": {"watch": false, "onSave": "test-src-file"}

Upvotes: 5

silex189
silex189

Reputation: 447

I just set this simple option into the VS Code's settings.json:

"jest.autoRun": "false"

Upvotes: 33

user1428619
user1428619

Reputation: 91

There's some great updated docs here

Migration rule from settings prior to v4:

if "jest.autoEnabled" = false => manual mode: "jest.autoRun": "off"

if "jest.runAllTestsFirst" = false => "jest.autoRun": {"watch": true }

if no customization of the 2 settings and no "jest.autoRun" found =>

Upvotes: 5

Evandro Coan
Evandro Coan

Reputation: 9428

I made it work by only setting the setting "jest.autoEnable": false, on my settings.json and restarting VSCode. At least, it is working until now and it hasn't broken yet: Disable starting Jest automatically

To open your settings.json:

  1. Press Ctrl+Shift+P
  2. Then type Preferences: Open Settings (JSON)

Upvotes: 22

Related Questions