sc-forks/solidity-coverage

Specify minimum coverage

AlissonRS opened this issue · 1 comments

This package is very nice, it provides istanbul reports in the coverage folder.

Is it possible to setup minimum coverage threshold for statements, branches functions and lines?

Someone had a similar issue a couple years ago (#191) but that unfortunately doesn't seem to work anymore.

I tried using Istanbul CLI (I think it's called "nyc" nowadays) but it seems to be incompatible with the report generated by this package.

This is what I did:

yarn add -D nyc
yarn hardhat coverage --testfiles \"./test/**/*.ts\" # this generates the coverage folder with coverage-final.json
yarn nyc report --reporter text -t coverage

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

Even though the coverage-final.json exists and has the coverage data available, the nyc report is empty.

If I run yarn nyc check-coverage --statements 90 it shows no result (as it's likely not finding the coverage similar to the report command).

I also tried generating a json-summary report, but then if I run nyc I get the error below:

Invalid file coverage object, missing keys, found:lines,statements,functions,branches,linesCovered

So my understanding is that nyc is at least finding the json reports in the ./coverage folder, but it's somehow not working.

Could someone provide an example on how to use Istanbul CLI to check coverage from reports generated by solidity-coverage? Otherwise, maybe solidity-coverage is using an older version of Istanbul Reporter that is incompatible with their new CLI?

Thanks in advance!

@AlissonRS Apologies for the late response. There is a recipe for doing this using the instanbul dependency which comes with solidity-coverage itself here:

#610 (comment)

You shouldn't need to install any additional packages. Please just ping this issue if you run into trouble with this - closing for now.