17

我正在尝试在运行 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"
    }
4

1 回答 1

5

我得到了你的支持,兄弟。

由于 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

于 2020-05-19T19:35:05.103 回答