在 VS Code 上调试 Jest [英] Debugging Jest on VS Code

查看:36
本文介绍了在 VS Code 上调试 Jest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VS Code 调试 Jest 单元测试.我有以下配置文件设置

I'm trying to debug Jest unit tests using VS Code. I have the following config file settings

"configurations": [
    {
        "name": "Debug Jest Tests",
        "type": "node",
        "request": "launch",
        "runtimeArgs": [
            "--inspect-brk",
            "${workspaceRoot}/node_modules//jest/bin/jest.js",
            "--runInBand"
        ],
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen"
    }
]

但是,当我运行 (F5) VS Code 时出现以下错误

However when I run (F5) VS Code I get the following error

错误:测试运行完成后必须存在 AggregatedResult

Error: AggregatedResult must be present after test run is complete

知道为什么吗?

推荐答案

关于使用 VSCode 调试 Jest 单元测试,创建如下文件(路径:.vscode/launch.json)

About debugging Jest unit tests using VSCode, create a the following file (path: .vscode/launch.json)

如果您使用 create-react-app

  {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Debug tests watch mode",
          "type": "node",
          "request": "launch",
          "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
          "args": ["test", "--runInBand", "--no-cache", "--watchAll=true"],
          "cwd": "${workspaceRoot}",
          "protocol": "inspector",
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen"
        }
      ]
    }

如果您从头开始创建应用:

If you have created your app from scratch:

   {
      "version": "0.2.0",
      "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Jest watch all tests",
          "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
          "args": [
            "--verbose",
            "-i",
            "--no-cache",
            "--watchAll"
          ],
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen"
        }
      ]
    }

有更多配置可用,如果您需要更多信息,请查看:

There are more configurations available, if you need more info check out:

这篇关于在 VS Code 上调试 Jest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆