Class: GitlabQuality::TestTooling::CodeCoverage::Artifacts

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb

Instance Method Summary collapse

Constructor Details

#initialize(coverage_report:, test_map:, test_reports:) ⇒ Artifacts

Loads coverage artifacts from the filesystem

Parameters:

  • test_reports (String)

    Glob pattern(s) for test JSON report files (RSpec or Jest). Supports comma-separated patterns (e.g., “jest/*/.json,rspec/*/.json”)

  • coverage_report (String)

    Path to the LCOV coverage report file (e.g., “coverage/lcov/gitlab.lcov”)

  • test_map (String)

    Path to the test map file, gzipped or plain JSON (e.g., “crystalball/packed-mapping.json.gz”)

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
# File 'lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb', line 18

def initialize(coverage_report:, test_map:, test_reports:)
  raise ArgumentError, "test_reports cannot be blank" if test_reports.blank?

  @test_reports_glob = test_reports
  @coverage_report_path = coverage_report
  @test_map_path = test_map
end

Instance Method Details

#coverage_reportString

Loads the LCOV coverage report file

Returns:

  • (String)

    Raw content of the LCOV coverage report

Raises:

  • (RuntimeError)

    If the coverage report file is not found



42
43
44
# File 'lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb', line 42

def coverage_report
  @coverage_report ||= read_coverage_reports
end

#test_mapHash

Loads and parses the test map file (supports gzipped or plain JSON)

Returns:

  • (Hash)

    Parsed test map data

Raises:

  • (RuntimeError)

    If the test map file is not found or cannot be parsed



50
51
52
# File 'lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb', line 50

def test_map
  @test_map ||= fetch_test_map
end

#test_reportsArray<Hash>

Loads and parses test JSON report files (RSpec or Jest)

Returns:

  • (Array<Hash>)

    Array of parsed JSON test reports

Raises:

  • (RuntimeError)

    If no test reports are found or if JSON parsing fails



30
31
32
33
34
35
36
# File 'lib/gitlab_quality/test_tooling/code_coverage/artifacts.rb', line 30

def test_reports
  @test_report_files ||= test_reports_paths.map do |report_path|
    JSON.parse(File.read(report_path))
  rescue JSON::ParserError => e
    raise "Invalid JSON in test report file #{report_path}: #{e.message}"
  end
end