parroty / excoveralls

Coverage report tool for Elixir with coveralls.io integration.
MIT License
820 stars 178 forks source link

Import coverdata if needed #292

Closed albertored closed 1 year ago

albertored commented 1 year ago

This PR aims to handle the generation and import of coverage data.

For generation, we need to handle the :export and :output options given to ExCoveralls.start/2 function. These options are described in Mix documentation for test.coverage.

For import, I added a new command line option (--import-cover) for selecting a directory from where cover data should be loaded. These files will be imported after module cover-compilation and their data will be added to the generated report.

coveralls commented 1 year ago

Coverage Status

Coverage decreased (-2.4%) to 88.113% when pulling 7d6345b278a6b2480666b17601230ea7108ab299 on albertored:coverdata into d1b6b35cee693e0bc461da00c969a79a23276baa on parroty:master.

coveralls commented 1 year ago

Coverage Status

Coverage: 88.015% (-1.2%) from 89.184% when pulling 0e88da01e75c662084e2f50534739d6231f00973 on albertored:coverdata into 2dc17fd56c8e15075a3f8aa12dea4afd481ff000 on parroty:master.

albertored commented 1 year ago

I will fix and add tests if you think the feature is ok

parroty commented 1 year ago

Thanks and sorry being late to respond. Is it possible for you to provide example for this option for understanding the scenario better? (document, example code, etc.)

albertored commented 1 year ago

@parroty I'll use the example taken from mix test.coverage to explain the changes.

Imagine you want to run tests split in different partitions, at the moment you won't get the real coverage from excoveralls since the only a subset of tests is ran in each partition. With this change, we mimic the behavior of mix by exporting .coverdata files in the first runs and importing them in the last run to have a full coverage report.

MIX_TEST_PARTITION=1 mix coveralls --partitions 3 --export-coverage part1
MIX_TEST_PARTITION=2 mix coveralls --partitions 3 --export-coverage part2
MIX_TEST_PARTITION=3 mix coveralls --partitions 3 --import-cover cover

The first 2 commands generate cover/part1.coverdata and cover/part2.coverdata files that are then imported by the last command to generate a full report.

Another example, similar to my use case, is when you want to test your application with something different from mix. Imagine to use mix test for unit tests and then have some other tool that performs some integration test. By directly calling the :cover erlang module you can generate .coverdata report from your integrations tests and then use mix coveralls --import-cover cover to run unit tests and include the integration tests report in the final coverage.

albertored commented 1 year ago

Hi @parroty, did you manage to take a look at the provided example? In the next days, I will add documentation and tests

albertored commented 1 year ago

Hi @parroty, just noticed that you merged #298 which implements half of my PR. I have rebased on top of that keeping only the part for importing coverage outputs, fixed tests and added the new option to the README. It should now be ready to be merged.

parroty commented 1 year ago

Thanks for the additional work, and sorry being late to respond 🙇 .