Commit 7e0ac377 authored by Maxime Orefice's avatar Maxime Orefice Committed by Heinrich Lee Yu

Add accessibility report for a build

parent 4400a604
......@@ -869,6 +869,14 @@ module Ci
end
end
def collect_accessibility_reports!(accessibility_report)
each_report(Ci::JobArtifact::ACCESSIBILITY_REPORT_FILE_TYPES) do |file_type, blob|
Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, accessibility_report)
end
accessibility_report
end
def collect_coverage_reports!(coverage_report)
each_report(Ci::JobArtifact::COVERAGE_REPORT_FILE_TYPES) do |file_type, blob|
Gitlab::Ci::Parsers.fabricate!(file_type).parse!(blob, coverage_report)
......
......@@ -320,6 +320,12 @@ FactoryBot.define do
end
end
trait :accessibility_reports do
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :accessibility, job: build)
end
end
trait :coverage_reports do
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :cobertura, job: build)
......
......@@ -3834,6 +3834,61 @@ describe Ci::Build do
end
end
describe '#collect_accessibility_reports!' do
subject { build.collect_accessibility_reports!(accessibility_report) }
let(:accessibility_report) { Gitlab::Ci::Reports::AccessibilityReports.new }
it { expect(accessibility_report.urls).to eq({}) }
context 'when build has an accessibility report' do
context 'when there is an accessibility report with errors' do
before do
create(:ci_job_artifact, :accessibility, job: build, project: build.project)
end
it 'parses blobs and add the results to the accessibility report' do
expect { subject }.not_to raise_error
expect(accessibility_report.urls.keys).to match_array(['https://about.gitlab.com/'])
expect(accessibility_report.errors_count).to eq(10)
expect(accessibility_report.scans_count).to eq(1)
expect(accessibility_report.passes_count).to eq(0)
end
end
context 'when there is an accessibility report without errors' do
before do
create(:ci_job_artifact, :accessibility_without_errors, job: build, project: build.project)
end
it 'parses blobs and add the results to the accessibility report' do
expect { subject }.not_to raise_error
expect(accessibility_report.urls.keys).to match_array(['https://pa11y.org/'])
expect(accessibility_report.errors_count).to eq(0)
expect(accessibility_report.scans_count).to eq(1)
expect(accessibility_report.passes_count).to eq(1)
end
end
context 'when there is an accessibility report with an invalid url' do
before do
create(:ci_job_artifact, :accessibility_with_invalid_url, job: build, project: build.project)
end
it 'parses blobs and add the results to the accessibility report' do
expect { subject }.not_to raise_error
expect(accessibility_report.urls).to be_empty
expect(accessibility_report.errors_count).to eq(0)
expect(accessibility_report.scans_count).to eq(0)
expect(accessibility_report.passes_count).to eq(0)
end
end
end
end
describe '#collect_coverage_reports!' do
subject { build.collect_coverage_reports!(coverage_report) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment