在 Visual Studio Code 编辑器中完全禁用 Jest 测试运行器的自动运行

the*_*itp 7 unit-testing jestjs visual-studio-code puppeteer

我有一些运行 Puppeteer 浏览器测试的 Jest 测试用例。

我已经尝试过这些测试运行器

对我来说,我最喜欢 Jest Test Explorer,但它总是自动开始运行测试用例。可以想象,当我使用 VS Code 打开一个项目时,会启动很多 Chrome 浏览器实例。

我找到了一些配置,但它们无法阻止自动运行测试用例。

  • "testExplorer.onStart": "重置",或设置为空
  • "testExplorer.onReload": "重置",或设置为空

仅供参考,Jest Test Explorer 的示例 UI 在此处输入图片说明

Jest (vscode-jest) 是一个很好的运行器,但我也无法停止使用这些设置自动运行。

  • “jest.runAllTestsFirst”:假,
  • “jest.autoEnable”:假,
  • "jest.showCoverageOnLoad": 假

因此,目前 Jest Runner (vscode-jest-runner) 是唯一不自动启动单元测试的运行器。

此外,如果您有任何其他测试运行器建议,请告诉我。

非常感谢。

Dan*_*ñoz 76

为了orta.vscode-jest扩展,我在settings.json. 您可以settings.json通过执行Command + Shift + P(Windows 上的 Ctrl + Shift + P)、键入settings JSON并选择 来打开Preferences: Open User Settings (JSON)

"jest.autoRun": {
    "onStartup": []
}
Run Code Online (Sandbox Code Playgroud)

或者您可以简单地添加:

"jest.autoRun": {}
Run Code Online (Sandbox Code Playgroud)

如果您想在启动时运行所有测试,请添加all-testsonStartup数组中:

"jest.autoRun": {
    "onStartup": ["all-tests"]
}
Run Code Online (Sandbox Code Playgroud)


sil*_*189 33

我只是将这个简单的选项设置到 VS Code 中settings.json

"jest.autoRun": "false"
Run Code Online (Sandbox Code Playgroud)

  • 我相信这在最近的更新中已经改变。我现在收到以下错误“无效的自动运行设置“false””。将使用默认设置`我现在使用设置`"jest.autoRun": { "watch": false }` (19认同)

小智 26

在撰写本文时(12 月 22 日),执行此操作的新方法(根据https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-trigger-the- test-run)的目的是在 VS Code settings.json 中包含以下内容。请注意,我之前尝试过其他答案,但没有成功。

  "jest.autoRun": { "watch": false }
Run Code Online (Sandbox Code Playgroud)

  • 上面的答案对我有用。版本 5.x。如果您使用的是 6.1 及更高版本,请尝试 `"jest.runMode": "on-demand"`。`"jest.runMode": {"type": "on-demand", "deferred": true}` 适用于< v6.1.0(根据[自定义表](https://github.com/2017/11/17/14/14/14/14/14/14/14/14/14/14/14/14/14/14/16/16/16/16/16/14/14/14/14/14/14/14/14/14/14/14/14/14/14/14/14/19/16/17/14/19/19/19/19/19/19/19/16/17/19/17/19/17/19/19须要运行模式)由runMode替换。 com/jest-community/vscode-jest/blob/master/README.md#customization) (4认同)

use*_*ser 8

我仅通过"jest.autoEnable": false,在我的设置上设置settings.json并重新启动 VSCode 来使其工作。至少,它一直工作到现在还没有坏:禁用自动启动 Jest

打开你的settings.json

  1. Ctrl+ Shift+P
  2. 然后输入 Preferences: Open Settings (JSON)


小智 8

转到 vscode 设置.json

您可以添加

"jest.autoRun": "off"
Run Code Online (Sandbox Code Playgroud)

或者

"jest.autoRun": false
Run Code Online (Sandbox Code Playgroud)

两者都是有效的选项。您可以在此处查看官方推荐的设置。

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

"jest.autoEnable": false
Run Code Online (Sandbox Code Playgroud)

已弃用。


小智 6

它对我有用的是:

文件 -> 首选项 -> 设置。然后在面板用户下(在工作区中也是如此,但我不确定您是否也需要在那里修改它),转到扩展 - >玩笑。

在那里你将有一个 jest: auto run 部分,你会找到一个链接“在 settings.json 中编辑”并修改其中的内容

"jest.autoRun": {
  "watch": false
}
Run Code Online (Sandbox Code Playgroud)


小智 6

只需将其放入 settings.json (用户)

"jest.runMode": "on-demand",
Run Code Online (Sandbox Code Playgroud)


Ryn*_*oRn 5

2024 更新: jest.autoRun已弃用,请"jest.runMode": "on-demand"改用。

来源