调试它是VS代码

问题描述 投票:2回答:2

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

"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时,我收到以下错误

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

知道为什么吗?

debugging visual-studio-code jestjs
2个回答
0
投票

我无法回答准确的问题,但是这个用于调试Jest的基本启动配置对我有用,包含Jest跳过文件也很简单

    {
      "type": "node",
      "request": "launch",
      "name": "Jest",
      "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
      "args": [
          "-i"
      ],
       "skipFiles": [
        "<node_internals>/**/*.js", "node_modules",
      ]
    },

0
投票

关于使用VSCode调试Jest单元测试,创建以下文件(路径:.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"
        }
      ]
    }

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

   {
      "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"
        }
      ]
    }

如果您需要更多信息,可以使用更多配置:

© www.soinside.com 2019 - 2024. All rights reserved.