Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for rspecs running in parallel on different workers #213

Open
whizzzkid opened this issue Jan 25, 2024 · 1 comment
Open

Support for rspecs running in parallel on different workers #213

whizzzkid opened this issue Jan 25, 2024 · 1 comment

Comments

@whizzzkid
Copy link

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?

@grodowski
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants