|
| 1 | +desc "static HTML formatted report of Coverband code coverage" |
| 2 | +task :simplecov_json_report do |
| 3 | + require "coverband" |
| 4 | + require "coverband/utils/html_formatter" |
| 5 | + require "coverband/utils/result" |
| 6 | + require "coverband/utils/file_list" |
| 7 | + require "coverband/utils/source_file" |
| 8 | + require "coverband/utils/lines_classifier" |
| 9 | + require "coverband/utils/results" |
| 10 | + |
| 11 | + require "simplecov" |
| 12 | + require "simplecov_json_formatter" |
| 13 | + |
| 14 | + `mkdir -p #{SimpleCov.coverage_path}` |
| 15 | + |
| 16 | + # For a fully static HTML that can be copied to artifacts are part of CI |
| 17 | + # we generate with inline assets |
| 18 | + ENV["SIMPLECOV_INLINE_ASSETS"] = "true" |
| 19 | + |
| 20 | + SimpleCovJSONFormatter::ResultExporter.send(:remove_const, "FILENAME") |
| 21 | + SimpleCovJSONFormatter::ResultExporter::FILENAME = "cypress_coverage.json" |
| 22 | + |
| 23 | + coverband_reports = Coverband::Reporters::Base.report(Coverband.configuration.store) |
| 24 | + Coverband::Reporters::Base.fix_reports(coverband_reports) |
| 25 | + result = Coverband::Utils::Results.new(coverband_reports) |
| 26 | + SimpleCov::Formatter::JSONFormatter.new.format(result) |
| 27 | + |
| 28 | + # fix json structure so it can be merged with coverage:merge |
| 29 | + generated_json_file = File.join(SimpleCov.coverage_path, SimpleCovJSONFormatter::ResultExporter::FILENAME) |
| 30 | + content = { "Cypress" => JSON.parse(File.read(generated_json_file)) } |
| 31 | + File.write(generated_json_file, content.to_json) |
| 32 | +end |
| 33 | + |
| 34 | +namespace :coverage do |
| 35 | + desc "Merge Minitest's and Cypress' code coverage json files into one" |
| 36 | + task :merge do |
| 37 | + require "simplecov" |
| 38 | + |
| 39 | + # change this if you use different json result names |
| 40 | + coverage_files = Dir["#{SimpleCov.coverage_path}/.resultset.json"] + Dir["#{SimpleCov.coverage_path}/cypress_coverage.json"] |
| 41 | + |
| 42 | + # make sure to use the `rails` profile to not add noise with files we won't test |
| 43 | + SimpleCov.collate coverage_files, "rails" |
| 44 | + end |
| 45 | +end |
0 commit comments