Using Knapsack Pro in Queue Mode with SimpleCov
This is needed only if you are using Knapsack Pro in Queue Mode.
RSpec
Apply the following code:
require 'knapsack_pro'
require 'simplecov'
SimpleCov.start
KnapsackPro::Hooks::Queue.before_queue do |queue_id|
SimpleCov.command_name("rspec_ci_node_#{KnapsackPro::Config::Env.ci_node_index}")
end
This is needed to avoid conflicts between code coverage reports generated by parallel CI nodes.
Please see this if you use CodeClimate.
Minitest
Apply the following code:
require 'knapsack_pro'
require 'simplecov'
SimpleCov.start
KnapsackPro::Hooks::Queue.before_queue do |queue_id|
SimpleCov.command_name("minitest_ci_node_#{KnapsackPro::Config::Env.ci_node_index}")
end
KnapsackPro::Hooks::Queue.after_queue do
SimpleCov.result.format!
end
This is needed to avoid conflicts between code coverage reports generated by parallel CI nodes.
Please see this if you use CodeClimate.
For legacy versions of knapsack_pro
older than 6.0.4, please click here.
require 'knapsack_pro'
require 'simplecov'
SimpleCov.start
KnapsackPro::Hooks::Queue.before_queue do |queue_id|
SimpleCov.command_name("minitest_ci_node_#{KnapsackPro::Config::Env.ci_node_index}")
end
How to merge SimpleCov reports from parallel CI nodes
Isolated parallel nodes with their own disk
Please check SimpleCov docs for merging test runs under different execution environments.
You could create a rake task to merge SimpleCov reports.
Please refer to your CI provider documentation to learn how to get files from parallel nodes and put them in the same location so that you can merge them. You can also look at these examples:
- How to merge SimpleCov results with parallel Rails specs on Semaphore CI
- How to merge CodeClimate reports for parallel jobs (CI nodes)
In Knapsack Pro Queue Mode, a late CI node will run no tests. The CI node is late when it starts work after other parallel nodes have already executed all the tests. This means there will be no SimpleCov report on the late CI node. You should adjust your CI pipeline for this when you expect to fetch SimpleCov reports from parallel nodes.
Shared disk between parallel nodes
SimpleCov generates a single report at coverage/index.html
with merged data if a local drive is shared between parallel nodes. This is the case when you use Jenkins and the disk is shared between parallel nodes.