codeclimate / ruby-test-reporter

DEPRECATED Uploads Ruby test coverage data to Code Climate
https://codeclimate.com
Other
92 stars 92 forks source link

Handle multi-command resultsets #163

Closed pbrisbin closed 7 years ago

pbrisbin commented 7 years ago

Simplecov supports merging coverage from multiple test suites by writing them at different command names in the resultset file, then merging them when building the report.

We were getting this for free pre-1.0 because the resultsets would be merged before being passed to the custom formatter. Post-1.0 we were (mistakenly) assuming it'd just be one command name in the JSON file, hence we were only reading:

SimpleCov::Result.new(results.values.fetch(0).fetch("coverage"))

discarding all but the first command-name.

This is both broken and more work than we need to do. The file has a well-defined schema, and we can rely more on Simplcov for parsing it.

Something like:

SimpleCov::Result.from_hash(results.first)

would've been functionally equivalent, and shows more clearly the bug. What we really want is:

results.map do |k, v|
  SimpleCov::Result.from_hash(k => v)
end

Then with an array of results, we can in-line some of Simplecov::ResultMerger to merge them together into a single Simplecov::Result that we'll format for upload. Unfortunately, we do have to in-line the method we need because this object has multiple responsibilities (yay!), including caching and re-writing files on disk, which we don't want.

Fixes #7

/cc @codeclimate/review

If someone's around and wants to merge / release that'd be great. If not, I'll pick it up when I'm back next week.

maxjacobson commented 7 years ago

Nice! Going to review more closely a littler later and may ship it this week. Looks like this build is failing for reasons unrelated to your change, which should be fixed here: https://github.com/codeclimate/ruby-test-reporter/pull/164