Commit ef2fc4a8 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'eb-skip-cobertura-sources' into 'master'

Ignore sources node from cobertura XML

See merge request gitlab-org/gitlab!39385
parents 41964d9c 6b6f779d
---
title: Ignore the sources node from the cobertura XML
merge_request: 39385
author:
type: fixed
...@@ -54,6 +54,10 @@ from any job in any stage in the pipeline. The coverage will be displayed for ea ...@@ -54,6 +54,10 @@ from any job in any stage in the pipeline. The coverage will be displayed for ea
Hovering over the coverage bar will provide further information, such as the number Hovering over the coverage bar will provide further information, such as the number
of times the line was checked by tests. of times the line was checked by tests.
NOTE: **Note:**
The Cobertura XML parser currently does not support the `sources` element and ignores it. It is assumed that
the `filename` of a `class` element contains the full path relative to the project root.
## Example test coverage configuration ## Example test coverage configuration
The following [`gitlab-ci.yml`](../../../ci/yaml/README.md) example uses [Mocha](https://mochajs.org/) The following [`gitlab-ci.yml`](../../../ci/yaml/README.md) example uses [Mocha](https://mochajs.org/)
......
...@@ -28,6 +28,8 @@ module Gitlab ...@@ -28,6 +28,8 @@ module Gitlab
end end
def parse_node(key, value, coverage_report) def parse_node(key, value, coverage_report)
return if key == 'sources'
if key == 'class' if key == 'class'
Array.wrap(value).each do |item| Array.wrap(value).each do |item|
parse_class(item, coverage_report) parse_class(item, coverage_report)
......
...@@ -19,6 +19,41 @@ RSpec.describe Gitlab::Ci::Parsers::Coverage::Cobertura do ...@@ -19,6 +19,41 @@ RSpec.describe Gitlab::Ci::Parsers::Coverage::Cobertura do
end end
end end
context 'when there is a <sources>' do
shared_examples_for 'ignoring sources' do
it 'parses XML without errors' do
expect { subject }.not_to raise_error
expect(coverage_report.files).to eq({})
end
end
context 'and has a single source' do
let(:cobertura) do
<<-EOF.strip_heredoc
<sources>
<source>project/src</source>
</sources>
EOF
end
it_behaves_like 'ignoring sources'
end
context 'and has multiple sources' do
let(:cobertura) do
<<-EOF.strip_heredoc
<sources>
<source>project/src/foo</source>
<source>project/src/bar</source>
</sources>
EOF
end
it_behaves_like 'ignoring sources'
end
end
context 'when there is a single <class>' do context 'when there is a single <class>' do
context 'with no lines' do context 'with no lines' do
let(:cobertura) do let(:cobertura) do
......
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