grodowski / undercover

undercover warns about methods, classes and blocks that were changed without tests, to help you easily find untested code and reduce the number of bugs. It does so by analysing data from git diffs, code structure and SimpleCov coverage reports

Home Page:https://undercover-ci.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for rspecs running in parallel on different workers

whizzzkid opened this issue · comments

When splitting rspec across multiple workers using something like knapsack, what would be the best way to club all generated coverage reports into a single artifact?

Hey @whizzzkid! Here's an example from https://undercover-ci.com/docs#parallel-tests. It uses SimpleCov.collate also described in the SimpleCov documentation.

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'simplecov'
require 'simplecov-lcov'

puts('Merging coverage results from parallel CircleCI tests containers into a single LCOV report...')

SimpleCov.collate(Dir['/home/circleci/rspec/*.resultset.json']) do
  enable_coverage(:branch)
end

report_path = ARGV[0] || 'coverage.lcov'
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
SimpleCov::Formatter::LcovFormatter.config.single_report_path = report_path

merged_result = SimpleCov.result
merged_result.format!

if File.size(report_path).zero?
  puts('Written report has 0 bytes')
  exit 1
end
puts("Done! LCOV saved to #{SimpleCov::Formatter::LcovFormatter.config.single_report_path}")

Depending on which CI you use, you'd need a script like this to run after all the workers have finished and then feed the merged coverage report to undercover.

Let me know how it goes!