制作nyc覆盖率报告时如何使用VSCode进行调试?

问题描述 投票:15回答:1

我正在尝试在运行nyc时进行调试,而不仅仅是在运行mocha测试时进行调试,因此,我不必每次都运行两次测试。VSCode运行覆盖并将其显示给我,但是它不会停止或验证断点,如何设置它以进行正确调试?可能吗?

我的启动配置:

{
        "type": "node",
        "request": "launch",
        "name": "Coverge",
        "program": "/usr/local/bin/nyc",
        "args": [
            "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "-u",
            "tdd",
            "--timeout",
            "999999",
            "--colors",
            "${workspaceFolder}/tests/*/*"
        ],
        "skipFiles": [
            "${workspaceFolder}/node_modules/**/*.js"
        ],
        "env": {},
        "outputCapture": "std",
        "internalConsoleOptions": "openOnSessionStart"
    }
node.js visual-studio-code nyc
1个回答
0
投票

我得到了你的后兄弟。

由于NYC作为子代运行子流程,因此它将不起作用。但是您可以运行一个称为“复合启动”的程序,实际上它运行2个进程,第一个连接到正在等待的第二个进程,侦听端口(默认为9229),然后瞧。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Coverage",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/node_modules/.bin/nyc",
            "args": [
                "-x","test","--reporter=lcov","--reporter=text",
                "node", "--inspect-brk",
                "./node_modules/.bin/mocha", "test", "--recursive", "--timeout=300000"
            ]
        }
        ,
        { // https://code.visualstudio.com/Docs/editor/debugging#_launch-versus-attach-configurations
            "type": "node",
            "name": "AttachMocha",
            "request": "attach",
            "port": 9229
        }
    ],
    // https://code.visualstudio.com/Docs/editor/debugging#_compound-launch-configurations
    "compounds": [
      {
        "name": "NYC/Mocha",
        "configurations": ["AttachMocha", "Coverage"]
      }
    ]
}

您将在调试运行列表上看到NYC / Mocha

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