如何在VS Code中交互式调试NodeJS测试套件? [英] How to interactively debug a NodeJS test suite in VS Code?

查看:324
本文介绍了如何在VS Code中交互式调试NodeJS测试套件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jest测试套件,我想使用VS Code交互式调试器进行调试.对于正常的NodeJS程序(launch.json中的"program": "foo.js"),这很好用.但是测试套件(foo.test.js)并不是一个自包含的程序,它必须从Jest运行.

I have a Jest test suite that I would like to debug using the VS Code interactive debugger. That works fine for normal NodeJS programs ("program": "foo.js" in launch.json). But the test suite (foo.test.js) isn't a self-contained program, it has to be run from Jest.

有没有办法做到这一点?

Is there a way to achieve this?

特定代码在此处: https://gitlab.com/stevage/guess-projection

推荐答案

调试标准的Jest测试

此Microsoft vscode-recipies 中的doc GitHub回购描述了如何为调试标准的Jest测试.

Debugging standard Jest tests

This doc in Microsoft's vscode-recipies GitHub repo describes how to set up VS Code for debugging standard Jest tests.

launch.json看起来像这样:

The launch.json looks like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Jest Current File",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": ["${relativeFile}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    }
  ]
}


调试create-react-app玩笑测试

如果您的应用程序是使用 create-react-app 引导的React应用,则该配置略有不同,因为Jest没有直接启动,并且在


Debugging create-react-app Jest tests

If your application is a React app bootstrapped with create-react-app then the configuration is a little different since Jest is not launched directly and is described in this section of the create-react-app docs.

这篇关于如何在VS Code中交互式调试NodeJS测试套件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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