I know I can put console.log
s in Chai tests and get them printed in console. However, I want to know how can I put a regular breakpoint (or debugger;
statement) in Vscode, and hit it, and debug as usual with stepping, evaluation, viewing local variables etc.
How do I truly debug hardhat chai test with breakpoints in Vscode (instead of console.log
s)?
2
Answers
As specified in the comments section above, I was in a similar situation, unable to have a breakpoint on chai tests.
There could be multiple ways to debug and I will keep updating the answer as and when I find a new one.
a) Place a breakpoint in the typescript test code.
b) Run the following command in Javascript Debug Terminal.
hardhat test [testfoldername][testfile].ts
For debugger in VSCode I have following in my
.vscode/launch.json
testhh
is a name of a script in mypackage.json
, which look like"testhh": "yarn hardhat test --no-compile"
.Debugger can then be run via
Run and Debug
menu.To add a bit of context to script. I run individual test files with yarn
testhh test-hardhat/<testFile>.ts