How to fail solidity tests when coverage us less than x% using hardhat coverage

Viewed 66

I am running my automated tests using hardhat coverage which uses the solidity-coverage package.

It is executed using npx hardhat coverage

I cant find any options to fail the test if the coverage is less than a certain percentage.

I want to make sure what when a new pull request is made that the coverage is above 90% before allowing the merge.

1 Answers

I think you may need a service like coveralls to always have the minimum percentage be the latest high. However you can hardcode some minimum thresholds. Try running

npx hardhat coverage && npx istanbul check-coverage --statements 90 --branches 90 --functions 90 --lines 90

And see if that fails the build when coverage is not enough

(source: https://github.com/sc-forks/solidity-coverage/issues/191#issuecomment-364474968)

Related