如何将调试器附加到 Vscode 中的 Hardhat Chai 测试并使用 Typescript 断点?

Can*_*ğlu 6 typescript visual-studio-code ethereum ethers.js hardhat

我知道我可以将console.logs 放入 Chai 测试中并将它们打印在控制台中。但是,我想知道如何debugger;在 Vscode 中放置常规断点(或语句),然后点击它,并像往常一样通过单步执行、求值、查看局部变量等进行调试。

如何在 Vscode(而不是 s)中使用断点真正console.log调试 Hardhat Chai 测试?

小智 2

对于 VSCode 中的调试器,我的.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Hardhat individual test",
            "type": "node",
            "request": "launch",
            "console": "integratedTerminal",
            "runtimeExecutable": "yarn",
            "runtimeArgs": [
                "testhh",
                "${workspaceFolder}/test-hardhat/<testFile>.ts"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

testhh是我的脚本的名称package.json,看起来像"testhh": "yarn hardhat test --no-compile". 然后可以通过菜单运行调试器Run and Debug

向脚本添加一些上下文。我用纱线运行单独的测试文件testhh test-hardhat/<testFile>.ts