我知道我可以把console.log
s放到Chai测试中,然后在控制台上打印出来。然而,我想知道如何在Vscode中放置常规断点(或debugger;
语句),并点击它,并像往常一样调试步进,评估,查看局部变量等。
我如何真正调试硬帽柴测试与断点在Vscode(而不是console.log
s)?
对于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"
]
}
]
}
testhh
是我的package.json
脚本的名称,看起来像"testhh": "yarn hardhat test --no-compile"
。调试器可以通过Run and Debug
菜单运行。
为脚本添加一些上下文。我运行单独的测试文件与纱线testhh test-hardhat/<testFile>.ts
正如上面评论部分所指定的,我遇到了类似的情况,无法在chai测试中设置断点。
可能有多种方法来调试,我会不断更新的答案,当我找到一个新的。
- 将合约部署到本地HardHat节点,并按照参考答案进行测试。 这是我遇到的最接近的答案,正如LinkedIn帖子评论中解释的那样。
a)在typescript测试代码中放置一个断点。
b)在Javascript调试终端中执行如下命令.
hardhat test [testfoldername][testfile].ts