69

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.

  • "testExplorer.onStart": "reset", or set to null
  • "testExplorer.onReload": "reset", or set to null

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.

  • "jest.runAllTestsFirst": false,
  • "jest.autoEnable": false,
  • "jest.showCoverageOnLoad": false

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.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
theeranitp
  • 925
  • 1
  • 10
  • 36
  • 2
    You're not the only one with this problem! I'm so annoyed by [Tridactyl](https://github.com/tridactyl/tridactyl)'s WebDriverIO tests launching every time I open VScode, and for the life of me, I cannot figure out how to make them stop. ;_; – ELLIOTTCABLE Sep 23 '19 at 20:59
  • Hi @ELLIOTTCABLE. Until now, I still don't know how to fix it. ^^ – theeranitp Sep 25 '19 at 03:14

8 Answers8

64

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"]
}
Daniel Muñoz
  • 1,374
  • 12
  • 18
  • Thank you. Command + Shift + P -> typing SETTINGS.JSON -> Preferences: Open Workspace settings ( JSON ). And add "jest.autoRun": {} Otherwise it will open settings.json file in read only mode. – Mishhub Mohammed Dec 26 '22 at 10:24
  • 1
    Thanks @MishhubMohammed. I've updated the answer to use `Preferences: Open User Settings (JSON)`. I suppose `Default` and `Workspace` settings work too. – Daniel Muñoz Apr 01 '23 at 03:01
32

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

"jest.autoRun": "false"
double-beep
  • 5,031
  • 17
  • 33
  • 41
silex189
  • 421
  • 5
  • 3
  • This is the best answer; https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest states `autoEnable` should instead use `autoRun`. – Charles Ouimet Feb 23 '22 at 16:15
  • This is the only thing that worked for me – Drew Landgrave Aug 10 '22 at 14:43
  • 16
    I believe this has changed in a recent update. I now get the following error `invalid autoRun setting "false". Will use default setting instead` I'm now using the setting `"jest.autoRun": { "watch": false }` instead – amarillion Dec 22 '22 at 15:31
20

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)
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
18

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 }
gmg13
  • 181
  • 1
  • 4
8

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.

Nemeton
  • 705
  • 6
  • 11
6

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
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
4

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"}
3

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 =>

user1428619
  • 71
  • 1
  • 5