Using Knapsack Pro with CircleCI
Collect metadata in Queue Mode
You may want to collect metadata in CircleCI. For example, to collect junit reports of your RSpec runs you would:
- Configure the junit formatter for RSpec
- Copy the report to the
$CIRCLE_TEST_REPORTS
directory as shown below
- RSpec
- CircleCI
spec_helper.rb or rails_helper.rb
# `TMP_REPORT` must be the same path as `--out`
# `TMP_REPORT` must be a full path (no `~`)
TMP_REPORT = "tmp/tmp_rspec_#{ENV['KNAPSACK_PRO_CI_NODE_INDEX']}.xml"
FINAL_REPORT = "tmp/final_rspec_#{ENV['KNAPSACK_PRO_CI_NODE_INDEX']}.xml"
KnapsackPro::Hooks::Queue.after_subset_queue do |queue_id, subset_queue_id|
if File.exist?(TMP_REPORT)
FileUtils.mv(TMP_REPORT, FINAL_REPORT)
end
end
KnapsackPro::Hooks::Queue.after_queue do |queue_id|
if File.exist?(FINAL_REPORT) && ENV['CIRCLE_TEST_REPORTS']
FileUtils.cp(FINAL_REPORT, "#{ENV['CIRCLE_TEST_REPORTS']}/rspec.xml")
end
end
.circleci/config.yml
- run:
name: RSpec with Knapsack Pro in Queue Mode
command: |
export CIRCLE_TEST_REPORTS=/tmp/test-results
mkdir $CIRCLE_TEST_REPORTS
bundle exec rake "knapsack_pro:queue:rspec[--format documentation --format RspecJunitFormatter --out tmp/rspec.xml]"
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
You can find a complete CircleCI configuration in RSpec testing parallel jobs with CircleCI and JUnit XML report.