Reputation: 1024
After running Hardhat tests in the console with npx hardhat test
I decided that being able to set break points would help me iterate faster.
How can I get Webstorm to run the underlying functions started by npx hardhat test
so that I can use the built in Debugger?
Upvotes: 3
Views: 2007
Reputation: 7257
Install ts-mocha as mentioned by @Fedy_
# remember to install mocha if you don't have it already (npm i -D mocha)
npm i -D ts-mocha
# install recent Mocha and Expect @types packages for best DX
npm i -D @types/mocha @types/expect
Add ts-mocha path to run Run/Debug configurations of IntelliJ IDEA
Upvotes: 1
Reputation: 491
If you're use typescript you need to import ts-mocha instead of mocha
Upvotes: 1
Reputation: 456
package.json
file for your Hardhat project.test
NPM run script and save the file. Your package.json should look something like this.{
"name": "hardhat-project",
"scripts": {
"test": "hardhat test"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-waffle": "2.0.1",
"chai": "4.3.4",
"ethereum-waffle": "3.4.0",
"ethers": "5.4.4",
"hardhat": "2.6.0"
}
}
Debug "test"
.I go through the instructions in a little more detail here, but this is the general idea. https://allendefibank.medium.com/how-to-debug-solidity-contracts-in-webstorm-hardhat-2ea0d3c4d582
Upvotes: 4
Reputation: 1024
I've since discovered that hardhat runs mocha under the hood.
To debug in WebStorm you can:
--timeout 10000
because mocha's default timeout is only 2000ms
const {ethers} = require('hardhat');
to your test file because it is no longer injected by hardhat during run time.At this point I could successfully set break points in my test file but not in the MyContract.sol file. This is not surprising given that the contract is compiled before its run.
Upvotes: 4